From ec0590cd91d6ae663f1e06e6a2934d07e9de9e6f Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 3 Sep 2024 11:20:36 +1200 Subject: [PATCH] fix: don't sync settings on dev/build --- src/Extensions/AlgoliaObjectExtension.php | 24 +---------------------- src/Tasks/AlgoliaConfigure.php | 5 +++++ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/Extensions/AlgoliaObjectExtension.php b/src/Extensions/AlgoliaObjectExtension.php index 0339d71..8eaebfe 100644 --- a/src/Extensions/AlgoliaObjectExtension.php +++ b/src/Extensions/AlgoliaObjectExtension.php @@ -19,6 +19,7 @@ use Wilr\Silverstripe\Algolia\Jobs\AlgoliaIndexItemJob; use Wilr\SilverStripe\Algolia\Service\AlgoliaIndexer; use Wilr\SilverStripe\Algolia\Service\AlgoliaService; +use Wilr\SilverStripe\Algolia\Tasks\AlgoliaConfigure; class AlgoliaObjectExtension extends DataExtension { @@ -87,29 +88,6 @@ public function updateSettingsFields(FieldList $fields) } } - /** - * On dev/build ensure that the indexer settings are up to date. - */ - public function requireDefaultRecords() - { - if ($this->ranSync) { - return false; - } - - $this->ranSync = true; - $algolia = Injector::inst()->create(AlgoliaService::class); - - if (!$this->indexEnabled()) { - return; - } - - try { - $algolia->syncSettings(); - } catch (Throwable $e) { - DB::alteration_message($e->getMessage(), 'error'); - } - } - /** * Returns whether this object should be indexed into Algolia. */ diff --git a/src/Tasks/AlgoliaConfigure.php b/src/Tasks/AlgoliaConfigure.php index e301284..ab03208 100644 --- a/src/Tasks/AlgoliaConfigure.php +++ b/src/Tasks/AlgoliaConfigure.php @@ -24,6 +24,11 @@ public function run($request) { $service = Injector::inst()->get(AlgoliaService::class); + if (!$this->isEnabled()) { + echo 'This task is disabled.' . PHP_EOL; + return; + } + try { if ($service->syncSettings()) { echo 'Success.' . PHP_EOL;