From 66011b149758aef0ef61a84921707f30298c8fc0 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 2 Dec 2024 16:20:12 +0900 Subject: [PATCH] Move all events into individual ones --- src/Database/Database.php | 19 ++++++++++++++----- tests/e2e/Adapter/Base.php | 10 +++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 7764554b4..925555553 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -3432,9 +3432,13 @@ public function createDocuments(string $collection, array $documents, int $batch } $documents[$key] = $this->decode($collection, $document); - $this->trigger(self::EVENT_DOCUMENT_CREATE, $documents[$key]); } + $this->trigger(self::EVENT_DOCUMENTS_CREATE, new Document([ + '$collection' => $collection->getId(), + 'modified' => array_map(fn ($document) => $document->getId(), $documents) + ])); + return $documents; } @@ -4102,9 +4106,13 @@ public function updateDocuments(string $collection, Document $updates, array $qu foreach ($documents as $document) { $this->purgeRelatedDocuments($collection, $document->getId()); $this->purgeCachedDocument($collection->getId(), $document->getId()); - $this->trigger(self::EVENT_DOCUMENT_UPDATE, $document); } + $this->trigger(self::EVENT_DOCUMENTS_UPDATE, new Document([ + '$collection' => $collection->getId(), + 'modified' => array_map(fn ($document) => $document->getId(), $documents) + ])); + return $documents; }); @@ -5245,9 +5253,10 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba return []; } - foreach ($documents as $document) { - $this->trigger(self::EVENT_DOCUMENT_DELETE, $document); - } + $this->trigger(self::EVENT_DOCUMENTS_DELETE, new Document([ + '$collection' => $collection->getId(), + 'modified' => array_map(fn ($document) => $document->getId(), $documents) + ])); $this->adapter->deleteDocuments($collection->getId(), array_map(fn ($document) => $document->getId(), $documents)); diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index 5a141718e..943eb458e 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -17036,15 +17036,11 @@ public function testEvents(): void Database::EVENT_DOCUMENT_SUM, Database::EVENT_DOCUMENT_INCREASE, Database::EVENT_DOCUMENT_DECREASE, - Database::EVENT_DOCUMENT_CREATE, - Database::EVENT_DOCUMENT_CREATE, - Database::EVENT_DOCUMENT_UPDATE, - Database::EVENT_DOCUMENT_UPDATE, - Database::EVENT_DOCUMENT_UPDATE, + Database::EVENT_DOCUMENTS_CREATE, + Database::EVENT_DOCUMENTS_UPDATE, Database::EVENT_INDEX_DELETE, Database::EVENT_DOCUMENT_DELETE, - Database::EVENT_DOCUMENT_DELETE, - Database::EVENT_DOCUMENT_DELETE, + Database::EVENT_DOCUMENTS_DELETE, Database::EVENT_ATTRIBUTE_DELETE, Database::EVENT_COLLECTION_DELETE, Database::EVENT_DATABASE_DELETE