Skip to content

Commit

Permalink
Merge pull request #59 from bigfork/versioned-without-stages
Browse files Browse the repository at this point in the history
FIX: Error when using AlgoliaObjectExtension on record without stages
  • Loading branch information
wilr authored Apr 20, 2023
2 parents f86daf5 + 5ccf65d commit 30811ec
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Extensions/AlgoliaObjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\ORM\DB;
use Ramsey\Uuid\Uuid;
use SilverStripe\Core\Convert;
use SilverStripe\Versioned\Versioned;
use Symbiote\QueuedJobs\Services\QueuedJobService;
use Throwable;
use Wilr\Silverstripe\Algolia\Jobs\AlgoliaDeleteItemJob;
Expand Down Expand Up @@ -78,9 +79,9 @@ public function updateSettingsFields(FieldList $fields)
$fields->addFieldsToTab(
'Root.Search',
[
ReadonlyField::create('AlgoliaIndexed', _t(__CLASS__.'.LastIndexed', 'Last indexed in Algolia'))
->setDescription($this->owner->AlgoliaError),
ReadonlyField::create('AlgoliaUUID', _t(__CLASS__.'.UUID', 'Algolia UUID'))
ReadonlyField::create('AlgoliaIndexed', _t(__CLASS__.'.LastIndexed', 'Last indexed in Algolia'))
->setDescription($this->owner->AlgoliaError),
ReadonlyField::create('AlgoliaUUID', _t(__CLASS__.'.UUID', 'Algolia UUID'))
]
);
}
Expand Down Expand Up @@ -174,7 +175,7 @@ private function updateAlgoliaFields($fields)
$set = implode(', ', $sets);
DB::query(sprintf('UPDATE %s SET %s WHERE ID = %s', $table, $set, $this->owner->ID));

if ($this->owner->hasExtension('SilverStripe\Versioned\Versioned')) {
if ($this->owner->hasExtension(Versioned::class) && $this->owner->hasStages()) {
DB::query(
sprintf(
'UPDATE %s_Live SET %s WHERE ID = %s',
Expand Down

0 comments on commit 30811ec

Please sign in to comment.