summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-11-12 17:27:09 +0100
committerGitHub <noreply@github.com>2018-11-12 17:27:09 +0100
commit9e1ec0cf46055dbf08a139124d292eb38b8aebd2 (patch)
tree486e7b845e5355b90a5caa3ad2527ba5cb319367
parentdcf68617845c6098da8ea347f2dc23ffbf73e06e (diff)
parentf7e3cf20854402806f8d735ca498a2f240f2615c (diff)
downloadnextcloud-server-9e1ec0cf46055dbf08a139124d292eb38b8aebd2.tar.gz
nextcloud-server-9e1ec0cf46055dbf08a139124d292eb38b8aebd2.zip
Merge pull request #12413 from nextcloud/bugfix/9305/oc_file_locks-unique-constraint
Fix UniqueConstraintViolationException while insert into oc_file_locks
-rw-r--r--lib/private/Lock/DBLockingProvider.php13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/private/Lock/DBLockingProvider.php b/lib/private/Lock/DBLockingProvider.php
index 6adb7488217..79f2ff274cf 100644
--- a/lib/private/Lock/DBLockingProvider.php
+++ b/lib/private/Lock/DBLockingProvider.php
@@ -26,6 +26,7 @@
namespace OC\Lock;
+use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OC\DB\QueryBuilder\Literal;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -133,7 +134,17 @@ class DBLockingProvider extends AbstractLockingProvider {
protected function initLockField(string $path, int $lock = 0): int {
$expire = $this->getExpireTime();
- return $this->connection->insertIfNotExist('*PREFIX*file_locks', ['key' => $path, 'lock' => $lock, 'ttl' => $expire], ['key']);
+
+ try {
+ $builder = $this->connection->getQueryBuilder();
+ return $builder->insert('file_locks')
+ ->setValue('key', $builder->createNamedParameter($path))
+ ->setValue('lock', $builder->createNamedParameter($lock))
+ ->setValue('ttl', $builder->createNamedParameter($expire))
+ ->execute();
+ } catch(UniqueConstraintViolationException $e) {
+ return 0;
+ }
}
/**