You are here

public function AdvancedHelpSearch::indexStatus in Advanced Help 8

Reports the status of indexing.

The core search module only invokes this method on active module plugins. Implementing modules do not need to check whether they are active when calculating their return values.

Return value

array An associative array with the key-value pairs:

  • remaining: The number of items left to index.
  • total: The total number of items to index.

Overrides SearchIndexingInterface::indexStatus

File

src/Plugin/Search/AdvancedHelpSearch.php, line 277

Class

AdvancedHelpSearch
Executes a keyword search for Advanced Help against the {advanced_help} topic pages.

Namespace

Drupal\advanced_help\Plugin\Search

Code

public function indexStatus() {
  $topics = $this->advancedHelp
    ->getTopics();
  $total = 0;
  foreach ($topics as $module => $module_topics) {
    foreach ($module_topics as $topic => $info) {
      $file = $this->advancedHelp
        ->getTopicFileName($module, $topic);
      if ($file) {
        $total++;
      }
    }
  }
  $last_cron = \Drupal::state()
    ->get($this
    ->getPluginId() . '.last_cron', [
    'time' => 0,
  ]);
  $indexed = 0;
  if ($last_cron['time'] != 0) {
    $indexed = $this->database
      ->select('search_dataset', 'sd')
      ->fields('sd', [
      'sid',
    ])
      ->condition('type', $this
      ->getPluginId())
      ->condition('reindex', 0)
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  return [
    'remaining' => $total - $indexed,
    'total' => $total,
  ];
}