|
7 | 7 | use craft\base\Model;
|
8 | 8 | use craft\base\Plugin as BasePlugin;
|
9 | 9 | use craft\elements\db\ElementQuery;
|
10 |
| -use craft\elements\Entry; |
11 | 10 | use craft\events\ModelEvent;
|
12 | 11 | use craft\helpers\ElementHelper;
|
13 | 12 | use craft\helpers\Queue;
|
@@ -80,40 +79,24 @@ static function (ModelEvent $event) use ($autoSyncIndices): void {
|
80 | 79 | return;
|
81 | 80 | }
|
82 | 81 |
|
83 |
| - $status = $sender->getStatus(); |
84 |
| - |
85 |
| - // Determine which status to use to check if the element is active. |
86 |
| - if ($sender instanceof Entry) { |
87 |
| - $activeStatus = Entry::STATUS_LIVE; |
88 |
| - } else { |
89 |
| - $activeStatus = Element::STATUS_ENABLED; |
90 |
| - } |
91 |
| - |
92 |
| - if ($status === $activeStatus) { |
93 |
| - // If an element is active, then we should update it in the index |
94 |
| - $autoSyncIndices->each(static function (Index $index) use ($sender): void { |
95 |
| - /** @var ElementQuery<array-key, Element> $query */ |
96 |
| - $query = $index->query; |
| 82 | + $autoSyncIndices->each(static function (Index $index) use ($sender): void { |
| 83 | + /** @var ElementQuery<array-key, Element> $query */ |
| 84 | + $query = $index->query; |
| 85 | + if (in_array($sender->getStatus(), $index->activeStatuses, true)) { |
| 86 | + // If an element is active, then we should update it in the index |
97 | 87 | if ($query->id($sender->id)->exists()) {
|
98 | 88 | Queue::push(new SyncJob([
|
99 | 89 | 'indexName' => $index->handle,
|
100 | 90 | 'identifier' => $sender->id,
|
101 | 91 | ]));
|
102 | 92 | }
|
103 |
| - }); |
104 |
| - } else { |
105 |
| - // Otherwise, we should make sure that it is not in the index |
106 |
| - $autoSyncIndices->each(static function (Index $index) use ($sender): void { |
107 |
| - /** @var ElementQuery<array-key, Element> $query */ |
108 |
| - $query = $index->query; |
109 |
| - if ($query->status(null)->id($sender->id)->exists()) { |
110 |
| - Queue::push(new DeleteJob([ |
111 |
| - 'indexName' => $index->handle, |
112 |
| - 'identifier' => $sender->id, |
113 |
| - ])); |
114 |
| - } |
115 |
| - }); |
116 |
| - } |
| 93 | + } elseif ($query->status(null)->id($sender->id)->exists()) { |
| 94 | + Queue::push(new DeleteJob([ |
| 95 | + 'indexName' => $index->handle, |
| 96 | + 'identifier' => $sender->id, |
| 97 | + ])); |
| 98 | + } |
| 99 | + }); |
117 | 100 | }
|
118 | 101 | );
|
119 | 102 |
|
|
0 commit comments