Console Lock

WIP
This commit is contained in:
Philipp Holzer 2019-08-13 21:20:41 +02:00
parent 425876316f
commit 41e2031e6b
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
9 changed files with 420 additions and 25 deletions

View file

@ -92,9 +92,16 @@ class DatabaseLock extends Lock
/**
* (@inheritdoc)
*/
public function releaseAll()
public function releaseAll($override = false)
{
$return = $this->dba->delete('locks', ['pid' => $this->pid]);
$success = parent::releaseAll($override);
if ($override) {
$where = ['1 = 1'];
} else {
$where = ['pid' => $this->pid];
}
$return = $this->dba->delete('locks', $where);
$this->acquiredLocks = [];
@ -114,4 +121,34 @@ class DatabaseLock extends Lock
return false;
}
}
/**
* {@inheritDoc}
*/
public function getName()
{
return self::TYPE_DATABASE;
}
/**
* {@inheritDoc}
*/
public function getLocks(string $prefix = '')
{
if (empty($prefix)) {
$where = ['`expires` >= ?', DateTimeFormat::utcNow()];
} else {
$where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', DateTimeFormat::utcNow(), $prefix];
}
$stmt = $this->dba->select('locks', ['name'], $where);
$keys = [];
while ($key = $this->dba->fetch($stmt)) {
array_push($keys, $key['name']);
}
$this->dba->close($stmt);
return $keys;
}
}