Skip to content

Commit

Permalink
Merge branch 'release/3.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Nov 8, 2023
2 parents e93b4d8 + 2322ba4 commit dc66bd7
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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))

## 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)!)
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/Scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
);
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/events/AfterIndexImport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace rias\scout\events;

use craft\base\Element;
use rias\scout\ScoutIndex;
use yii\base\Event;

/**
* This event fires right at the end of je ImportIndexJob, after every element has been imported.
*/
class AfterIndexImport extends Event
{
/**
* The index that has been imported
*
* @var string
*/
public string $indexName;


}
5 changes: 4 additions & 1 deletion src/jobs/DeindexElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);

Expand Down
12 changes: 11 additions & 1 deletion src/jobs/ImportIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

namespace rias\scout\jobs;

use craft\base\Event;
use craft\queue\BaseJob;
use rias\scout\engines\Engine;
use rias\scout\events\AfterIndexImport;
use rias\scout\Scout;

class ImportIndex extends BaseJob
{
/** @var string */
public $indexName;

public const EVENT_AFTER_INDEX_IMPORT = "afterIndexImport";

public function execute($queue): void
{
/** @var Engine $engine */
$engine = Scout::$plugin->getSettings()->getEngines()->first(function(Engine $engine) {
$engine = Scout::$plugin->getSettings()->getEngines()->first(function (Engine $engine) {
return $engine->scoutIndex->indexName === $this->indexName;
});

Expand All @@ -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
Expand Down

0 comments on commit dc66bd7

Please sign in to comment.