search_api_solr.install 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Implements hook_schema().
  4. */
  5. function search_api_solr_schema() {
  6. // See, e.g., block_schema() for this trick. Seems to be the best way to get a
  7. // cache table definition.
  8. $schema['cache_search_api_solr'] = drupal_get_schema_unprocessed('system', 'cache');
  9. $schema['cache_search_api_solr']['description'] = 'Cache table for the Search API Solr module to store various data related to Solr servers.';
  10. return $schema;
  11. }
  12. /**
  13. * Implements hook_requirements().
  14. */
  15. function search_api_solr_requirements($phase) {
  16. $ret = array();
  17. if ($phase == 'runtime') {
  18. $servers = search_api_server_load_multiple(FALSE, array('class' => 'search_api_solr_service', 'enabled' => TRUE));
  19. $count = 0;
  20. $unavailable = 0;
  21. $last = NULL;
  22. foreach ($servers as $server) {
  23. if (!$server->ping()) {
  24. ++$unavailable;
  25. $last = $server;
  26. }
  27. ++$count;
  28. }
  29. if (!$count) {
  30. return array();
  31. }
  32. $ret['search_api_solr'] = array(
  33. 'title' => t('Solr servers'),
  34. 'value' => format_plural($count, '1 server', '@count servers'),
  35. );
  36. if ($unavailable) {
  37. if ($unavailable == 1) {
  38. $ret['search_api_solr']['description'] = t('The Solr server of <a href="!url">%name</a> could not be reached.',
  39. array('!url' => url('admin/config/search/search_api/server/' . $last->machine_name), '%name' => $last->name));
  40. }
  41. else {
  42. $ret['search_api_solr']['description'] = t('@count Solr servers could not be reached.', array('@count' => $unavailable));
  43. }
  44. $ret['search_api_solr']['severity'] = REQUIREMENT_ERROR;
  45. }
  46. else {
  47. $ret['search_api_solr']['description'] = format_plural($count, 'The Solr server could be reached.', 'All @count Solr servers could be reached.');
  48. $ret['search_api_solr']['severity'] = REQUIREMENT_OK;
  49. }
  50. }
  51. return $ret;
  52. }
  53. /**
  54. * Implements hook_uninstall().
  55. */
  56. function search_api_solr_uninstall() {
  57. variable_del('search_api_solr_last_optimize');
  58. variable_del('search_api_solr_autocomplete_max_occurrences');
  59. variable_del('search_api_solr_index_prefix');
  60. variable_del('search_api_solr_http_get_max_length');
  61. variable_del('search_api_solr_cron_action');
  62. variable_del('search_api_solr_site_hash');
  63. }
  64. /**
  65. * Implements hook_update_dependencies().
  66. */
  67. function search_api_solr_update_dependencies() {
  68. // This update should run after primary IDs have been changed to machine names in the framework.
  69. $dependencies['search_api_solr'][7101] = array(
  70. 'search_api' => 7102,
  71. );
  72. return $dependencies;
  73. }
  74. /**
  75. * Implements transition from using the index IDs to using machine names.
  76. */
  77. function search_api_solr_update_7101() {
  78. foreach (search_api_server_load_multiple(FALSE, array('class' => 'search_api_solr_service')) as $server) {
  79. if ($server->enabled) {
  80. $server->deleteItems('all');
  81. }
  82. else {
  83. $tasks = variable_get('search_api_tasks', array());
  84. $tasks[$server->machine_name][''] = array('clear all');
  85. variable_set('search_api_tasks', $tasks);
  86. }
  87. $query = db_select('search_api_index', 'i')
  88. ->fields('i', array('machine_name'))
  89. ->condition('server', $server->machine_name);
  90. db_update('search_api_item')
  91. ->fields(array(
  92. 'changed' => REQUEST_TIME,
  93. ))
  94. ->condition('index_id', $query, 'IN')
  95. ->execute();
  96. }
  97. return t('The Solr search module was updated. ' .
  98. 'Please stop your Solr servers, replace their schema.xml with the new version and then start them again. ' .
  99. 'All data indexed on Solr servers will have to be reindexed.');
  100. }
  101. /**
  102. * Create the Search API Solr cache table {cache_search_api_solr}.
  103. */
  104. function search_api_solr_update_7102() {
  105. if (!db_table_exists('cache_search_api_solr')) {
  106. $table = drupal_get_schema_unprocessed('system', 'cache');
  107. $table['description'] = 'Cache table for the Search API Solr module to store various data related to Solr servers.';
  108. db_create_table('cache_search_api_solr', $table);
  109. }
  110. }