]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Process.php
Remove "fcontact" from suggestions
[friendica.git] / src / Model / Process.php
index 2652929681d6e6209280a74098c9954f9f6f892d..94699d6acc9d21ce59e5eb8288157ffcaf64dccb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -21,7 +21,7 @@
 
 namespace Friendica\Model;
 
-use Friendica\Database\DBA;
+use Friendica\Database\Database;
 use Friendica\Util\DateTimeFormat;
 
 /**
@@ -29,29 +29,33 @@ use Friendica\Util\DateTimeFormat;
  */
 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();
-               }
+               $this->dba->transaction();
 
-               DBA::transaction();
-
-               if (!DBA::exists('process', ['pid' => $pid])) {
-                       $return = DBA::insert('process', ['pid' => $pid, 'command' => $command, 'created' => DateTimeFormat::utcNow()]);
+               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;
        }
@@ -59,33 +63,29 @@ class Process
        /**
         * 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();
        }
 }