Skip to content

Commit

Permalink
Merge pull request #12413 from nextcloud/bugfix/9305/oc_file_locks-un…
Browse files Browse the repository at this point in the history
…ique-constraint

Fix UniqueConstraintViolationException while insert into oc_file_locks
  • Loading branch information
MorrisJobke authored Nov 12, 2018
2 parents dcf6861 + f7e3cf2 commit 9e1ec0c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/private/Lock/DBLockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,7 +134,17 @@ public function __construct(

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;
}
}

/**
Expand Down

0 comments on commit 9e1ec0c

Please sign in to comment.