feat: listen to user life cycle events

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-08 21:47:07 -04:00
parent 6c4b42b32b
commit 18822a4d88
5 changed files with 214 additions and 3 deletions
+24 -2
View File
@@ -308,7 +308,12 @@ class Store {
if ($identifier === null) {
return $entity;
}
return $this->collectionDestroyById($tenantId, $userId, (string) $identifier) ? $entity : $entity;
$this->entityDestroyByCollectionId($tenantId, $userId, [(string) $identifier]);
$this->chronicleExpungeByCollectionId($tenantId, [(string) $identifier]);
$this->collectionDestroyById($tenantId, $userId, (string) $identifier);
return $entity;
}
/**
@@ -592,6 +597,21 @@ class Store {
return false;
}
/**
* Delete entities belonging to specific collections from the data store.
*
* @param string $tenantId tenant identifier
* @param string $userId user identifier
* @param array $identifiers collection identifiers
*/
private function entityDestroyByCollectionId(string $tenantId, string $userId, array $identifiers): void {
$this->_store->selectCollection($this->_EntityTable)->deleteMany([
'tid' => $tenantId,
'uid' => $userId,
'cid' => ['$in' => $identifiers],
]);
}
/**
* chronicle a operation to an entity to the data store
*
@@ -758,11 +778,13 @@ class Store {
*
* @since Release 1.0.0
*
* @param string $tenantId tenant identifier
* @param array $identifiers collection of identifiers
*/
private function chronicleExpungeByCollectionId(array $identifiers): void {
private function chronicleExpungeByCollectionId(string $tenantId, array $identifiers): void {
// Delete chronicle entries for the specified collection identifiers
$this->_store->selectCollection($this->_ChronicleTable)->deleteMany([
'tid' => $tenantId,
'cid' => ['$in' => $identifiers]
]);
}