Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-05-10 18:34:10 +0300
committerRobin Appelman <robin@icewind.nl>2021-05-19 18:08:20 +0300
commited2396b045c7b10555d7f05df5f81d2d17a00caf (patch)
treea467de2d39cb89fb76b061246b92c7cf56940a82 /lib/private/Files/Cache
parentfd284f428dc15c0ebd4054fa5e4e9431d518bcb1 (diff)
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/Files/Cache')
-rw-r--r--lib/private/Files/Cache/Storage.php40
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;
+ }
+ }
}