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

Namesort descending Description
drush_search_index
drush_search_reindex
drush_search_status
search_drush_command
system_nodeapi Fake an implementation of hook_nodeapi() for Drupal 6.
system_node_update_index Fake an implementation of hook_node_update_index() for Drupal 7.
_drush_search_index
_drush_search_status

File

commands/core/search.drush.inc
View source
  1. <?php
  2. function search_drush_command() {
  3. $items['search-status'] = array(
  4. 'description' => 'Show how many items remain to be indexed out of the total.',
  5. 'drupal dependencies' => array('search'),
  6. 'options' => array(
  7. 'pipe' => 'Display in the format remaining/total for processing by scripts.',
  8. ),
  9. );
  10. $items['search-index'] = array(
  11. 'description' => 'Index the remaining search items without wiping the index.',
  12. 'drupal dependencies' => array('search'),
  13. );
  14. $items['search-reindex'] = array(
  15. 'description' => 'Force the search index to be rebuilt.',
  16. 'drupal dependencies' => array('search'),
  17. 'options' => array(
  18. 'immediate' => 'Rebuild the index immediately, instead of waiting for cron.',
  19. ),
  20. );
  21. return $items;
  22. }
  23. function drush_search_status() {
  24. list($remaining, $total) = _drush_search_status();
  25. drush_print(dt('There are @remaining items out of @total still to be indexed.', array(
  26. '@remaining' => $remaining,
  27. '@total' => $total,
  28. )));
  29. drush_print_pipe("$remaining/$total\n");
  30. }
  31. function _drush_search_status() {
  32. $remaining = 0;
  33. $total = 0;
  34. if (drush_drupal_major_version() >= 7) {
  35. foreach (variable_get('search_active_modules', array('node', 'user')) as $module) {
  36. $status = module_invoke($module, 'search_status');
  37. $remaining += $status['remaining'];
  38. $total += $status['total'];
  39. }
  40. }
  41. else {
  42. foreach (module_implements('search') as $module) {
  43. // Special case. Apachesolr recommends disabling core indexing with
  44. // search_cron_limit = 0. Need to avoid infinite status loop.
  45. if ($module == 'node' && variable_get('search_cron_limit', 10) == 0) {
  46. continue;
  47. }
  48. $status = module_invoke($module, 'search', 'status');
  49. if (isset($status['remaining']) && isset($status['total'])) {
  50. $remaining += $status['remaining'];
  51. $total += $status['total'];
  52. }
  53. }
  54. }
  55. return array($remaining, $total);
  56. }
  57. function drush_search_index() {
  58. drush_op('_drush_search_index');
  59. drush_log(dt('The search index has been built.'), 'ok');
  60. }
  61. function _drush_search_index() {
  62. list($remaining, ) = _drush_search_status();
  63. register_shutdown_function('search_update_totals');
  64. $failures = 0;
  65. while ($remaining > 0) {
  66. drush_log(dt('Remaining items to be indexed: ' . $remaining), 'ok');
  67. // Use drush_invoke_process() to start subshell. Avoids out of memory issue.
  68. $eval = "register_shutdown_function('search_update_totals');";
  69. if (drush_drupal_major_version() >= 7) {
  70. // If needed, prod module_implements() to recognize our
  71. // hook_node_update_index() implementations.
  72. $implementations = module_implements('node_update_index');
  73. if (!in_array('system', $implementations)) {
  74. // Note that this resets module_implements cache.
  75. module_implements('node_update_index', FALSE, TRUE);
  76. }
  77. foreach (variable_get('search_active_modules', array('node', 'user')) as $module) {
  78. $eval .= " module_invoke('$module', 'update_index');";
  79. }
  80. }
  81. else {
  82. // If needed, prod module_implements() to recognize our hook_nodeapi()
  83. // implementations.
  84. $implementations = module_implements('nodeapi');
  85. if (!in_array('system', $implementations)) {
  86. // Note that this resets module_implements cache.
  87. module_implements('nodeapi', FALSE, TRUE);
  88. }
  89. $eval .= " module_invoke_all('update_index');";
  90. }
  91. drush_invoke_process('@self', 'php-eval', array($eval));
  92. $previous_remaining = $remaining;
  93. list($remaining, ) = _drush_search_status();
  94. // Make sure we're actually making progress.
  95. if ($remaining == $previous_remaining) {
  96. $failures++;
  97. if ($failures == 3) {
  98. drush_log(dt('Indexing stalled with @number items remaining.', array(
  99. '@number' => $remaining,
  100. )), 'error');
  101. return;
  102. }
  103. }
  104. // Only count consecutive failures.
  105. else {
  106. $failures = 0;
  107. }
  108. }
  109. }
  110. function drush_search_reindex() {
  111. drush_print(dt("The search index must be fully rebuilt before any new items can be indexed."));
  112. if (drush_get_option('immediate')) {
  113. drush_print(dt("Rebuilding the index may take a long time."));
  114. }
  115. if (!drush_confirm(dt('Do you really want to continue?'))) {
  116. return drush_user_abort();
  117. }
  118. if (drush_drupal_major_version() >= 7) {
  119. drush_op('search_reindex');
  120. }
  121. else {
  122. drush_op('search_wipe');
  123. }
  124. if (drush_get_option('immediate')) {
  125. drush_op('_drush_search_index');
  126. drush_log(dt('The search index has been rebuilt.'), 'ok');
  127. }
  128. else {
  129. drush_log(dt('The search index will be rebuilt.'), 'ok');
  130. }
  131. }
  132. /**
  133. * Fake an implementation of hook_node_update_index() for Drupal 7.
  134. */
  135. function system_node_update_index($node) {
  136. // Verbose output.
  137. if (drush_get_context('DRUSH_VERBOSE')) {
  138. drush_log(dt('Indexing node !nid.', array('!nid' => $node->nid)), 'ok');
  139. }
  140. }
  141. /**
  142. * Fake an implementation of hook_nodeapi() for Drupal 6.
  143. */
  144. function system_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  145. if ($op == 'update index') {
  146. // Verbose output.
  147. if (drush_get_context('DRUSH_VERBOSE')) {
  148. drush_log(dt('Indexing node !nid.', array('!nid' => $node->nid)), 'ok');
  149. }
  150. }
  151. }