From e61c4a109886b7cf69f297e34d405f2a36f7310c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 4 Mar 2024 15:21:47 +0100 Subject: [PATCH] fix: remove use of depricated insertIfNotExist from UserMountCache Signed-off-by: Robin Appelman --- lib/private/Files/Config/UserMountCache.php | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 27d84e9383831..c3d0051345350 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -28,6 +28,7 @@ */ namespace OC\Files\Config; +use OC\DB\Exceptions\DbalException; use OCP\Cache\CappedMemoryCache; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Diagnostics\IEventLogger; @@ -172,14 +173,21 @@ private function findChangedMounts(array $newMounts, array $cachedMounts) { private function addToCache(ICachedMountInfo $mount) { if ($mount->getStorageId() !== -1) { - $this->connection->insertIfNotExist('*PREFIX*mounts', [ - 'storage_id' => $mount->getStorageId(), - 'root_id' => $mount->getRootId(), - 'user_id' => $mount->getUser()->getUID(), - 'mount_point' => $mount->getMountPoint(), - 'mount_id' => $mount->getMountId(), - 'mount_provider_class' => $mount->getMountProvider(), - ], ['root_id', 'user_id', 'mount_point']); + $query = $this->connection->getQueryBuilder(); + $query->insert('mounts') + ->values([ + 'storage_id' => $query->createNamedParameter($mount->getStorageId(), IQueryBuilder::PARAM_INT), + 'root_id' => $query->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT), + 'user_id' => $query->createNamedParameter($mount->getUser()->getUID()), + 'mount_point' => $query->createNamedParameter($mount->getMountPoint()), + 'mount_id' => $query->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT), + 'mount_provider_class' => $query->createNamedParameter($mount->getMountProvider()), + ]); + try { + $query->executeStatement(); + } catch (DbalException $e) { + // ignore duplicate + } } else { // in some cases this is legitimate, like orphaned shares $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());