function _drush_search_index

8.0.x search.drush.inc _drush_search_index()
6.x search.drush.inc _drush_search_index()
7.x search.drush.inc _drush_search_index()
5.x search.drush.inc _drush_search_index()
master search.drush.inc _drush_search_index()
2 string references to '_drush_search_index'

File

commands/core/search.drush.inc, line 96

Code

function _drush_search_index() {
  list($remaining, $total) = _drush_search_status();
  register_shutdown_function('search_update_totals');
  $failures = 0;
  while ($remaining > 0) {
    $done = $total - $remaining;
    $percent = $done / $total * 100;
    drush_log(dt('!percent complete. Remaining items to be indexed: !count', array('!percent' => number_format($percent, 2), '!count' => $remaining)), LogLevel::OK);
    $eval = "register_shutdown_function('search_update_totals');";

    // Use drush_invoke_process() to start subshell. Avoids out of memory issue.
    if (drush_drupal_major_version() >= 8) {
      $eval = "drush_module_invoke('search', 'cron');";
    }
    elseif (drush_drupal_major_version() == 7) {
      // If needed, prod drush_module_implements() to recognize our
      // hook_node_update_index() implementations.
      drush_include_engine('drupal', 'environment');
      $implementations = drush_module_implements('node_update_index');
      if (!in_array('system', $implementations)) {
        // Note that this resets module_implements cache.
        drush_module_implements('node_update_index', FALSE, TRUE);
      }

      foreach (variable_get('search_active_modules', array('node', 'user')) as $module) {
        // TODO: Make sure that drush_module_invoke is really available when doing this eval().
        $eval .= " drush_module_invoke('$module', 'update_index');";
      }
    }
    else {
      // If needed, prod module_implements() to recognize our hook_nodeapi()
      // implementations.
      $implementations = module_implements('nodeapi');
      if (!in_array('system', $implementations)) {
        // Note that this resets module_implements cache.
        module_implements('nodeapi', FALSE, TRUE);
      }

      $eval .= " module_invoke_all('update_index');";
    }
    drush_invoke_process('@self', 'php-eval', array($eval));
    $previous_remaining = $remaining;
    list($remaining, ) = _drush_search_status();
    // Make sure we're actually making progress.
    if ($remaining == $previous_remaining) {
      $failures++;
      if ($failures == 3) {
        drush_log(dt('Indexing stalled with @number items remaining.', array(
          '@number' => $remaining,
        )), LogLevel::ERROR);
        return;
      }
    }
    // Only count consecutive failures.
    else {
      $failures = 0;
    }
  }
}