Skip to content

Commit

Permalink
fix: remove use of depricated insertIfNotExist from Files\Cache\Storage
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Mar 5, 2024
1 parent 799c6de commit f11a83b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/private/Files/Cache/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f11a83b

Please sign in to comment.