Skip to content

Commit

Permalink
fix: don't sync settings on dev/build
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Sep 2, 2024
1 parent a3c286a commit ec0590c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
24 changes: 1 addition & 23 deletions src/Extensions/AlgoliaObjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/AlgoliaConfigure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ec0590c

Please sign in to comment.