/** * Displays information about a search index. * * @param \Drupal\search_api\IndexInterface $search_api_index * The index to display. * * @return array * An array suitable for drupal_render(). */ public function page(IndexInterface $search_api_index) { // Build the search index information. $render = array('view' => array('#theme' => 'search_api_index', '#index' => $search_api_index)); // Check if the index is enabled and can be written to. if ($search_api_index->status() && !$search_api_index->isReadOnly()) { // Attach the index status form. $render['form'] = $this->formBuilder()->getForm('Drupal\\search_api\\Form\\IndexStatusForm', $search_api_index); } return $render; }
/** * Creates an indexing batch for a given search index. * * @param \Drupal\search_api\IndexInterface $index * The search index for which items should be indexed. * @param int|null $batch_size * (optional) Number of items to index per batch. Defaults to the cron limit * set for the index. * @param int $limit * (optional) Maximum number of items to index. Defaults to indexing all * remaining items. * * @throws \Drupal\search_api\SearchApiException * Thrown if the batch could not be created. */ public static function create(IndexInterface $index, $batch_size = NULL, $limit = -1) { // Check if the size should be determined by the index cron limit option. if ($batch_size === NULL) { // Use the size set by the index. $batch_size = $index->getOption('cron_limit', \Drupal::config('search_api.settings')->get('default_cron_limit')); } // Check if indexing items is allowed. if ($index->status() && !$index->isReadOnly() && $batch_size !== 0 && $limit !== 0) { // Define the search index batch definition. $batch_definition = array('operations' => array(array(array(__CLASS__, 'process'), array($index, $batch_size, $limit))), 'finished' => array(__CLASS__, 'finish'), 'progress_message' => static::t('Completed about @percentage% of the indexing operation (@current of @total).')); // Schedule the batch. batch_set($batch_definition); } else { $args = array('%size' => $batch_size, '%limit' => $limit, '%name' => $index->label()); throw new SearchApiException(new FormattableMarkup('Failed to create a batch with batch size %size and limit %limit for index %name', $args)); } }
/** * {@inheritdoc} */ public function deleteAllIndexItems(IndexInterface $index) { if ($index->isReadOnly()) { $vars = array('%index' => $index->label()); \Drupal::logger('search_api')->warning('Trying to delete items from index %index which is marked as read-only.', $vars); return; } $server_task_manager = \Drupal::getContainer()->get('search_api.server_task_manager'); try { if ($server_task_manager->execute($this)) { $this->getBackend()->deleteAllIndexItems($index); return; } } catch (SearchApiException $e) { $vars = array('%server' => $this->label(), '%index' => $index->label()); watchdog_exception('search_api', $e, '%type while deleting items of index %index from server %server: @message in %function (line %line of %file).', $vars); } $server_task_manager->add($this, __FUNCTION__, $index); }
/** * {@inheritdoc} */ public function isReadOnly() { return $this->entity->isReadOnly(); }