Add insertIgnoreConflict to Adapter and use it for for executing the file locking.
Signed-off-by: Ole Ostergaard <ole.c.ostergaard@gmail.com>
This commit is contained in:
parent
0155edc195
commit
a48ea8cffa
3 changed files with 18 additions and 11 deletions
|
@ -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…
Reference in a new issue