seo_checklist.install 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the seo_checklist module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function seo_checklist_install() {
  10. // Detect and update a pre- name change installation.
  11. $result = db_query("SELECT * FROM {system} WHERE name = 'seochecklist'");
  12. if ($result->rowCount()) {
  13. seo_checklist_update_7400();
  14. }
  15. }
  16. /**
  17. * Implements hook_uninstall().
  18. */
  19. function seo_checklist_uninstall() {
  20. variable_del('checklistapi_checklist_seo_checklist');
  21. }
  22. /**
  23. * Rename module machine name and convert saved progress data to new format.
  24. *
  25. * Note: Drupal won't detect and run this function in the usual way, because
  26. * the change of module machine name causes it to lose track of the current
  27. * schema version, so it's invoked manually by seo_checklist_install(), if
  28. * appropriate.
  29. */
  30. function seo_checklist_update_7400() {
  31. // Convert saved progress data.
  32. if (db_table_exists('seo_checklist')) {
  33. $result = db_query('SELECT id, completed, uid FROM {seo_checklist}');
  34. $old_data = $result->fetchAllAssoc('id');
  35. $data_mapping = array(
  36. 'install_page_title' => 1,
  37. 'enable_clean_urls' => 2,
  38. 'install_pathauto' => 5,
  39. 'install_globalredirect' => 6,
  40. 'get_google_account' => 7,
  41. 'install_google_analytics' => 9,
  42. 'create_google_analytics_analytics' => 11,
  43. 'input_google_analytics_code' => 12,
  44. 'authenticate_with_google_analytics' => 13,
  45. 'install_metatags_quick' => 15,
  46. 'install_scheduler' => 16,
  47. 'install_htmlpurifier' => 17,
  48. 'install_search404' => 18,
  49. 'validate_html' => 19,
  50. 'check_links' => 20,
  51. 'install_xmlsitemap' => 21,
  52. 'authenticate_with_google' => 23,
  53. 'submit_xml_sitemap_to_google' => 24,
  54. 'submit_xml_sitemap_to_bing' => 28,
  55. 'add_to_google_places' => 29,
  56. 'install_addthis' => 30,
  57. 'install_service_links' => 31,
  58. 'install_mollom' => 39,
  59. 'sign_up_for_mollom_account' => 40,
  60. 'authenticate_with_bing' => 43,
  61. 'get_windows_live_id' => 44,
  62. 'install_htmlpurifier' => 45,
  63. 'install_site_map' => 46,
  64. 'install_site_verify' => 47,
  65. 'install_addtoany' => 49,
  66. 'add_geo_meta_tags' => 51,
  67. 'install_admin_menu' => 53,
  68. 'enable_drupal_caching' => 54,
  69. 'install_boost' => 55,
  70. 'install_seo_checker' => 57,
  71. 'install_fb_social' => 58,
  72. 'install_follow' => 59,
  73. 'install_elements' => 60,
  74. 'install_security_review' => 61,
  75. 'install_read_more' => 62,
  76. 'install_ga_tokenizer' => 63,
  77. 'install_contact_google_analytics' => 64,
  78. 'install_context_keywords' => 65,
  79. );
  80. global $user;
  81. $new_data = array(
  82. '#changed' => $time = time(),
  83. '#changed_by' => $user->uid,
  84. '#completed_items' => 0,
  85. );
  86. $definitions = seo_checklist_checklistapi_checklist_info();
  87. $groups = $definitions['seo_checklist'];
  88. foreach (element_children($groups) as $group_key) {
  89. $group = &$groups[$group_key];
  90. foreach (element_children($group) as $item_key) {
  91. if (!empty($data_mapping[$item_key])) {
  92. $old_item = $old_data[$data_mapping[$item_key]];
  93. if (!empty($old_item->completed)) {
  94. $new_data[$item_key] = array(
  95. '#completed' => $old_item->completed,
  96. '#uid' => $old_item->uid,
  97. );
  98. $new_data['#completed_items']++;
  99. }
  100. }
  101. if (!isset($new_data[$item_key])) {
  102. $new_data[$item_key] = 0;
  103. }
  104. }
  105. }
  106. if (variable_get('seo_checklist_link', 0)) {
  107. $new_data['link_to_volacci'] = array(
  108. '#completed' => $time,
  109. '#uid' => $user->uid,
  110. );
  111. }
  112. ksort($new_data);
  113. variable_set('checklistapi_checklist_seo_checklist', $new_data);
  114. }
  115. // Remove old database tables.
  116. foreach (array('seo_group', 'seo_checklist') as $table) {
  117. if (db_table_exists($table)) {
  118. db_drop_table($table);
  119. }
  120. }
  121. // Remove the old "seochecklist" row from the system table.
  122. db_delete('system')
  123. ->condition('name', 'seochecklist')
  124. ->execute();
  125. // Remove now unused variables.
  126. variable_del('seo_checklist_book_references');
  127. variable_del('seo_checklist_link');
  128. variable_del('seo_checklist_podcast');
  129. variable_del('seo_checklist_thanks');
  130. }