X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FProcess.php;h=94699d6acc9d21ce59e5eb8288157ffcaf64dccb;hb=f1d3f60499a325557be866fedd31b46093d477ae;hp=8b7ce8d34ae80ee3b9536494a9e9e25502594e14;hpb=000e6457b4c460aa5a1850b812dc5e622a237685;p=friendica.git diff --git a/src/Model/Process.php b/src/Model/Process.php index 8b7ce8d34a..94699d6acc 100644 --- a/src/Model/Process.php +++ b/src/Model/Process.php @@ -1,42 +1,61 @@ . + * */ -namespace Friendica\Model; -use Friendica\BaseObject; -use dba; +namespace Friendica\Model; -require_once 'include/dba.php'; -require_once 'include/datetime.php'; +use Friendica\Database\Database; +use Friendica\Util\DateTimeFormat; /** - * @brief functions for interacting with a process + * functions for interacting with a process */ -class Process extends BaseObject +class Process { + /** @var Database */ + private $dba; + + public function __construct(Database $dba) + { + $this->dba = $dba; + } + /** * Insert a new process row. If the pid parameter is omitted, we use the current pid * * @param string $command - * @param string $pid + * @param int $pid The process id to insert * @return bool + * @throws \Exception */ - public static function insert($command, $pid = null) + public function insert(string $command, int $pid) { $return = true; - if (is_null($pid)) { - $pid = getmypid(); - } - - dba::transaction(); + $this->dba->transaction(); - if (!dba::exists('process', ['pid' => $pid])) { - $return = dba::insert('process', ['pid' => $pid, 'command' => $command, 'created' => datetime_convert()]); + if (!$this->dba->exists('process', ['pid' => $pid])) { + $return = $this->dba->insert('process', ['pid' => $pid, 'command' => $command, 'created' => DateTimeFormat::utcNow()]); } - dba::commit(); + $this->dba->commit(); return $return; } @@ -44,32 +63,29 @@ class Process extends BaseObject /** * Remove a process row by pid. If the pid parameter is omitted, we use the current pid * - * @param string $pid + * @param int $pid The pid to delete * @return bool + * @throws \Exception */ - public static function deleteByPid($pid = null) + public function deleteByPid(int $pid) { - if ($pid === null) { - $pid = getmypid(); - } - - return dba::delete('process', ['pid' => $pid]); + return $this->dba->delete('process', ['pid' => $pid]); } /** * Clean the process table of inactive physical processes */ - public static function deleteInactive() + public function deleteInactive() { - dba::transaction(); + $this->dba->transaction(); - $processes = dba::select('process', ['pid']); - while($process = dba::fetch($processes)) { + $processes = $this->dba->select('process', ['pid']); + while($process = $this->dba->fetch($processes)) { if (!posix_kill($process['pid'], 0)) { - self::deleteByPid($process['pid']); + $this->deleteByPid($process['pid']); } } - - dba::commit(); + $this->dba->close($processes); + $this->dba->commit(); } }