Skip to content

Commit

Permalink
Dispatch event for all remove entry
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Jan 31, 2023
1 parent 3ff5683 commit 2830eea
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,16 @@ private function getSubFolders(ICacheEntry $entry) {
}

/**
* Recursively remove all children of a folder
* Remove all children of a folder
*
* @param ICacheEntry $entry the cache entry of the folder to remove the children of
* @throws \OC\DatabaseException
*/
private function removeChildren(ICacheEntry $entry) {
$parentIds = [$entry->getId()];
$queue = [$entry->getId()];
$deletedIds = [];
$deletedPaths = [];

// we walk depth first through the file tree, removing all filecache_extended attributes while we walk
// and collecting all folder ids to later use to delete the filecache entries
Expand All @@ -589,6 +591,12 @@ private function removeChildren(ICacheEntry $entry) {
$childIds = array_map(function (ICacheEntry $cacheEntry) {
return $cacheEntry->getId();
}, $children);
$childPaths = array_map(function (ICacheEntry $cacheEntry) {
return $cacheEntry->getPath();
}, $children);

$deletedIds = array_merge($deletedIds, $childIds);
$deletedPaths = array_merge($deletedPaths, $childPaths);

$query = $this->getQueryBuilder();
$query->delete('filecache_extended')
Expand Down Expand Up @@ -617,6 +625,16 @@ private function removeChildren(ICacheEntry $entry) {
$query->setParameter('parentIds', $parentIdChunk, IQueryBuilder::PARAM_INT_ARRAY);
$query->execute();
}

foreach (array_combine($deletedIds, $deletedPaths) as $fileId => $filePath) {
$cacheEntryRemovedEvent = new CacheEntryRemovedEvent(
$this->storage,
$filePath,
$fileId,
$this->getNumericStorageId()
);
$this->eventDispatcher->dispatchTyped($cacheEntryRemovedEvent);
}
}

/**
Expand Down

0 comments on commit 2830eea

Please sign in to comment.