Add insertIgnoreConflict to Adapter and use it for for executing the file locking.

Signed-off-by: Ole Ostergaard <ole.c.ostergaard@gmail.com>
pull/13721/head
Ole Ostergaard 6 years ago committed by Ole Ostergaard
parent 0155edc195
commit a48ea8cffa
  1. 13
      lib/private/DB/Adapter.php
  2. 4
      lib/private/DB/Connection.php
  3. 12
      lib/private/Lock/DBLockingProvider.php

@ -126,4 +126,17 @@ class Adapter {
return 0;
}
}
public function insertIgnoreConflict($table, $input) : int {
try {
$builder = $this->conn->getQueryBuilder();
$builder->insert($table);
foreach($input as $key => $value) {
$builder->setValue($key, $builder->createNamedParameter($value));
}
return $builder->execute();
} catch(UniqueConstraintViolationException $e) {
return 0;
}
}
}

@ -257,6 +257,10 @@ class Connection extends ReconnectWrapper implements IDBConnection {
return $this->adapter->insertIfNotExist($table, $input, $compare);
}
public function insertIgnoreConflict($table, $input) : int {
return $this->adapter->insertIgnoreConflict($table, $input);
}
private function getType($value) {
if (is_bool($value)) {
return IQueryBuilder::PARAM_BOOL;

@ -134,17 +134,7 @@ class DBLockingProvider extends AbstractLockingProvider {
protected function initLockField(string $path, int $lock = 0): int {
$expire = $this->getExpireTime();
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;
}
return $this->connection->insertIgnoreConflict('file_locks', ['key' => $path, 'lock' => $lock, 'ttl' => $expire]);
}
/**

Loading…
Cancel
Save