Skip to content

Commit

Permalink
FIX reindexing with onlyClass (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Jun 30, 2021
1 parent 0c264b2 commit cb71d4c
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/Tasks/AlgoliaReindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ public function run($request)
}

if ($targetClass) {
$this->indexClass($targetClass, $filter);
$items = $this->getItems($targetClass, $filter);

if ($items->exists()) {
$this->indexItems($targetClass, $filter, $items);
} else {
echo sprintf(
'Found 0 %s remaining to index which match filter (%s)%s',
$targetClass,
$filter,
PHP_EOL
);
}
} else {
$algoliaService = Injector::inst()->create(AlgoliaService::class);

Expand All @@ -63,6 +74,13 @@ public function run($request)

if ($items->exists()) {
$this->indexItems($candidate, $filter, $items);
} else {
echo sprintf(
'Found 0 %s remaining to index which match filter (%s)%s',
$targetClass,
$filter,
PHP_EOL
);
}
}
}
Expand All @@ -73,6 +91,9 @@ public function run($request)
}

/**
* @param string $targetClass
* @param string $filter
*
* @return \SilverStripe\ORM\DataList
*/
public function getItems($targetClass, $filter = '')
Expand All @@ -92,6 +113,11 @@ public function getItems($targetClass, $filter = '')
return $items;
}

/**
* @param string $targetClass
* @param string $filter
* @param DataList? $items
*/
public function indexItems($targetClass, $filter = '', $items = null)
{
$algoliaService = Injector::inst()->create(AlgoliaService::class);
Expand All @@ -104,9 +130,10 @@ public function indexItems($targetClass, $filter = '', $items = null)
$indexer = Injector::inst()->create(AlgoliaIndexer::class);

echo sprintf(
'Found %s %s remaining to index, will export in batches of %s, %s batches total %s',
'Found %s %s remaining to index which match filter (%s), will export in batches of %s, %s batches total %s',
$total,
$targetClass,
$filter,
$batchSize,
$batchesTotal,
PHP_EOL
Expand Down

0 comments on commit cb71d4c

Please sign in to comment.