diff options
author | Robin Appelman <robin@icewind.nl> | 2021-05-10 17:34:10 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-05-19 17:08:20 +0200 |
commit | ed2396b045c7b10555d7f05df5f81d2d17a00caf (patch) | |
tree | a467de2d39cb89fb76b061246b92c7cf56940a82 /lib/private | |
parent | fd284f428dc15c0ebd4054fa5e4e9431d518bcb1 (diff) | |
download | nextcloud-server-ed2396b045c7b10555d7f05df5f81d2d17a00caf.tar.gz nextcloud-server-ed2396b045c7b10555d7f05df5f81d2d17a00caf.zip |
better cleanup of filecache when deleting an external storage
this way it can delete the cache entries even with per-user credentials
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/Cache/Storage.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/private/Files/Cache/Storage.php b/lib/private/Files/Cache/Storage.php index 173091f53b0..48313c96560 100644 --- a/lib/private/Files/Cache/Storage.php +++ b/lib/private/Files/Cache/Storage.php @@ -29,6 +29,7 @@ namespace OC\Files\Cache; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Storage\IStorage; use Psr\Log\LoggerInterface; @@ -219,4 +220,43 @@ class Storage { $query->execute(); } } + + /** + * remove the entry for the storage by the mount id + * + * @param int $mountId + */ + public static function cleanByMountId(int $mountId) { + $db = \OC::$server->getDatabaseConnection(); + + try { + $db->beginTransaction(); + + $query = $db->getQueryBuilder(); + $query->select('storage_id') + ->from('mounts') + ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); + $storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); + + $query = $db->getQueryBuilder(); + $query->delete('filecache') + ->where($query->expr()->in('storage', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); + $query->executeStatement(); + + $query = $db->getQueryBuilder(); + $query->delete('storages') + ->where($query->expr()->eq('numeric_id', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); + $query->executeStatement(); + + $query = $db->getQueryBuilder(); + $query->delete('mounts') + ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); + $query->executeStatement(); + + $db->commit(); + } catch (\Exception $e) { + $db->rollBack(); + throw $e; + } + } } |