hosting.install

Define database schemas and update functions for the hosting module.

Functions

Namesort descending Description
hosting_install Implements hook_install().
hosting_schema Implements hook_schema().
hosting_update_1 Implements hook_update_N().
hosting_update_2 Implements hook_update_N().
hosting_update_3 Implements hook_update_N().
hosting_update_6000 Implements hook_update_N().
hosting_update_6001 Implements hook_update_N().
hosting_update_6002 Implements hook_update_N().
hosting_update_6003 Implements hook_update_N().
hosting_update_6004 Implements hook_update_N().
hosting_update_6005 Implements hook_update_N().
hosting_update_6006 Implements hook_update_N().
hosting_update_6007 Implements hook_update_N().
hosting_update_6008 Implements hook_update_N().
hosting_update_6009 Implements hook_update_N().
hosting_update_6010 Implements hook_update_N().
hosting_update_6011 Implements hook_update_N().
hosting_update_6012 Implements hook_update_N().
hosting_update_6013 Implements hook_update_N().
hosting_update_6014 Implements hook_update_N().
hosting_update_6015 Implements hook_update_N().
hosting_update_6201 Replace lists with Views.
hosting_update_6202 Provide a welcome message for anonymous users.
hosting_update_6203 Delete hosting features junk variables.
hosting_update_6204 Create new roles.
hosting_update_6205 Add permissions to roles.
hosting_update_6206 Enable the jquery_update module.
hosting_update_6207 Alter the length available for a site alias to 235.

File

