From 9c732a4870a5166831add8bf2e9de9294acc6971 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 22 Jul 2020 13:34:37 +0200 Subject: [PATCH] Added utility methods updateJobs and generateJobs to controller core/JQW_Controller --- application/config/jqm.php | 2 +- application/core/JQW_Controller.php | 38 ++++++++++++++++++++++++++ application/libraries/JobsQueueLib.php | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/application/config/jqm.php b/application/config/jqm.php index d7e0a3525..541183deb 100644 --- a/application/config/jqm.php +++ b/application/config/jqm.php @@ -14,7 +14,7 @@ $config['job_type_permissions_white_list'] = array( // List of schedulers that can be run by the scheduler $config['job_schedulers_list'] = array( // Controllers - 'extensions/FHC-Core-SAP/JBMScheduler' => array( // Methods + 'extensions/FHC-Core-SAP/JQMScheduler' => array( // Methods 'newUsers', 'updateUsers' ) diff --git a/application/core/JQW_Controller.php b/application/core/JQW_Controller.php index 01ae99805..1105ad037 100644 --- a/application/core/JQW_Controller.php +++ b/application/core/JQW_Controller.php @@ -74,5 +74,43 @@ abstract class JQW_Controller extends JOB_Controller return $result; } + + /** + * Utility method to update the specified properties of the given jobs with the given values + */ + protected function updateJobs($jobs, $properties, $values) + { + // If not valid arrays of properties and values arrays are not of the same size then exit + if (isEmptyArray($jobs) || isEmptyArray($properties) || isEmptyArray($values)) return; + if (count($properties) != count($values)) return; + + // For each job + foreach ($jobs as $job) + { + // For each propery of the job + for ($pI = 0; $pI < count($properties); $pI++) + { + // If this property is present in the job object + if (property_exists($job, $properties[$pI])) + { + $job->{$properties[$pI]} = $values[$pI]; // set a new value + } + } + } + } + + /** + * Utility method to generate a job with the given parameters and return it inside an array + * ready to be used by addNewJobsToQueue and updateJobsQueue + */ + protected function generateJobs($status, $input) + { + $job = stdClass(); + + $job->{self::PROPERTY_STATUS} = $status; + $job->{self::PROPERTY_INPUT} = $input; + + return array($job); + } } diff --git a/application/libraries/JobsQueueLib.php b/application/libraries/JobsQueueLib.php index 0e74f6605..fa9f3890b 100644 --- a/application/libraries/JobsQueueLib.php +++ b/application/libraries/JobsQueueLib.php @@ -335,7 +335,7 @@ class JobsQueueLib $found = $this->_inArray($job->{self::PROPERTY_STATUS}, $statuses, self::PROPERTY_STATUS); } - // No status was not found and does NOT already contain the property error + // No status was found and does NOT already contain the property error if (!$found && !property_exists($job, self::PROPERTY_ERROR)) { $job->{self::PROPERTY_ERROR} = 'The provided status of this job is not valid'; // store the error message in the object