diff --git a/src/Task/IndexTaskManager.php b/src/Task/IndexTaskManager.php index 806dc0c..89f5b8a 100644 --- a/src/Task/IndexTaskManager.php +++ b/src/Task/IndexTaskManager.php @@ -65,7 +65,7 @@ class IndexTaskManager implements IndexTaskManagerInterface { 'status' => 1, 'pages' => array_fill_keys($datasource_ids, 0), ); - $this->state->set($this->getIndexState($index), $index_state); + $this->state->set($this->getIndexStateKey($index), $index_state); } } @@ -109,7 +109,7 @@ class IndexTaskManager implements IndexTaskManagerInterface { return NULL; } - $this->state->set($this->getIndexState($index), $index_state); + $this->state->set($this->getIndexStateKey($index), $index_state); return $added; } @@ -219,7 +219,7 @@ class IndexTaskManager implements IndexTaskManagerInterface { $this->state->delete($this->getIndexStateKey($index)); } else { - $this->state->set($this->getIndexState($index), $index_state); + $this->state->set($this->getIndexStateKey($index), $index_state); } } } @@ -229,7 +229,7 @@ class IndexTaskManager implements IndexTaskManagerInterface { */ public function isTrackingComplete(IndexInterface $index) { $index_state = $this->getIndexState($index); - return (bool) $index_state['status']; + return !$index_state['status']; } /** diff --git a/src/Task/IndexTaskManagerInterface.php b/src/Task/IndexTaskManagerInterface.php index e9c1df6..5754bd8 100644 --- a/src/Task/IndexTaskManagerInterface.php +++ b/src/Task/IndexTaskManagerInterface.php @@ -14,16 +14,74 @@ use Drupal\search_api\IndexInterface; */ interface IndexTaskManagerInterface { + /** + * Creates a task to start tracking for the given index, or some datasources. + * + * @param \Drupal\search_api\IndexInterface $index + * The search index. + * @param string[]|null $datasource_ids + * (optional) The IDs of specific datasources for which tracking should + * start. Or NULL to start tracking for all datasources. + */ public function startTracking(IndexInterface $index, array $datasource_ids = NULL); + /** + * Adds a single page of items to the tracker. + * + * @param \Drupal\search_api\IndexInterface $index + * The search index. + * + * @return int|null + * The number of items tracked. Or NULL if no items were added and tracking + * for this index has been completed. (Note that 0 can also be returned, + * which does not mean that tracking has been completed for the index.) + */ public function addItemsOnce(IndexInterface $index); + /** + * Sets a batch to track all remaining items for the given index. + * + * @param \Drupal\search_api\IndexInterface $index + * The search index. + */ public function addItemsBatch(IndexInterface $index); + /** + * Tracks all remaining items for the given index. + * + * Since no kind of batch processing is used, this might run out of memory or + * execution time on larger sites. + * + * @param \Drupal\search_api\IndexInterface $index + * The search index. + * + * @return mixed + */ public function addItemsAll(IndexInterface $index); + /** + * Stops tracking for the given index. + * + * Will delete any remaining tracking tasks and also remove all items from + * tracking for this index. + * + * @param \Drupal\search_api\IndexInterface $index + * The search index. + * @param string[]|null $datasource_ids + * (optional) The IDs of the datasources for which to stop tracking. Or NULL + * to stop tracking for all datasources. + */ public function stopTracking(IndexInterface $index, array $datasource_ids = NULL); + /** + * Checks whether tracking has already been completed for the given index. + * + * @param \Drupal\search_api\IndexInterface $index + * The search index. + * + * @return bool + * TRUE if tracking has been completed for the given index, FALSE otherwise. + */ public function isTrackingComplete(IndexInterface $index); }