Skip to content

Commit

Permalink
ECS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Feb 15, 2024
1 parent e1bec3b commit 03869eb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
22 changes: 11 additions & 11 deletions src/Scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public static function editions(): array

public function init()
{
Craft::$app->onInit(function () {
Craft::$app->onInit(function() {
parent::init();

self::$plugin = $this;

Craft::$container->setSingleton(SearchClient::class, function () {
Craft::$container->setSingleton(SearchClient::class, function() {
$config = SearchConfig::create(
self::$plugin->getSettings()->getApplicationId(),
self::$plugin->getSettings()->getAdminApiKey()
Expand Down Expand Up @@ -101,7 +101,7 @@ private function registerUtility(): void
Event::on(
Utilities::class,
Utilities::EVENT_REGISTER_UTILITIES,
function (RegisterComponentTypesEvent $event) {
function(RegisterComponentTypesEvent $event) {
$event->types[] = ScoutUtility::class;
}
);
Expand All @@ -113,7 +113,7 @@ private function registerBehaviors(): void
Event::on(
Element::class,
Element::EVENT_DEFINE_BEHAVIORS,
function (DefineBehaviorsEvent $event) {
function(DefineBehaviorsEvent $event) {
$event->behaviors['searchable'] = SearchableBehavior::class;
}
);
Expand All @@ -125,7 +125,7 @@ private function registerVariables(): void
Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function (Event $event) {
function(Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('scout', ScoutVariable::class);
Expand Down Expand Up @@ -154,7 +154,7 @@ private function registerEventHandlers(): void
Event::on(
$event[0],
$event[1],
function (ElementEvent $event) {
function(ElementEvent $event) {
/** @var SearchableBehavior $element */
$element = $event->element;
if (!$element->hasMethod('searchable') || !$element->shouldBeSearchable()) {
Expand All @@ -168,7 +168,7 @@ function (ElementEvent $event) {
->push(
new IndexElement([
'id' => $element->id,
'siteId' => $element->site ? $element->site->id : null
'siteId' => $element->site ? $element->site->id : null,
])
);
} else {
Expand All @@ -181,7 +181,7 @@ function (ElementEvent $event) {
Event::on(
Elements::class,
Elements::EVENT_BEFORE_DELETE_ELEMENT,
function (ElementEvent $event) {
function(ElementEvent $event) {
if (!Scout::$plugin->getSettings()->indexRelations) {
$this->beforeDeleteRelated = new Collection();

Expand All @@ -203,7 +203,7 @@ function (ElementEvent $event) {
->push(
new DeindexElement([
'id' => $element->id,
'siteId' => $element->site ? $element->site->id : null
'siteId' => $element->site ? $element->site->id : null,
])
);
}
Expand All @@ -213,7 +213,7 @@ function (ElementEvent $event) {
Event::on(
Elements::class,
Elements::EVENT_AFTER_DELETE_ELEMENT,
function (ElementEvent $event) {
function(ElementEvent $event) {
// Skip this step if we already ran the DeIndex function earlier
if (Scout::$plugin->getSettings()->queue) {
return;
Expand All @@ -226,7 +226,7 @@ function (ElementEvent $event) {
}

if ($this->beforeDeleteRelated) {
$this->beforeDeleteRelated->each(function (Element $relatedElement) {
$this->beforeDeleteRelated->each(function(Element $relatedElement) {
/* @var SearchableBehavior $relatedElement */
if ($relatedElement->hasMethod('searchable')) {
$relatedElement->searchable(false);
Expand Down
10 changes: 5 additions & 5 deletions src/console/controllers/scout/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function actionFlush($index = '')
}

$engines = Scout::$plugin->getSettings()->getEngines();
$engines->filter(function (Engine $engine) use ($index) {
$engines->filter(function(Engine $engine) use ($index) {
return !$engine->scoutIndex->replicaIndex && ($index === '' || $engine->scoutIndex->indexName === $index);
})->each(function (Engine $engine) {
})->each(function(Engine $engine) {
$engine->flush();
$this->stdout("Flushed index {$engine->scoutIndex->indexName}\n", Console::FG_GREEN);
});
Expand All @@ -49,17 +49,17 @@ public function actionImport($index = '')
{
$engines = Scout::$plugin->getSettings()->getEngines();

$engines->filter(function (Engine $engine) use ($index) {
$engines->filter(function(Engine $engine) use ($index) {
return !$engine->scoutIndex->replicaIndex && ($index === '' || $engine->scoutIndex->indexName === $index);
})->each(function (Engine $engine) {
})->each(function(Engine $engine) {
if ($this->queue) {
Craft::$app->getQueue()
->ttr(Scout::$plugin->getSettings()->ttr)
->priority(Scout::$plugin->getSettings()->priority)
->push(new ImportIndex([
'indexName' => $engine->scoutIndex->indexName,
]));
$this->stdout("Added ImportIndex job for '{$engine->scoutIndex->indexName}' to the queue".PHP_EOL, Console::FG_GREEN);
$this->stdout("Added ImportIndex job for '{$engine->scoutIndex->indexName}' to the queue" . PHP_EOL, Console::FG_GREEN);
} else {
$totalElements = $engine->scoutIndex->criteria->count();
$elementsUpdated = 0;
Expand Down
3 changes: 0 additions & 3 deletions src/events/AfterIndexImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace rias\scout\events;

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

/**
Expand All @@ -17,6 +16,4 @@ class AfterIndexImport extends Event
* @var string
*/
public string $indexName;


}
4 changes: 2 additions & 2 deletions src/jobs/ImportIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ImportIndex extends BaseJob
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 @@ -39,7 +39,7 @@ public function execute($queue): void
}

$event = new AfterIndexImport([
'indexName' => $this->indexName
'indexName' => $this->indexName,
]);

Event::trigger(self::class, self::EVENT_AFTER_INDEX_IMPORT, $event);
Expand Down
9 changes: 3 additions & 6 deletions src/jobs/MakeSearchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class MakeSearchable extends BaseJob

public function execute($queue): void
{

$element = $this->getElement();
if ($element) {
// Enabled element found
Expand All @@ -35,14 +34,12 @@ public function execute($queue): void
} else {
// Element not found, checking if it was disabled and needs to be de-indexed.
$element = $this->getAnyElement();
if($element){
if(!$element->shouldBeSearchable()) {
if ($element) {
if (!$element->shouldBeSearchable()) {
$element->unsearchable();
}
}
}


}

protected function defaultDescription(): string
Expand Down Expand Up @@ -91,7 +88,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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/ScoutUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function contentHtml(): string

$engines = Scout::$plugin->getSettings()->getEngines();

$stats = $engines->map(function (Engine $engine) {
$stats = $engines->map(function(Engine $engine) {
$stats = [
'name' => $engine->scoutIndex->indexName,
'replicaIndex' => $engine->scoutIndex->replicaIndex,
Expand Down

0 comments on commit 03869eb

Please sign in to comment.