]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Worker.php
Fix addons problem more elegant
[friendica.git] / src / Core / Worker.php
index 57895ab1734d9b9ccea2b51e8c76c506f9abeda7..90bce0a88e5807df6fa0f9eed52829c6f4440fef 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -331,7 +331,7 @@ class Worker
                $mypid = getmypid();
 
                // Quit when in maintenance
-               if (DI::config()->get('system', 'maintenance', false, true)) {
+               if (DI::config()->get('system', 'maintenance', false)) {
                        Logger::notice('Maintenance mode - quit process', ['pid' => $mypid]);
                        return false;
                }
@@ -1264,7 +1264,7 @@ class Worker
 
                $command = array_shift($args);
                $parameters = json_encode($args);
-               $found = DBA::exists('workerqueue', ['command' => $command, 'parameter' => $parameters, 'done' => false]);
+               $queue = DBA::selectFirst('workerqueue', ['id', 'priority'], ['command' => $command, 'parameter' => $parameters, 'done' => false]);
                $added = 0;
 
                if (!is_int($priority) || !in_array($priority, self::PRIORITIES)) {
@@ -1277,14 +1277,17 @@ class Worker
                        return 0;
                }
 
-               if (!$found) {
+               if (empty($queue)) {
                        if (!DBA::insert('workerqueue', ['command' => $command, 'parameter' => $parameters, 'created' => $created,
                                'priority' => $priority, 'next_try' => $delayed])) {
                                return 0;
                        }
                        $added = DBA::lastInsertId();
                } elseif ($force_priority) {
-                       DBA::update('workerqueue', ['priority' => $priority], ['command' => $command, 'parameter' => $parameters, 'done' => false, 'pid' => 0]);
+                       $ret = DBA::update('workerqueue', ['priority' => $priority], ['command' => $command, 'parameter' => $parameters, 'done' => false, 'pid' => 0]);
+                       if ($ret && ($priority != $queue['priority'])) {
+                               $added = $queue['id'];
+                       }
                }
 
                // Set the IPC flag to ensure an immediate process execution via daemon
@@ -1312,8 +1315,8 @@ class Worker
                        return $added;
                }
 
-               // Quit on daemon mode
-               if (Worker\Daemon::isMode()) {
+               // Quit on daemon mode, except the priority is critical (like for db updates)
+               if (Worker\Daemon::isMode() && $priority !== self::PRIORITY_CRITICAL) {
                        return $added;
                }