From 039b7e2c57ba90e57b4a7d8e808f00d6326f9d92 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 26 Feb 2024 18:01:59 +0100 Subject: [PATCH] fix: remove use of depricated insertIfNotExist from Files\Cache\Storage Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Storage.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/Cache/Storage.php b/lib/private/Files/Cache/Storage.php index ba0f98f42f492..7be96f2322a80 100644 --- a/lib/private/Files/Cache/Storage.php +++ b/lib/private/Files/Cache/Storage.php @@ -29,6 +29,7 @@ */ namespace OC\Files\Cache; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Storage\IStorage; use OCP\IDBConnection; @@ -78,9 +79,16 @@ public function __construct($storage, $isAvailable, IDBConnection $connection) { $this->numericId = (int)$row['numeric_id']; } else { $available = $isAvailable ? 1 : 0; - if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) { - $this->numericId = $connection->lastInsertId('*PREFIX*storages'); - } else { + $query = $connection->getQueryBuilder(); + $query->insert('storages') + ->values([ + 'id' => $query->createNamedParameter($this->storageId), + 'available' => $query->createNamedParameter($available, IQueryBuilder::PARAM_INT), + ]); + try { + $query->executeStatement(); + $this->numericId = $query->getLastInsertId(); + } catch (UniqueConstraintViolationException $e) { if ($row = self::getStorageById($this->storageId)) { $this->numericId = (int)$row['numeric_id']; } else {