From: Michael Date: Sun, 11 Feb 2018 16:18:39 +0000 (+0000) Subject: Some clean up for the worker, arrays are now supported as parameter X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2a762868e90cfd3d892de45b1ab540c4c47052eb;p=friendica.git Some clean up for the worker, arrays are now supported as parameter --- diff --git a/boot.php b/boot.php index 6816915417..27d8448531 100644 --- a/boot.php +++ b/boot.php @@ -39,7 +39,7 @@ define('FRIENDICA_PLATFORM', 'Friendica'); define('FRIENDICA_CODENAME', 'Asparagus'); define('FRIENDICA_VERSION', '3.6-dev'); define('DFRN_PROTOCOL_VERSION', '2.23'); -define('DB_UPDATE_VERSION', 1252); +define('DB_UPDATE_VERSION', 1253); define('NEW_UPDATE_ROUTINE_VERSION', 1170); /** diff --git a/database.sql b/database.sql index 3dadc23961..3f568a1dcf 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 3.6-dev (Asparagus) --- DB_UPDATE_VERSION 1250 +-- DB_UPDATE_VERSION 1253 -- ------------------------------------------ @@ -1003,6 +1003,7 @@ CREATE TABLE IF NOT EXISTS `tokens` ( -- CREATE TABLE IF NOT EXISTS `user` ( `uid` mediumint NOT NULL auto_increment COMMENT '', + `parent-uid` mediumint NOT NULL DEFAULT 0 COMMENT 'The parent user that has full control about this user', `guid` varchar(64) NOT NULL DEFAULT '' COMMENT '', `username` varchar(255) NOT NULL DEFAULT '' COMMENT '', `password` varchar(255) NOT NULL DEFAULT '' COMMENT '', @@ -1065,7 +1066,7 @@ CREATE TABLE IF NOT EXISTS `userd` ( -- CREATE TABLE IF NOT EXISTS `workerqueue` ( `id` int NOT NULL auto_increment COMMENT 'Auto incremented worker task id', - `parameter` mediumtext COMMENT 'Task command', + `parameter` mediumblob COMMENT 'Task command', `priority` tinyint NOT NULL DEFAULT 0 COMMENT 'Task priority', `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date', `pid` int NOT NULL DEFAULT 0 COMMENT 'Process id of the worker', diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 5a1392c093..a3bfeec32b 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -200,7 +200,7 @@ class Addon if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) { foreach ($a->hooks[$name] as $hook) { - Worker::add($priority, 'ForkHook', $name, json_encode($hook), json_encode($data)); + Worker::add($priority, 'ForkHook', $name, $hook, $data); } } } diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 57d2fa9711..e8a1f2e9f6 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -218,7 +218,7 @@ class Worker return false; } - $argv = json_decode($queue["parameter"]); + $argv = json_decode($queue["parameter"], true); // Check for existance and validity of the include file $include = $argv[0]; @@ -552,7 +552,7 @@ class Worker $max_duration_defaults = [PRIORITY_CRITICAL => 720, PRIORITY_HIGH => 10, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180, PRIORITY_NEGLIGIBLE => 720]; $max_duration = $max_duration_defaults[$entry["priority"]]; - $argv = json_decode($entry["parameter"]); + $argv = json_decode($entry["parameter"], true); $argv[0] = basename($argv[0]); // How long is the process already running? @@ -1001,32 +1001,12 @@ class Worker */ public static function add($cmd) { - $proc_args = func_get_args(); + $args = func_get_args(); - $args = []; - if (!count($proc_args)) { + if (!count($args)) { return false; } - // Preserve the first parameter - // It could contain a command, the priority or an parameter array - // If we use the parameter array we have to protect it from the following function - $run_parameter = array_shift($proc_args); - - // expand any arrays - foreach ($proc_args as $arg) { - if (is_array($arg)) { - foreach ($arg as $n) { - $args[] = $n; - } - } else { - $args[] = $arg; - } - } - - // Now we add the run parameters back to the array - array_unshift($args, $run_parameter); - $arr = ['args' => $args, 'run_cmd' => true]; Addon::callHooks("proc_run", $arr); @@ -1052,10 +1032,9 @@ class Worker } } - $argv = $args; - array_shift($argv); + array_shift($args); - $parameters = json_encode($argv); + $parameters = json_encode($args); $found = dba::exists('workerqueue', ['parameter' => $parameters, 'done' => false]); // Quit if there was a database error - a precaution for the update process to 3.5.3 diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 9c3c0d82a3..9a1c8a2d52 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -1772,7 +1772,7 @@ class DBStructure "comment" => "Background tasks queue entries", "fields" => [ "id" => ["type" => "int", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented worker task id"], - "parameter" => ["type" => "mediumtext", "comment" => "Task command"], + "parameter" => ["type" => "mediumblob", "comment" => "Task command"], "priority" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Task priority"], "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "Creation date"], "pid" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => "Process id of the worker"], diff --git a/src/Worker/ForkHook.php b/src/Worker/ForkHook.php index 1cd83bb3b3..6c138bace4 100644 --- a/src/Worker/ForkHook.php +++ b/src/Worker/ForkHook.php @@ -8,12 +8,9 @@ namespace Friendica\Worker; use Friendica\Core\Addon; Class ForkHook { - public static function execute($name, $hook_json, $data_json) { + public static function execute($name, $hook, $data) { global $a; - $hook = json_decode($hook_json, true); - $data = json_decode($data_json, true); - Addon::callSingleHook($a, $name, $hook, $data); } }