I'm trying to set up a custom scheduled task and I want to utilise the Rules parameters as part of my logic to get other records from the database.
So my question is how do I get the json rules? I've tried the following in my mytaskTask.
private function mytaskTask(ExecuteTaskEvent $event) : int
{
// Your task goes here
$taskType = $event->getArgument('routineId');
// get the rules
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select(' execution_rules ' );
$query->from($db->quoteName('#__scheduler_tasks'));
$query->where($db->quoteName('type').' = '.$db->quote($taskType) );
$db->setQuery($query);
try {
$rules = $db->loadResult();
$this->logTask('Retrieved task rules', 'notice');
} catch (RuntimeException $e) {
$this->logTask($e->getMessage());
return Status::KNOCKOUT;
}
$rulesObj = json_decode($rules);
$ruleType = $rulesObj->rule-type;
UPDATED: So now I'm able to get the rules as a JSON string in $rulesObj however when I try to get the rule type I get the terminated dialogue box with the message:
JSON.parse: unexpected character at line 1 column 1 of the JSON data
When I display the variable $rulesObj I see the result as:
stdClass Object
(
[rule-type] => interval-days
[interval-days] => 1
[exec-day] => 21
[exec-time] => 05:19
)
As usual, all guidance appreciated.