diff --git a/src/Extensions/AlgoliaObjectExtension.php b/src/Extensions/AlgoliaObjectExtension.php index f91b359..0339d71 100644 --- a/src/Extensions/AlgoliaObjectExtension.php +++ b/src/Extensions/AlgoliaObjectExtension.php @@ -231,12 +231,23 @@ public function doImmediateIndexInAlgolia(): bool return false; } + + $schema = DataObject::getSchema(); + $table = $schema->tableForField($this->owner->ClassName, 'AlgoliaError'); $indexer = Injector::inst()->get(AlgoliaIndexer::class); try { if ($indexer->indexItem($this->owner)) { $this->touchAlgoliaIndexedDate(); + DB::query( + sprintf( + 'UPDATE %s SET AlgoliaError = \'\' WHERE ID = %s', + $table, + $this->owner->ID + ) + ); + return true; } else { return false; @@ -244,9 +255,6 @@ public function doImmediateIndexInAlgolia(): bool } catch (Throwable $e) { Injector::inst()->get(LoggerInterface::class)->error($e); - $schema = DataObject::getSchema(); - $table = $schema->tableForField($this->owner->ClassName, 'AlgoliaError'); - DB::query( sprintf( 'UPDATE %s SET AlgoliaError = \'%s\' WHERE ID = %s', diff --git a/src/Extensions/SubsitesVirtualPageExtension.php b/src/Extensions/SubsitesVirtualPageExtension.php index 464bba6..df8ac96 100644 --- a/src/Extensions/SubsitesVirtualPageExtension.php +++ b/src/Extensions/SubsitesVirtualPageExtension.php @@ -44,6 +44,8 @@ public function exportObjectToAlgolia($toIndex) return $attributes; }); + $attributes->push('SubsiteID', $this->owner->SubsiteID); + return $result; } } diff --git a/src/Tasks/AlgoliaReindexItem.php b/src/Tasks/AlgoliaReindexItem.php index 9c2e8d0..a5c5c08 100644 --- a/src/Tasks/AlgoliaReindexItem.php +++ b/src/Tasks/AlgoliaReindexItem.php @@ -4,8 +4,10 @@ use SilverStripe\CMS\Model\VirtualPage; use SilverStripe\Core\Environment; +use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\BuildTask; use SilverStripe\ORM\DataObject; +use Wilr\SilverStripe\Algolia\Service\AlgoliaIndexer; class AlgoliaReindexItem extends BuildTask { @@ -49,12 +51,19 @@ public function run($request) $obj->assignAlgoliaUUID(true); } + $indexer = Injector::inst()->get(AlgoliaIndexer::class); + $service = $indexer->getService(); + + echo 'Indexing to Algolia indexes ('; + echo implode(', ', array_map(function ($indexName) use ($service) { + return $service->environmentizeIndex($indexName); + }, array_keys($service->initIndexes($obj)))) . ')' . PHP_EOL; $result = $obj->doImmediateIndexInAlgolia(); echo sprintf( 'Indexed: %s%sUUID: %s%s%s', - $result ? 'true' : 'false', + $result ? 'true ' . '(timestamp ' . $obj->AlgoliaIndexed . ')' : 'false', PHP_EOL, $obj->AlgoliaUUID ? $obj->AlgoliaUUID : 'No ID set', PHP_EOL,