page_title.install 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * @file page_title.install
  4. *
  5. * Handles the install, uninstall and updating of Page Title
  6. */
  7. /**
  8. * Implements hook_schema().
  9. */
  10. function page_title_schema() {
  11. $schema['page_title'] = array(
  12. 'fields' => array(
  13. 'type' => array('type' => 'varchar', 'length' => 15, 'not null' => TRUE, 'default' => 'node'),
  14. 'id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  15. 'page_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')
  16. ),
  17. 'primary key' => array('type', 'id'),
  18. );
  19. return $schema;
  20. }
  21. /**
  22. * Implements hook_update_n().
  23. */
  24. function page_title_update_6200() {
  25. $ret = array();
  26. if (db_column_exists('page_title', 'id')) {
  27. return $ret;
  28. }
  29. db_create_table($ret, 'page_title_temp', array(
  30. 'fields' => array(
  31. 'type' => array('type' => 'varchar', 'length' => 15, 'not null' => TRUE, 'default' => 'node'),
  32. 'id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
  33. 'page_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')
  34. ),
  35. 'primary key' => array('type', 'id'),
  36. ));
  37. $ret[] = update_sql('INSERT INTO {page_title_temp} (id, page_title) SELECT nid, page_title FROM {page_title}');
  38. db_rename_table($ret, 'page_title', 'page_title_old');
  39. db_rename_table($ret, 'page_title_temp', 'page_title');
  40. $display_settings = variable_get('page_title_display', array());
  41. foreach ($display_settings as $type) {
  42. if ($type) {
  43. variable_set('page_title_type_' . $type . '_showfield', 1);
  44. }
  45. }
  46. variable_del('page_title_display');
  47. return $ret;
  48. }
  49. /**
  50. * Implements hook_update_n().
  51. * Rename all the Vocabulary settings to reference by the new Machine Name, rather than Vocab ID.
  52. */
  53. function page_title_update_7200() {
  54. $ret = array();
  55. // If taxonomy not enabled, do no further updates
  56. if (!module_exists('taxonomy')) {
  57. return $ret;
  58. }
  59. foreach (taxonomy_get_vocabularies() as $vocab) {
  60. $page_title_vocab_settings = variable_get("page_title_vocab_{$vocab->vid}", FALSE);
  61. $page_title_vocab_showfield = variable_get("page_title_vocab_{$vocab->vid}_showfield", FALSE);
  62. if ($page_title_vocab_settings) {
  63. variable_set("page_title_vocab_{$vocab->machine_name}", $page_title_vocab_settings);
  64. }
  65. if ($page_title_vocab_showfield) {
  66. variable_set("page_title_vocab_{$vocab->machine_name}_showfield", $page_title_vocab_showfield);
  67. }
  68. variable_del("page_title_vocab_{$vocab->vid}_showfield");
  69. variable_del("page_title_vocab_{$vocab->vid}");
  70. }
  71. return $ret;
  72. }
  73. /**
  74. * Implements hook_uninstall().
  75. */
  76. function page_title_uninstall() {
  77. // Clear variables
  78. variable_del('page_title_default');
  79. variable_del('page_title_individual');
  80. variable_del('page_title_front');
  81. variable_del('page_title_blog');
  82. variable_del('page_title_user');
  83. variable_del('page_title_user_showfield');
  84. variable_del('page_title_pager_pattern');
  85. variable_del('page_title_forum_root_title');
  86. variable_del('page_title_comment_reply');
  87. variable_del('page_title_comment_child_reply');
  88. // Clear the node specific variables
  89. $types = node_type_get_names();
  90. foreach ($types as $type => $name) {
  91. variable_del("page_title_type_{$type}");
  92. variable_del("page_title_type_{$type}_showfield");
  93. }
  94. // Clear the vocab specific variables
  95. if (module_exists('taxonomy')) {
  96. $vocabs = taxonomy_get_vocabularies();
  97. foreach ($vocabs as $vid => $vocab) {
  98. variable_del("page_title_vocab_{$vocab->machine_name}");
  99. variable_del("page_title_vocab_{$vocab->machine_name}_showfield");
  100. // Legacy delete - just in case the uninstall is happening befoer update 7200
  101. variable_del("page_title_vocab_{$vid}");
  102. variable_del("page_title_vocab_{$vid}_showfield");
  103. }
  104. }
  105. }