From 69738ee2293d742162936622a7a7b78ff618b2d7 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Wed, 8 Nov 2023 13:42:51 +0100 Subject: [PATCH 1/4] Use siteId in de-indexing as well #281 --- src/Scout.php | 5 ++++- src/jobs/DeindexElement.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Scout.php b/src/Scout.php index ce17635..e6efe18 100644 --- a/src/Scout.php +++ b/src/Scout.php @@ -201,7 +201,10 @@ function (ElementEvent $event) { ->ttr(Scout::$plugin->getSettings()->ttr) ->priority(Scout::$plugin->getSettings()->priority) ->push( - new DeindexElement(['id' => $element->id]) + new DeindexElement([ + 'id' => $element->id, + 'siteId' => $element->site->id + ]) ); } } diff --git a/src/jobs/DeindexElement.php b/src/jobs/DeindexElement.php index e93cac9..cff5e6b 100644 --- a/src/jobs/DeindexElement.php +++ b/src/jobs/DeindexElement.php @@ -11,9 +11,12 @@ class DeindexElement extends BaseJob /** @var int */ public $id; + /** @var int */ + public int $siteId; + public function execute($queue): void { - $element = Craft::$app->getElements()->getElementById($this->id, null, null, [ + $element = Craft::$app->getElements()->getElementById($this->id, null, $this->siteId, [ 'trashed' => null, ]); From c53d55a4be82d77f1010e5a14b60948b4d8288b4 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Wed, 8 Nov 2023 16:48:02 +0100 Subject: [PATCH 2/4] Changelog for #281 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24c8e70..99ea4b1 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.1 - 2023-11-08 +### Fixed +- Deindexing now also takes the correct siteId into account ([#281](https://github.com/studioespresso/craft-scout/issues/281)) + ## 3.3.0 - 2023-10-23 ### Added - Added support for creating and configuring replica indexes ([#275](https://github.com/studioespresso/craft-scout/pull/275), thanks [@johnnynotsolucky](https://github.com/johnnynotsolucky)!) From 3795cc8f04561899d280a80270e8093ced466ed4 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Wed, 8 Nov 2023 16:54:05 +0100 Subject: [PATCH 3/4] Added AfterIndexImport event #283 --- CHANGELOG.md | 3 +++ README.md | 23 +++++++++++++++++++++++ src/events/AfterIndexImport.php | 22 ++++++++++++++++++++++ src/jobs/ImportIndex.php | 12 +++++++++++- 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/events/AfterIndexImport.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 99ea4b1..1f07b44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. ## 3.3.1 - 2023-11-08 + +### Added +- Added `AfterIndexImport` event, which fires after the ImportIndex job has finished. ([#283](https://github.com/studioespresso/craft-scout/issues/283)) ### Fixed - Deindexing now also takes the correct siteId into account ([#281](https://github.com/studioespresso/craft-scout/issues/281)) diff --git a/README.md b/README.md index 757e44c..a14e562 100644 --- a/README.md +++ b/README.md @@ -332,6 +332,29 @@ The event has a properties: An example use-case for this would be to check the type of the element that's beind saved and settings `shouldBeSearchable` to `false` when it's a Matrix block. +### AfterIndexImport + +This event runs at the end of the `ImportIndex` job, when every item has been processed. + +```php + +use rias\scout\events\AfterIndexImport; +use rias\scout\jobs\ImportIndex; + +Event::on( + ImportIndex::class, + ImportIndex::EVENT_AFTER_INDEX_IMPORT, + function (AfterIndexImport $event) { + // Your code here + }); +``` + +The event has one property: +- $indexName (the name of the index that just finished importing + +An example use-case for this would be to keep a log or dateLastImported if you're running imports on a schedule. + + --- ## Upgrading from 1.x diff --git a/src/events/AfterIndexImport.php b/src/events/AfterIndexImport.php new file mode 100644 index 0000000..438fb75 --- /dev/null +++ b/src/events/AfterIndexImport.php @@ -0,0 +1,22 @@ +getSettings()->getEngines()->first(function(Engine $engine) { + $engine = Scout::$plugin->getSettings()->getEngines()->first(function (Engine $engine) { return $engine->scoutIndex->indexName === $this->indexName; }); @@ -33,6 +37,12 @@ public function execute($queue): void $elementsUpdated += count($elements); $this->setProgress($queue, $elementsUpdated / $elementsCount); } + + $event = new AfterIndexImport([ + 'indexName' => $this->indexName + ]); + + Event::trigger(self::class, self::EVENT_AFTER_INDEX_IMPORT, $event); } protected function defaultDescription(): string From 2322ba4e59de7291d2cbd3ee22d9e0c0a647e717 Mon Sep 17 00:00:00 2001 From: Jan Henckens Date: Wed, 8 Nov 2023 16:54:17 +0100 Subject: [PATCH 4/4] Version bump --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6151f03..5aeb77a 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.0", + "version": "3.3.1", "keywords": [ "craft", "cms",