custom_search.install 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @file
  4. * Install, update, and uninstall functions for the custom search module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function custom_search_install() {
  10. db_update('system')
  11. ->fields(array('weight' => 100))
  12. ->condition('name', 'custom_search')
  13. ->execute();
  14. }
  15. /**
  16. * Implements hook_uninstall().
  17. */
  18. function custom_search_uninstall() {
  19. db_delete('variable')
  20. ->condition('name', 'custom_search_%', 'LIKE')
  21. ->execute();
  22. }
  23. /**
  24. * Implements hook_enable().
  25. */
  26. function custom_search_enable() {
  27. drupal_set_message(t('Custom Search enabled. Don\'t forget to <a href="@link">set permissions</a>.', array('@link' => url('admin/people/permissions', array('fragment' => 'module-custom_search')))));
  28. }
  29. /**
  30. * Increases the module weight.
  31. */
  32. function custom_search_update_7100() {
  33. db_update('system')
  34. ->fields(array('weight' => 100))
  35. ->condition('name', 'custom_search')
  36. ->execute();
  37. return t("Module's weight increased.");
  38. }
  39. /**
  40. * New sub-modules notice.
  41. */
  42. function custom_search_update_7101() {
  43. return t('Custom Search has been divided in multiple modules. Please re-enable the sub-modules you need.');
  44. }
  45. /**
  46. * Custom search paths upgrade.
  47. */
  48. function custom_search_update_7102() {
  49. if (variable_get('custom_search_path', '') != '') {
  50. variable_set('custom_search_paths', variable_get('custom_search_path', '') . '|Custom path');
  51. }
  52. variable_del('custom_search_path');
  53. return t('Custom search paths upgraded.');
  54. }
  55. /**
  56. * Changes in the advanced search form settings.
  57. */
  58. function custom_search_update_7103() {
  59. if (variable_get('custom_search_results_advanced_override', FALSE)) {
  60. variable_set('custom_search_advanced_or_display', variable_get('custom_search_criteria_or_display', FALSE));
  61. variable_set('custom_search_advanced_phrase_display', variable_get('custom_search_criteria_phrase_display', FALSE));
  62. variable_set('custom_search_advanced_negative_display', variable_get('custom_search_criteria_negative_display', FALSE));
  63. $types = array_keys(array_filter(variable_get('custom_search_node_types', array())));
  64. if (count($types)) {
  65. $names = array_keys(node_type_get_names());
  66. foreach ($names as $name) {
  67. if (!in_array($name, $types)) {
  68. variable_set('custom_search_advanced_type_' . $name . '_display', FALSE);
  69. }
  70. }
  71. }
  72. if (module_exists('taxonomy')) {
  73. $vocabularies = taxonomy_get_vocabularies();
  74. foreach ($vocabularies as $voc) {
  75. if (variable_get('custom_search_voc' . $voc->vid . '_selector', 'disabled') == 'disabled') {
  76. variable_set('custom_search_advanced_voc' . $voc->vid . '_display', FALSE);
  77. }
  78. }
  79. }
  80. }
  81. variable_del('custom_search_results_advanced_override');
  82. return t('Advanced search form settings changed.');
  83. }
  84. /**
  85. * Store vids - machine names association.
  86. */
  87. function custom_search_update_7104() {
  88. if (module_exists('taxonomy')) {
  89. $vocabularies = taxonomy_get_vocabularies();
  90. $machine_names = array();
  91. foreach ($vocabularies as $voc) {
  92. $machine_names[$voc->machine_name] = $voc->vid;
  93. }
  94. // This will be needed for those upgrading to Drupal 8 or Backdrop.
  95. variable_set('custom_search_taxonomy_machine_names', $machine_names);
  96. }
  97. }