Skip to content

Commit 039b7e2

Browse files
committed
fix: remove use of depricated insertIfNotExist from Files\Cache\Storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 54afea4 commit 039b7e2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/private/Files/Cache/Storage.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
namespace OC\Files\Cache;
3131

32+
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
3233
use OCP\DB\QueryBuilder\IQueryBuilder;
3334
use OCP\Files\Storage\IStorage;
3435
use OCP\IDBConnection;
@@ -78,9 +79,16 @@ public function __construct($storage, $isAvailable, IDBConnection $connection) {
7879
$this->numericId = (int)$row['numeric_id'];
7980
} else {
8081
$available = $isAvailable ? 1 : 0;
81-
if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) {
82-
$this->numericId = $connection->lastInsertId('*PREFIX*storages');
83-
} else {
82+
$query = $connection->getQueryBuilder();
83+
$query->insert('storages')
84+
->values([
85+
'id' => $query->createNamedParameter($this->storageId),
86+
'available' => $query->createNamedParameter($available, IQueryBuilder::PARAM_INT),
87+
]);
88+
try {
89+
$query->executeStatement();
90+
$this->numericId = $query->getLastInsertId();
91+
} catch (UniqueConstraintViolationException $e) {
8492
if ($row = self::getStorageById($this->storageId)) {
8593
$this->numericId = (int)$row['numeric_id'];
8694
} else {

0 commit comments

Comments
 (0)