hosting_alias.install

Define database schema and update function for the site aliases module.

Functions

Namesort descending Description
hosting_alias_schema Implements hook_schema().
hosting_alias_update_1 Implements hook_update_N().
hosting_alias_update_2 Implements hook_update_N().
hosting_alias_update_6203 Alter the redirection field to a varchar
hosting_alias_update_6204 Fixup redirection data after table change in hosting_alias_update_6203()

File

alias/hosting_alias.install
View source
  1. <?php
  2. /**
  3. * @file
  4. * Define database schema and update function for the site aliases module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function hosting_alias_schema() {
  10. $schema['hosting_site_alias'] = array(
  11. 'fields' => array(
  12. 'vid' => array(
  13. 'type' => 'int',
  14. 'not null' => TRUE,
  15. 'default' => 0,
  16. ),
  17. 'nid' => array(
  18. 'type' => 'int',
  19. 'unsigned' => TRUE,
  20. 'not null' => TRUE,
  21. 'default' => 0,
  22. ),
  23. 'alias' => array(
  24. 'type' => 'varchar',
  25. 'length' => 128,
  26. 'not null' => TRUE,
  27. ),
  28. 'automatic' => array(
  29. 'type' => 'int',
  30. 'not null' => TRUE,
  31. 'default' => 0,
  32. ),
  33. 'redirection' => array(
  34. 'type' => 'varchar',
  35. 'length' => 255,
  36. 'not null' => TRUE,
  37. ),
  38. ),
  39. 'indexes' => array(
  40. 'vid' => array('vid'),
  41. 'alias' => array('alias'),
  42. ),
  43. );
  44. return $schema;
  45. }
  46. /**
  47. * Implements hook_update_N().
  48. *
  49. * This removes dodgy data created by an import bug.
  50. */
  51. function hosting_alias_update_1() {
  52. $ret = array();
  53. $ret[] = update_sql("DELETE FROM {hosting_site_alias} WHERE alias='Array'");
  54. return $ret;
  55. }
  56. /**
  57. * Implements hook_update_N().
  58. *
  59. * Add the redirection field.
  60. */
  61. function hosting_alias_update_2() {
  62. $ret = array();
  63. db_add_field($ret, 'hosting_site_alias', 'redirection', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
  64. return $ret;
  65. }
  66. /**
  67. * Alter the redirection field to a varchar
  68. */
  69. function hosting_alias_update_6203() {
  70. $ret = array();
  71. $spec = array(
  72. 'type' => 'varchar',
  73. 'length' => 255,
  74. 'not null' => TRUE,
  75. );
  76. db_change_field($ret, 'hosting_site_alias', 'redirection', 'redirection', $spec);
  77. return $ret;
  78. }
  79. /**
  80. * Fixup redirection data after table change in hosting_alias_update_6203()
  81. */
  82. function hosting_alias_update_6204() {
  83. $ret = array();
  84. $result = db_query("SELECT alias.nid FROM {hosting_site_alias} alias INNER JOIN {hosting_site} site ON site.nid = alias.nid WHERE redirection=1 AND site.status>-2");
  85. while ($obj = db_fetch_object($result)) {
  86. $node = node_load($obj->nid);
  87. if (is_object($node)) {
  88. $node->redirection = $node->title;
  89. hosting_alias_update($node);
  90. // Run a verify task to update the vhost
  91. hosting_add_task($node->nid, 'verify');
  92. }
  93. }
  94. return $ret;
  95. }