hostmaster.install

Functions

Namesort ascending Description
hostmaster_task_finalize
hostmaster_place_blocks Helper function to place block.
hostmaster_install Implement hook_install().
hostmaster_bootstrap

File

hostmaster.install
View source
  1. <?php
  2. /**
  3. * Implement hook_install().
  4. *
  5. * Perform actions to set up the site for this profile.
  6. */
  7. function hostmaster_install() {
  8. variable_set('install_profile', 'hostmaster');
  9. // add support for nginx
  10. if (d()->platform->server->http_service_type === 'nginx') {
  11. module_enable(array('hosting_nginx'));
  12. }
  13. // Bootstrap and create all the initial nodes
  14. hostmaster_bootstrap();
  15. // Finalize and setup themes, optional modules etc
  16. hostmaster_task_finalize();
  17. }
  18. function hostmaster_bootstrap() {
  19. /* Default node types and default node */
  20. $types = node_types_rebuild();
  21. // Initialize the hosting defines
  22. hosting_init();
  23. /* Default client */
  24. $node = new stdClass();
  25. $node->uid = 1;
  26. $node->type = 'client';
  27. $node->title = drush_get_option('client_name', 'admin');
  28. $node->status = 1;
  29. node_save($node);
  30. variable_set('hosting_default_client', $node->nid);
  31. variable_set('hosting_admin_client', $node->nid);
  32. $client_id = $node->nid;
  33. /* Default server */
  34. $node = new stdClass();
  35. $node->uid = 1;
  36. $node->type = 'server';
  37. $node->title = php_uname('n');
  38. $node->status = 1;
  39. $node->hosting_name = 'server_master';
  40. $node->services = array();
  41. /* Make it compatible with more than apache and nginx */
  42. $master_server = d()->platform->server;
  43. hosting_services_add($node, 'http', $master_server->http_service_type, array(
  44. 'restart_cmd' => $master_server->http_restart_cmd,
  45. 'port' => $master_server->http_port,
  46. 'available' => 1,
  47. ));
  48. /* examine the db server associated with the hostmaster site */
  49. $db_server = d()->db_server;
  50. $master_db = parse_url($db_server->master_db);
  51. /* if it's not the same server as the master server, create a new node
  52. * for it */
  53. if ($db_server->remote_host == $master_server->remote_host) {
  54. $db_node = $node;
  55. } else {
  56. $db_node = new stdClass();
  57. $db_node->uid = 1;
  58. $db_node->type = 'server';
  59. $db_node->title = $master_db['host'];
  60. $db_node->status = 1;
  61. $db_node->hosting_name = 'server_' . $db_server->remote_host;
  62. $db_node->services = array();
  63. }
  64. hosting_services_add($db_node, 'db', $db_server->db_service_type, array(
  65. 'db_type' => $master_db['scheme'],
  66. 'db_user' => urldecode($master_db['user']),
  67. 'db_passwd' => isset($master_db['pass']) ? urldecode($master_db['pass']) : '',
  68. 'port' => $db_server->db_port,
  69. 'available' => 1,
  70. ));
  71. drupal_set_message(st('Creating master server node'));
  72. node_save($node);
  73. if ($db_server->remote_host != $master_server->remote_host) {
  74. drupal_set_message(st('Creating db server node'));
  75. node_save($db_node);
  76. }
  77. variable_set('hosting_default_web_server', $node->nid);
  78. variable_set('hosting_own_web_server', $node->nid);
  79. variable_set('hosting_default_db_server', $db_node->nid);
  80. variable_set('hosting_own_db_server', $db_node->nid);
  81. // Create the hostmaster platform & packages
  82. $node = new stdClass();
  83. $node->uid = 1;
  84. $node->title = 'Drupal';
  85. $node->type = 'package';
  86. $node->package_type = 'platform';
  87. $node->short_name = 'drupal';
  88. $node->old_short_name = 'drupal';
  89. $node->description = 'Drupal code-base.';
  90. $node->status = 1;
  91. node_save($node);
  92. $package_id = $node->nid;
  93. $node = new stdClass();
  94. $node->uid = 1;
  95. $node->type = 'platform';
  96. $node->title = 'hostmaster';
  97. $node->publish_path = d()->root;
  98. $node->makefile = '';
  99. $node->verified = 1;
  100. $node->web_server = variable_get('hosting_default_web_server', 2);
  101. $node->platform_status = 1;
  102. $node->status = 1;
  103. $node->make_working_copy = 0;
  104. node_save($node);
  105. $platform_id = $node->nid;
  106. variable_set('hosting_own_platform', $node->nid);
  107. $instance = new stdClass();
  108. $instance->rid = $node->nid;
  109. $instance->version = VERSION;
  110. $instance->filename = '';
  111. $instance->version_code = 1;
  112. //$instance->schema_version = drupal_get_installed_schema_version('system');
  113. $instance->schema_version = 0;
  114. $instance->package_id = $package_id;
  115. $instance->status = 0;
  116. $instance->platform = $platform_id;
  117. hosting_package_instance_save($instance);
  118. // Create the hostmaster profile package node
  119. $node = new stdClass();
  120. $node->uid = 1;
  121. $node->title = 'hostmaster';
  122. $node->type = 'package';
  123. $node->old_short_name = 'hostmaster';
  124. $node->description = 'The Hostmaster profile.';
  125. $node->package_type = 'profile';
  126. $node->short_name = 'hostmaster';
  127. $node->status = 1;
  128. node_save($node);
  129. $profile_id = $node->nid;
  130. $instance = new stdClass();
  131. $instance->rid = $node->nid;
  132. $instance->version = VERSION;
  133. $instance->filename = '';
  134. $instance->version_code = 1;
  135. //$instance->schema_version = drupal_get_installed_schema_version('system');
  136. $instance->schema_version = 0;
  137. $instance->package_id = $profile_id;
  138. $instance->status = 0;
  139. $instance->platform = $platform_id;
  140. hosting_package_instance_save($instance);
  141. // Create the main Aegir site node
  142. $node = new stdClass();
  143. $node->uid = 1;
  144. $node->type = 'site';
  145. $node->title = d()->uri;
  146. $node->platform = $platform_id;
  147. $node->client = $client_id;
  148. $node->db_name = '';
  149. $node->db_server = $db_node->nid;
  150. $node->profile = $profile_id;
  151. $node->import = true;
  152. $node->hosting_name = 'hostmaster';
  153. $node->site_status = 1;
  154. $node->verified = 1;
  155. $node->status = 1;
  156. node_save($node);
  157. // Enable the hosting features of modules that we enable by default.
  158. // The module will already be enabled,
  159. // this makes sure we also set the default permissions.
  160. $default_hosting_features = array(
  161. 'hosting_web_server' => 'web_server',
  162. 'hosting_db_server' => 'db_server',
  163. 'hosting_platform' => 'platform',
  164. 'hosting_client' => 'client',
  165. 'hosting_task' => 'task',
  166. 'hosting_server' => 'server',
  167. 'hosting_package' => 'package',
  168. 'hosting_site' => 'site',
  169. 'hosting' => 'hosting',
  170. );
  171. hosting_features_enable($default_hosting_features, $rebuild = TRUE, $enable = FALSE);
  172. variable_set('site_frontpage', 'hosting/sites');
  173. // do not allow user registration: the signup form will do that
  174. variable_set('user_register', 0);
  175. // This is saved because the config generation script is running via drush, and does not have access to this value
  176. variable_set('install_url' , $GLOBALS['base_url']);
  177. }
  178. function hostmaster_task_finalize() {
  179. variable_set('install_profile', 'hostmaster');
  180. // Enable Eldir, and set is as default theme
  181. theme_enable(array('eldir'));
  182. variable_set('theme_default', 'eldir');
  183. // Disable the default Bartik theme
  184. theme_disable(array('bartik'));
  185. drupal_set_message(st('Configuring default blocks'));
  186. hostmaster_place_blocks('eldir');
  187. // Save "menu_options" for our content types, so they don't offer to be put in menus.
  188. variable_set('menu_options_client', array());
  189. variable_set('menu_options_platform', array());
  190. variable_set('menu_options_server', array());
  191. variable_set('menu_options_site', array());
  192. }
  193. /**
  194. * Helper function to place block.
  195. */
  196. function hostmaster_place_blocks($theme) {
  197. $blocks = array(
  198. array(
  199. 'module' => 'hosting',
  200. 'delta' => 'hosting_queues',
  201. 'theme' => $theme,
  202. 'status' => 1,
  203. 'weight' => -2,
  204. 'region' => 'sidebar_first',
  205. 'visibility' => 0,
  206. 'pages' => '',
  207. 'cache' => -1,
  208. ),
  209. array(
  210. 'module' => 'system',
  211. 'delta' => 'navigation',
  212. 'theme' => $theme,
  213. 'status' => 1,
  214. 'weight' => 0,
  215. 'region' => 'sidebar_first',
  216. 'visibility' => 0,
  217. 'pages' => '',
  218. 'cache' => -1,
  219. ),
  220. array(
  221. 'module' => 'views',
  222. 'delta' => 'hosting_task_list-block',
  223. 'theme' => $theme,
  224. 'status' => 1,
  225. 'weight' => -2,
  226. 'region' => 'sidebar_first',
  227. 'visibility' => 0,
  228. 'pages' => '',
  229. 'cache' => -1,
  230. ),
  231. array(
  232. 'module' => 'views',
  233. 'delta' => 'hosting_site_list-block_sites',
  234. 'theme' => $theme,
  235. 'status' => 1,
  236. 'weight' => 0,
  237. 'region' => 'content_bottom',
  238. 'visibility' => 1,
  239. 'pages' => 'hosting/c/platform_*',
  240. 'cache' => -1,
  241. ),
  242. array(
  243. 'module' => 'views',
  244. 'delta' => 'hosting_platform_list-block_1',
  245. 'theme' => $theme,
  246. 'status' => 1,
  247. 'weight' => 0,
  248. 'region' => 'content_bottom',
  249. 'visibility' => 1,
  250. 'pages' => 'hosting/c/server_*',
  251. 'cache' => -1,
  252. ),
  253. array(
  254. 'module' => 'views',
  255. 'delta' => 'hosting_site_list-block_profile',
  256. 'theme' => $theme,
  257. 'status' => 1,
  258. 'weight' => 0,
  259. 'region' => 'content_bottom',
  260. 'visibility' => 0,
  261. 'pages' => '',
  262. //"<?php\n\$node = menu_get_object();\nif (!empty(\$node)) {\n return \$node->package_type == 'profile';\n}\n
  263. 'cache' => -1,
  264. ),
  265. array(
  266. 'module' => 'views',
  267. 'delta' => 'hosting_site_list-block_client',
  268. 'theme' => $theme,
  269. 'status' => 1,
  270. 'weight' => 0,
  271. 'region' => 'content_bottom',
  272. 'visibility' => 0,
  273. 'pages' => '',
  274. //"<?php\n\$node = menu_get_object();\n\$menu_item = menu_get_item();\nif (!empty(\$node) && \$menu_item['number_parts'] == 2) {\n return \$node->type == 'client';\n}\n
  275. 'cache' => -1,
  276. ),
  277. array(
  278. 'module' => 'views',
  279. 'delta' => 'hosting_site_list-block_client2',
  280. 'theme' => $theme,
  281. 'status' => 1,
  282. 'weight' => 0,
  283. 'region' => 'content_bottom',
  284. 'visibility' => 0,
  285. 'pages' => '',
  286. //"<?php\nglobal \$user;\$node = menu_get_object();\n\$menu_item = menu_get_item();\nif (!empty(\$node)) && \$menu_item['number_parts'] == 2) {\n return \$node->type == 'client' && $user->uid != 1;\n}\n
  287. 'cache' => -1,
  288. ),
  289. array(
  290. 'module' => 'views',
  291. 'delta' => 'hosting_package_list-block_1',
  292. 'theme' => $theme,
  293. 'status' => 1,
  294. 'weight' => 0,
  295. 'region' => 'content_bottom',
  296. 'visibility' => 0,
  297. 'pages' => '',
  298. //"<?php\n\$node = menu_get_object();\nif (!empty(\$node)) {\n return \$node->type == 'package' && \$node->package_type != 'profile';\n}\n
  299. 'cache' => -1,
  300. ),
  301. );
  302. $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'visibility', 'pages', 'cache'));
  303. foreach ($blocks as $block) {
  304. $query->values($block);
  305. }
  306. $query->execute();
  307. }