current_search.install 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @file
  4. * Install, update, and uninstall functions for the Current Search Blocks
  5. * module.
  6. */
  7. /**
  8. * Implements hook_schema().
  9. */
  10. function current_search_schema() {
  11. $schema = array();
  12. $schema['current_search'] = array(
  13. 'description' => 'Current search block configurations.',
  14. 'export' => array(
  15. 'key' => 'name',
  16. 'identifier' => 'item',
  17. 'default hook' => 'current_search_default_items',
  18. 'delete callback' => 'current_search_export_crud_delete',
  19. 'api' => array(
  20. 'owner' => 'current_search',
  21. 'api' => 'current_search',
  22. 'minimum_version' => 1,
  23. 'current_version' => 1,
  24. ),
  25. ),
  26. 'fields' => array(
  27. 'name' => array(
  28. 'description' => 'The machine readable name of the configuration.',
  29. 'type' => 'varchar',
  30. 'length' => 255,
  31. 'not null' => TRUE,
  32. 'default' => '',
  33. ),
  34. 'label' => array(
  35. 'description' => 'The human readable name of the configuration.',
  36. 'type' => 'varchar',
  37. 'length' => 255,
  38. 'not null' => TRUE,
  39. 'default' => '',
  40. ),
  41. 'settings' => array(
  42. 'description' => 'Serialized storage of general settings.',
  43. 'type' => 'text',
  44. 'serialize' => TRUE,
  45. ),
  46. ),
  47. 'primary key' => array('name'),
  48. );
  49. $schema['block_current_search'] = array(
  50. 'description' => 'Sets up display criteria for blocks based on searcher',
  51. 'fields' => array(
  52. 'delta' => array(
  53. 'type' => 'varchar',
  54. 'length' => 32,
  55. 'not null' => TRUE,
  56. 'description' => "The block's unique delta within module, from {block}.delta.",
  57. ),
  58. 'searcher' => array(
  59. 'type' => 'varchar',
  60. 'length' => 128,
  61. 'not null' => TRUE,
  62. 'description' => "The machine-readable name of the searcher.",
  63. ),
  64. ),
  65. 'primary key' => array('delta'),
  66. 'indexes' => array(
  67. 'searcher' => array('searcher'),
  68. ),
  69. );
  70. return $schema;
  71. }
  72. /**
  73. * Implements hook_uninstall().
  74. */
  75. function current_search_uninstall() {
  76. // Remove Current Search blocks.
  77. // @see http://drupal.org/node/1567928
  78. if (db_table_exists('block')) {
  79. db_delete('block')->condition('module', 'current_search')->execute();
  80. }
  81. }
  82. /**
  83. * Update the structure of saved settings objects.
  84. */
  85. function current_search_update_7101() {
  86. // @see http://drupal.org/node/1379166
  87. $result = db_query('SELECT name, settings FROM {current_search}');
  88. foreach ($result as $record) {
  89. $settings = unserialize($record->settings);
  90. // Make our best guess as to whether or not we are using the old structure.
  91. if (count($settings) != 2 || !isset($settings['items']) || !isset($settings['advanced'])) {
  92. $settings = array(
  93. 'items' => $settings,
  94. 'advanced' => array(
  95. 'empty_searches' => 0,
  96. ),
  97. );
  98. db_update('current_search')
  99. ->fields(array('settings' => serialize($settings)))
  100. ->execute();
  101. }
  102. }
  103. }