Skip to content

Commit

Permalink
Move all events into individual ones
Browse files Browse the repository at this point in the history
  • Loading branch information
PineappleIOnic committed Dec 2, 2024
1 parent d95bbbd commit 66011b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
19 changes: 14 additions & 5 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
});

Expand Down Expand Up @@ -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));

Expand Down
10 changes: 3 additions & 7 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 66011b1

Please sign in to comment.