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 (variable_get('search_active_modules', array('node', 'user')) 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. if (isset($status['remaining']) && isset($status['total'])) {
  29. $remaining += $status['remaining'];
  30. $total += $status['total'];
  31. }
  32. }
  33. }
  34. return array($remaining, $total);
  35. }
  36. function drush_core_search_index() {
  37. drush_print(dt("Building the index may take a long time."));
  38. if (!drush_confirm(dt('Do you really want to continue?'))) {
  39. return drush_user_abort();
  40. }
  41. drush_op('_drush_core_search_index');
  42. drush_log(dt('The search index has been built.'), 'ok');
  43. }
  44. function _drush_core_search_index() {
  45. list($remaining, ) = _drush_core_search_status();
  46. register_shutdown_function('search_update_totals');
  47. while ($remaining > 0) {
  48. drush_log(dt('Remaining items to be indexed: ' . $remaining), 'ok');
  49. // Use drush_backend_invoke() to start subshell. Avoids out of memory issue.
  50. $eval = "register_shutdown_function('search_update_totals');";
  51. if (drush_drupal_major_version() >= 7) {
  52. foreach (variable_get('search_active_modules', array('node', 'user')) as $module) {
  53. $eval .= " module_invoke($module, 'update_index');";
  54. }
  55. }
  56. else {
  57. $eval .= " module_invoke_all('update_index');";
  58. }
  59. drush_backend_invoke('php-eval', array($eval));
  60. list($remaining, ) = _drush_core_search_status();
  61. }
  62. }
  63. function drush_core_search_reindex() {
  64. drush_print(dt("The search index must be fully rebuilt before any new items can be indexed."));
  65. if (drush_get_option('immediate')) {
  66. drush_print(dt("Rebuilding the index may take a long time."));
  67. }
  68. if (!drush_confirm(dt('Do you really want to continue?'))) {
  69. return drush_user_abort();
  70. }
  71. if (drush_drupal_major_version() >= 7) {
  72. drush_op('search_reindex');
  73. }
  74. else {
  75. drush_op('search_wipe');
  76. }
  77. if (drush_get_option('immediate')) {
  78. drush_op('_drush_core_search_index');
  79. drush_log(dt('The search index has been rebuilt.'), 'ok');
  80. }
  81. else {
  82. drush_log(dt('The search index will be rebuilt.'), 'ok');
  83. }
  84. }