diff --git a/CHANGELOG.md b/CHANGELOG.md index 62bfe99..32bedb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## 3.3.3-beta.1 - 2023-12-06 +### Fixed +- This beta release is a first try at resolving an issue with deindexing of element not working properly. ([#281](https://github.com/studioespresso/craft-scout/issues/281)) + ## 3.3.2 - 2023-11-15 ### Fixed - Fixed an error on the Control Panel Utility page ([#284](https://github.com/studioespresso/craft-scout/issues/284)) diff --git a/composer.json b/composer.json index 1b82bbb..ef4c235 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "studioespresso/craft-scout", "description": "Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.", "type": "craft-plugin", - "version": "3.3.2", + "version": "3.3.3-beta.1", "keywords": [ "craft", "cms", diff --git a/src/jobs/MakeSearchable.php b/src/jobs/MakeSearchable.php index 7486bda..5332157 100644 --- a/src/jobs/MakeSearchable.php +++ b/src/jobs/MakeSearchable.php @@ -23,20 +23,31 @@ class MakeSearchable extends BaseJob public function execute($queue): void { - if (!$element = $this->getElement()) { - return; - } - $this->getEngine()->update($element); + $element = $this->getElement(); + if ($element) { + // Enabled element found + $this->getEngine()->update($element); - if ($this->propagate) { - $element->searchableRelations(); + if ($this->propagate) { + $element->searchableRelations(); + } + } else { + // Element not found, checking if it was disabled and needs to be de-indexed. + $element = $this->getAnyElement(); + if($element){ + if(!$element->shouldBeSearchable()) { + $element->unsearchable(); + } + } } + + } protected function defaultDescription(): string { - if (!$element = $this->getElement()) { + if (!$element = $this->getAnyElement()) { return ''; } @@ -63,6 +74,16 @@ private function getElement() ->one(); } + private function getAnyElement() + { + return $this->getIndex() + ->criteria + ->id($this->id) + ->status(null) + ->siteId($this->siteId) + ->one(); + } + protected function getEngine() { return Scout::$plugin->getSettings()->getEngine($this->getIndex()); @@ -70,7 +91,7 @@ protected function getEngine() protected function getIndex() { - return Scout::$plugin->getSettings()->getIndices()->first(function(ScoutIndex $scoutindex) { + return Scout::$plugin->getSettings()->getIndices()->first(function (ScoutIndex $scoutindex) { return $scoutindex->indexName === $this->indexName; }); }