Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all events into individual ones #490

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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