From 5375c8b8bc852150e2791125181141e7ac26719f Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 24 Mar 2021 12:26:12 +1300 Subject: [PATCH] Display syncSetting error without stopping the build Only track syncSettings once per dev/build --- src/Extensions/AlgoliaObjectExtension.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Extensions/AlgoliaObjectExtension.php b/src/Extensions/AlgoliaObjectExtension.php index 52dc8b0..e13ce90 100644 --- a/src/Extensions/AlgoliaObjectExtension.php +++ b/src/Extensions/AlgoliaObjectExtension.php @@ -23,6 +23,11 @@ class AlgoliaObjectExtension extends DataExtension { use Configurable; + /** + * @var boolean + */ + private $ranSync = false; + /** * @config * @@ -73,8 +78,18 @@ public function updateSettingsFields(FieldList $fields) */ public function requireDefaultRecords() { + if ($this->ranSync) { + return false; + } + + $this->ranSync = true; $algolia = Injector::inst()->create(AlgoliaService::class); - $algolia->syncSettings(); + + try { + $algolia->syncSettings(); + } catch (Exception $e) { + DB::alteration_message($e->getMessage(), 'error'); + } } /**