hosting.install
View source
  1. <?php
  2. /**
  3. * @file
  4. * Define database schemas and update functions for the hosting module.
  5. */
  6. // HOSTING_MAX_ALIAS_LENGTH is defined here:
  7. require_once(dirname(__FILE__) . '/hosting.module');
  8. /**
  9. * Implements hook_schema().
  10. */
  11. function hosting_schema() {
  12. $schema['hosting_context'] = array(
  13. 'fields' => array(
  14. 'nid' => array(
  15. 'type' => 'int',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. 'default' => 0,
  19. ),
  20. 'name' => array(
  21. 'type' => 'varchar',
  22. 'length' => HOSTING_MAX_ALIAS_LENGTH,
  23. 'not null' => TRUE,
  24. ),
  25. ),
  26. 'primary key' => array('nid'),
  27. 'unique keys' => array(
  28. 'name' => array('name'),
  29. ),
  30. );
  31. return $schema;
  32. }
  33. /**
  34. * Implements hook_install().
  35. */
  36. function hosting_install() {
  37. hosting_create_roles();
  38. }
  39. /**
  40. * Implements hook_update_N().
  41. *
  42. * Set weight for hosting module.
  43. */
  44. function hosting_update_1() {
  45. $ret = array();
  46. $ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE type='module' and name='hosting'");
  47. return $ret;
  48. }
  49. /**
  50. * Implements hook_update_N().
  51. *
  52. * Update function to remove unused table
  53. */
  54. function hosting_update_2() {
  55. $ret = array();
  56. $ret[] = update_sql("DROP TABLE {hosting_config_template}");
  57. return $ret;
  58. }
  59. /**
  60. * Implements hook_update_N().
  61. *
  62. * Hide hostmaster and hostslave profiles.
  63. */
  64. function hosting_update_3() {
  65. $ret = array();
  66. $result = db_query("select n.nid from {node} n left join hosting_package p on n.nid = p.nid where short_name in ('hostslave', 'hostmaster')");
  67. while ($obj = db_fetch_object($result)) {
  68. $in[] = (int) $obj->nid;
  69. }
  70. $in = implode(", ", $in);
  71. $ret[] = update_sql("UPDATE {node} SET status = 0 WHERE nid IN (" . $in . ")", $values);
  72. return $ret;
  73. }
  74. /**
  75. * Implements hook_update_N().
  76. *
  77. * Enable the modalframe and jquery_ui modules.
  78. */
  79. function hosting_update_6000() {
  80. $ret = array();
  81. module_enable(array('modalframe', 'jquery_ui'));
  82. return $ret;
  83. }
  84. /**
  85. * Implements hook_update_N().
  86. *
  87. * Change the default configured blocks to match eldir.
  88. */
  89. function hosting_update_6001() {
  90. $ret = array();
  91. module_enable(array('install_profile_api'));
  92. drupal_load('module', 'install_profile_api');
  93. install_include(array('block'));
  94. $theme = 'eldir';
  95. install_disable_block('hosting', 'hosting_queues_summary', $theme);
  96. install_set_block('user', 0 , $theme, 'right', 0);
  97. install_set_block('user', 1 , $theme, 'right', 0);
  98. install_set_block('hosting', 'hosting_queues', $theme, 'right', 5);
  99. install_set_block('hosting', 'hosting_summary', $theme, 'right', 10);
  100. return $ret;
  101. }
  102. /**
  103. * Implements hook_update_N().
  104. *
  105. * no-op - this used to verify one platform and all sites but breaks
  106. * major upgrades.
  107. */
  108. function hosting_update_6002() {
  109. return array();
  110. }
  111. /**
  112. * Implements hook_update_N().
  113. *
  114. * Lower the default amount of concurrent tasks.
  115. */
  116. function hosting_update_6003() {
  117. $ret = array();
  118. variable_set('hosting_queue_tasks_items', 5);
  119. return $ret;
  120. }
  121. /**
  122. * Implements hook_update_N().
  123. *
  124. * Stricter initial permissions for the anonymous user.
  125. */
  126. function hosting_update_6004() {
  127. $ret = array();
  128. install_include(array('user'));
  129. install_remove_permissions(install_get_rid('anonymous user'), array('access content', 'access all views'));
  130. install_remove_permissions(install_get_rid('authenticated user'), array('access content', 'access all views'));
  131. return $ret;
  132. }
  133. /**
  134. * Implements hook_update_N().
  135. *
  136. * Move some menu items to the primary links menu.
  137. */
  138. function hosting_update_6005() {
  139. drupal_install_modules(array('hosting_server'));
  140. menu_rebuild();
  141. install_include(array('menu'));
  142. $menu_name = variable_get('menu_primary_links_source', 'primary-links');
  143. $items = install_menu_get_items('hosting/servers');
  144. $item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
  145. $item['menu_name'] = $menu_name;
  146. $item['customized'] = 1;
  147. $item['options'] = unserialize($item['options']);
  148. install_menu_update_menu_item($item);
  149. $items = install_menu_get_items('hosting/sites');
  150. $item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
  151. $item['menu_name'] = $menu_name;
  152. $item['customized'] = 1;
  153. $item['options'] = unserialize($item['options']);
  154. install_menu_update_menu_item($item);
  155. menu_rebuild();
  156. return array();
  157. }
  158. /**
  159. * Implements hook_update_N().
  160. *
  161. * Move the platforms into primary links.
  162. */
  163. function hosting_update_6006() {
  164. install_include(array('menu'));
  165. $menu_name = variable_get('menu_primary_links_source', 'primary-links');
  166. $items = install_menu_get_items('hosting/platforms');
  167. $item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
  168. $item['menu_name'] = $menu_name;
  169. $item['customized'] = 1;
  170. $item['options'] = unserialize($item['options']);
  171. install_menu_update_menu_item($item);
  172. return array();
  173. }
  174. /**
  175. * Implements hook_update_N().
  176. *
  177. * Update the default db_server now that we've merged the webserver and dbserver nodes
  178. * See http://drupal.org/node/731550
  179. */
  180. function hosting_update_6007() {
  181. variable_set('hosting_default_db_server', variable_get('hosting_default_web_server', 3));
  182. variable_set('hosting_own_db_server', variable_get('hosting_default_web_server', 3));
  183. return array();
  184. }
  185. /**
  186. * Implements hook_update_N().
  187. *
  188. * Add hosting_context table to map alias names.
  189. */
  190. function hosting_update_6008() {
  191. $return = array();
  192. if (!variable_get('hosting_update_6008_run', FALSE)) {
  193. db_create_table($return, 'hosting_context', array(
  194. 'fields' => array(
  195. 'nid' => array(
  196. 'type' => 'int',
  197. 'unsigned' => TRUE,
  198. 'not null' => TRUE,
  199. 'default' => 0,
  200. ),
  201. 'name' => array(
  202. 'type' => 'varchar',
  203. 'length' => 50,
  204. 'not null' => TRUE,
  205. ),
  206. ),
  207. 'primary key' => array('nid'),
  208. 'unique keys' => array(
  209. 'name' => array('name')
  210. ),
  211. ));
  212. variable_set('hosting_update_6008_run', TRUE);
  213. $records = array();
  214. $result = db_query("SELECT n.nid, title FROM {node} n LEFT JOIN {hosting_site} s ON n.nid=s.nid WHERE s.status <> -2 AND n.type='site'");
  215. while ($object = db_fetch_object($result)) {
  216. $records[$object->nid] = $object->title;
  217. }
  218. $result = db_query("SELECT n.nid, title FROM {node} n LEFT JOIN {hosting_server} s ON n.nid=s.nid WHERE n.status = 1 AND n.type='server'");
  219. while ($object = db_fetch_object($result)) {
  220. $records[$object->nid] = 'server_' . preg_replace("/[!\W\.\-]/", "", $object->title);
  221. }
  222. // We start with the web server because we assume that the main hostmaster site is installed locally.
  223. $server_id = variable_get('hosting_default_web_server', 3);
  224. $records[$server_id] = 'server_master';
  225. foreach ($records as $nid => $name) {
  226. hosting_context_register($nid, $name);
  227. }
  228. }
  229. return $return;
  230. }
  231. /**
  232. * Implements hook_update_N().
  233. *
  234. * Fix the reference to the master server so that it no longer points at localhost.
  235. */
  236. function hosting_update_6009() {
  237. // This undoes the change we made previously in update_6008, but can be run again.
  238. $ret = array();
  239. db_query("UPDATE {hosting_context} SET name='server_master' WHERE name='server_localhost'");
  240. $nid = db_result(db_query("SELECT nid from {hosting_context} WHERE name='server_master'"));
  241. $uname = php_uname('n');
  242. db_query("UPDATE {node} SET title='%s' WHERE nid=%d", $uname, $nid);
  243. db_query("UPDATE {node_revisions} SET title='%s' WHERE nid=%d", $uname, $nid);
  244. return $ret;
  245. }
  246. /**
  247. * Implements hook_update_N().
  248. *
  249. * Add url aliases for the context names that are registered.
  250. */
  251. function hosting_update_6010() {
  252. // We include the file instead of enabling the module,
  253. // because we do not want the overhead of having all the
  254. // path UI stuff on nodes.
  255. require_once("./modules/path/path.module");
  256. $ret = array();
  257. $result = db_query("SELECT nid, name FROM {hosting_context}");
  258. while ($obj = db_fetch_object($result)) {
  259. path_set_alias("node/$obj->nid", "hosting/c/$obj->name");
  260. }
  261. return $ret;
  262. }
  263. /**
  264. * Implements hook_update_N().
  265. *
  266. * Clients and packages were imported as belonging to the anonymous user. Reassign them to the admin user.
  267. */
  268. function hosting_update_6011() {
  269. $ret = array();
  270. db_query("UPDATE {node} SET uid=1 WHERE uid=0 AND type IN ('client', 'package')");
  271. return $ret;
  272. }
  273. /**
  274. * Implements hook_update_N().
  275. *
  276. * Remove the hosting summary block.
  277. */
  278. function hosting_update_6012() {
  279. $ret = array();
  280. drupal_load('module', 'install_profile_api');
  281. install_include(array('block'));
  282. $theme = 'eldir';
  283. install_disable_block('hosting', 'hosting_summary', $theme);
  284. return $ret;
  285. }
  286. /**
  287. * Implements hook_update_N().
  288. *
  289. * Add a permission allowing users to view the 'site disabled' message, which got
  290. * lost when 'access content' permission was revoked a while ago.
  291. */
  292. function hosting_update_6013() {
  293. $ret = array();
  294. install_include(array('user'));
  295. install_add_permissions(install_get_rid('anonymous user'), array('access disabled sites'));
  296. install_add_permissions(install_get_rid('authenticated user'), array('access disabled sites'));
  297. return $ret;
  298. }
  299. /**
  300. * Implements hook_update_N().
  301. *
  302. * Restore proper weight to the hosting module.
  303. *
  304. * For some obscure reason, the weight is 10 which makes its updates run
  305. * after all others, which gave us constant issues during upgrades.
  306. */
  307. function hosting_update_6014() {
  308. $ret = array();
  309. $ret[] = update_sql("UPDATE {system} SET weight = 0 WHERE type='module' and name='hosting'");
  310. return $ret;
  311. }
  312. /**
  313. * Implements hook_update_N().
  314. *
  315. * Delete URL aliases for sites that have been deleted.
  316. *
  317. * Ideally we'd do this in a single DB query, but there isn't a nice performant
  318. * way to do it, so we do more DB queries instead of using potentially a lot of
  319. * memory. Basically this may take a long time to run, but it shouldn't run out
  320. * of resources doing so.
  321. */
  322. function hosting_update_6015(&$sandbox) {
  323. $ret = array();
  324. if (!isset($sandbox['progress'])) {
  325. $sandbox['progress'] = 0;
  326. $sandbox['current_pid'] = 0;
  327. $sandbox['max'] = db_result(db_query('SELECT COUNT(pid) FROM {url_alias} WHERE dst LIKE "hosting/c/%" AND pid > 0'));
  328. }
  329. $aliases = db_query_range("SELECT pid, src, dst FROM {url_alias} WHERE dst LIKE 'hosting/c/%' AND pid > %d ORDER BY pid ASC", $sandbox['current_pid'], 0, 50);
  330. while ($alias = db_fetch_object($aliases)) {
  331. // Get the node ID for the alias.
  332. $nid = preg_replace('#^node/#', '', $alias->src);
  333. if (is_numeric($nid)) {
  334. // Check to see if the corresponding context has been deleted.
  335. if (!db_result(db_query('SELECT COUNT(nid) FROM {hosting_context} WHERE nid = %d', $nid))) {
  336. db_query('DELETE FROM {url_alias} WHERE pid = %d', $alias->pid);
  337. }
  338. }
  339. $sandbox['progress']++;
  340. $sandbox['current_pid'] = $alias->pid;
  341. }
  342. $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
  343. return $ret;
  344. }
  345. /**
  346. * Replace lists with Views.
  347. */
  348. function hosting_update_6201() {
  349. $ret = array();
  350. // Remove menu links that will be replaced by Views
  351. menu_link_delete(NULL, 'hosting/platforms');
  352. menu_link_delete(NULL, 'hosting/sites');
  353. // Enable and install Views and Views Bulk operations.
  354. drupal_install_modules(array('views', 'views_bulk_operations'));
  355. // Flush all Drupal caches.
  356. drupal_flush_all_caches();
  357. // Temporarily enable Install Profile API module and load includes.
  358. module_enable(array('install_profile_api'));
  359. drupal_load('module', 'install_profile_api');
  360. install_include(array('block'));
  361. // Enable blocks.
  362. $theme = 'eldir';
  363. install_set_block('views', 'hosting_task_list-block' , $theme, 'right', 0);
  364. install_set_block('views', '-exp-hosting_site_list-page_sites' , $theme, 'content_top', 0, 1, 'hosting/sites');
  365. install_set_block('views', 'hosting_site_list-block_platform' , $theme, 'content_bottom', 0, 1, 'hosting/c/platform_*');
  366. install_set_block('views', 'hosting_site_list-block_profile' , $theme, 'content_bottom', 0, 2, "<?php\n\$node = menu_get_object();\nif (!empty(\$node)) {\n return \$node->package_type == 'profile';\n}\n?>");
  367. install_set_block('views', 'hosting_site_list-block_client' , $theme, 'content_bottom', 0, 2, "<?php\n\$node = menu_get_object();\nif (!empty(\$node)) {\n return \$node->type == 'client';\n}\n?>");
  368. module_disable(array('install_profile_api'));
  369. return $ret;
  370. }
  371. /**
  372. * Provide a welcome message for anonymous users.
  373. */
  374. function hosting_update_6202() {
  375. $ret = array();
  376. // Flush the menu cache.
  377. menu_rebuild();
  378. return $ret;
  379. }
  380. /**
  381. * Delete hosting features junk variables.
  382. */
  383. function hosting_update_6203() {
  384. $ret = array();
  385. $features = hosting_get_features(TRUE);
  386. foreach ($features as $feature => $info) {
  387. if (variable_get($feature, FALSE) != FALSE) {
  388. variable_del($feature);
  389. }
  390. }
  391. }
  392. /**
  393. * Create new roles.
  394. */
  395. function hosting_update_6204() {
  396. $ret = array();
  397. // Temporarily enable Install Profile API module and load includes.
  398. module_enable(array('install_profile_api'));
  399. module_load_include('inc', 'install_profile_api', 'core/user');
  400. install_remove_permissions(install_get_rid('aegir client'), array('access all views'));
  401. install_add_role('aegir platform manager');
  402. install_add_permissions(install_get_rid('aegir platform manager'), array('create clone task', 'create migrate task', 'create platform', 'delete platform', 'edit platform', 'view locked platforms', 'view platform', 'create site', 'delete site', 'edit site', 'view site', 'access task logs', 'create lock task', 'create unlock task', 'view revisions', 'search content', 'use advanced search'));
  403. install_add_role('aegir administrator');
  404. install_add_permissions(install_get_rid('aegir administrator'), array('access disabled sites', 'access hosting wizard', 'administer hosting', 'administer hosting features', 'administer hosting queues', 'administer hosting settings', 'administer hosting aliases', 'create site aliases', 'administer clients', 'create client', 'delete own client', 'edit client uname', 'edit client users', 'edit own client', 'view client', 'create clone task', 'create migrate task', 'create package', 'delete package', 'edit package', 'view package', 'create platform', 'delete platform', 'edit platform', 'view locked platforms', 'view platform', 'edit all quotas', 'view all quotas', 'view own quota', 'create server', 'delete server', 'edit server', 'view server', 'access hosting signup form', 'administer sites', 'create site', 'delete site', 'edit site', 'view site', 'create ssl certificate', 'access task logs', 'administer tasks', 'cancel own tasks', 'create backup task', 'create backup-delete task', 'create delete task', 'create disable task', 'create enable task', 'create lock task', 'create login-reset task', 'create restore task', 'create unlock task', 'create verify task', 'retry failed tasks', 'view own tasks', 'view task'));
  405. module_disable(array('install_profile_api'));
  406. return $ret;
  407. }
  408. /**
  409. * Add permissions to roles.
  410. */
  411. function hosting_update_6205() {
  412. $ret = array();
  413. // Temporarily enable Install Profile API module and load includes.
  414. module_enable(array('install_profile_api'));
  415. module_load_include('inc', 'install_profile_api', 'core/user');
  416. install_add_permissions(install_get_rid('aegir client'), array('view own quota', 'create site aliases', 'create verify task', 'create clone task', 'create migrate task', 'create ssl certificate', 'access task logs', 'view package', 'view platform', 'view revisions', 'edit site'));
  417. install_add_permissions(install_get_rid('aegir account manager'), array('administer clients', 'access content', 'access user profiles', 'edit all quotas', 'view all quotas', 'view own quota', 'edit client uname', 'view_site'));
  418. install_add_permissions(install_get_rid('aegir platform manager'), array('view package', 'administer platforms', 'cancel own tasks', 'view own tasks', 'access content', 'view task', 'administer sites', 'create verify task', 'retry failed tasks', 'administer clients', 'administer tasks'));
  419. install_add_permissions(install_get_rid('aegir administrator'), array('access administration menu', 'administer platforms', 'administer servers', 'access content', 'view revisions', 'administer hosting aliases', 'create site aliases', 'edit all quotas', 'view all quotas', 'view own quota', 'access hosting signup form', 'create ssl certificate', 'access user profiles', 'update status of tasks'));
  420. module_disable(array('install_profile_api'));
  421. return $ret;
  422. }
  423. /**
  424. * Enable the jquery_update module.
  425. */
  426. function hosting_update_6206() {
  427. $ret = array();
  428. module_enable(array('jquery_update'));
  429. return $ret;
  430. }
  431. /**
  432. * Alter the length available for a site alias to 235.
  433. *
  434. * https://drupal.org/node/1971348
  435. */
  436. function hosting_update_6207() {
  437. $ret = array();
  438. $spec = array(
  439. 'type' => 'varchar',
  440. // @see HOSTING_MAX_ALIAS_LENGTH
  441. 'length' => 235,
  442. 'not null' => TRUE,
  443. );
  444. db_change_field($ret, 'hosting_context', 'name', 'name', $spec);
  445. return $ret;
  446. }