search.drush.inc

  1. 8.0.x commands/core/search.drush.inc
  2. 6.x commands/core/search.drush.inc
  3. 7.x commands/core/search.drush.inc
  4. 3.x commands/core/search.drush.inc
  5. 4.x commands/core/search.drush.inc
  6. 5.x commands/core/search.drush.inc
  7. master commands/core/search.drush.inc

Functions

File

commands/core/search.drush.inc
View source
  1. <?php
  2. function drush_core_search_status() {
  3. list($remaining, $total) = _drush_core_search_status();
  4. drush_print(dt('There are @remaining items out of @total still to be indexed.', array(
  5. '@remaining' => $remaining,
  6. '@total' => $total,
  7. )));
  8. drush_print_pipe("$remaining/$total\n");
  9. }
  10. function _drush_core_search_status() {
  11. $remaining = 0;
  12. $total = 0;
  13. if (drush_drupal_major_version() >= 7) {
  14. foreach (module_implements('search_status') as $module) {
  15. $status = module_invoke($module, 'search_status');
  16. $remaining += $status['remaining'];
  17. $total += $status['total'];
  18. }
  19. }
  20. else {
  21. foreach (module_implements('search') as $module) {
  22. // Special case. Apachesolr recommends disabling core indexing with
  23. // search_cron_limit = 0. Need to avoid infinite status loop.
  24. if ($module == 'node' && variable_get('search_cron_limit', 10) == 0) {
  25. continue;
  26. }
  27. $status = module_invoke($module, 'search', 'status');
  28. $remaining += $status['remaining'];
  29. $total += $status['total'];
  30. }
  31. }
  32. return array($remaining, $total);
  33. }
  34. function drush_core_search_index() {
  35. drush_print(dt("Building the index may take a long time."));
  36. if (!drush_confirm(dt('Do you really want to continue?'))) {
  37. return drush_set_error('CORE_SEARCH_REBUILD_ABORT', 'Aborting.');
  38. }
  39. drush_op('_drush_core_search_index');
  40. drush_log(dt('The search index has been built.'), 'ok');
  41. }
  42. function _drush_core_search_index() {
  43. list($remaining, ) = _drush_core_search_status();
  44. register_shutdown_function('search_update_totals');
  45. while ($remaining > 0) {
  46. drush_log(dt('Remaining items to be indexed: ' . $remaining), 'ok');
  47. // Use drush_backend_invoke() to start subshell. Avoids out of memory issue.
  48. $eval = "register_shutdown_function('search_update_totals');";
  49. if (drush_drupal_major_version() >= 7) {
  50. foreach (variable_get('search_active_modules', array('node', 'user')) as $module) {
  51. $eval .= " module_invoke($module, 'update_index');";
  52. }
  53. }
  54. else {
  55. $eval .= " module_invoke_all('update_index');";
  56. }
  57. drush_backend_invoke('php-eval', array($eval));
  58. list($remaining, ) = _drush_core_search_status();
  59. }
  60. }
  61. function drush_core_search_reindex() {
  62. drush_print(dt("The search index must be fully rebuilt before any new items can be indexed."));
  63. if (drush_get_option('immediate')) {
  64. drush_print(dt("Rebuilding the index may take a long time."));
  65. }
  66. if (!drush_confirm(dt('Do you really want to continue?'))) {
  67. return drush_set_error('CORE_SEARCH_REINDEX_ABORT', 'Aborting.');
  68. }
  69. if (drush_drupal_major_version() >= 7) {
  70. drush_op('search_reindex');
  71. }
  72. else {
  73. drush_op('search_wipe');
  74. }
  75. if (drush_get_option('immediate')) {
  76. drush_op('_drush_core_search_index');
  77. drush_log(dt('The search index has been rebuilt.'), 'ok');
  78. }
  79. else {
  80. drush_log(dt('The search index will be rebuilt.'), 'ok');
  81. }
  82. }