Skip to content

Commit f32abc6

Browse files
authored
Merge pull request #245 from catalyst/ci-fx-MOODLE_404_STABLE
Fix CI issues
2 parents 2a03757 + d089351 commit f32abc6

File tree

80 files changed

+1222
-1069
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1222
-1069
lines changed

classes/edit_form.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public function definition() {
5858
$mform->addHelpButton('workflowname', 'workflowname', 'tool_trigger');
5959

6060
// Workflow description.
61-
$editoroptions = array(
61+
$editoroptions = [
6262
'subdirs' => 0,
6363
'maxbytes' => 0,
6464
'maxfiles' => 0,
6565
'changeformat' => 0,
6666
'context' => \context_system::instance(),
6767
'noclean' => 0,
68-
'trusttext' => 0
69-
);
68+
'trusttext' => 0,
69+
];
7070
$mform->addElement('editor', 'workflowdescription', get_string ('workflowdescription', 'tool_trigger'), $editoroptions);
7171
$mform->setType('workflowdescription', PARAM_RAW_TRIMMED);
7272
$mform->addHelpButton('workflowdescription', 'workflowdescription', 'tool_trigger');
@@ -95,7 +95,7 @@ public function definition() {
9595
$mform->addElement('advcheckbox',
9696
'workflowactive',
9797
get_string ('workflowactive', 'tool_trigger'),
98-
'Enable', array(), array(0, 1));
98+
'Enable', [], [0, 1]);
9999
$mform->setType('workflowactive', PARAM_INT);
100100
$mform->addHelpButton('workflowactive', 'workflowactive', 'tool_trigger');
101101
$mform->setDefault('workflowactive', 1);
@@ -104,7 +104,7 @@ public function definition() {
104104
$mform->addElement('advcheckbox',
105105
'workflowrealtime',
106106
get_string ('workflowrealtime', 'tool_trigger'),
107-
'Enable', array(), array(0, 1));
107+
'Enable', [], [0, 1]);
108108
$mform->setType('workflowrealtime', PARAM_INT);
109109
$mform->addHelpButton('workflowrealtime', 'workflowrealtime', 'tool_trigger');
110110
$mform->setDefault('workflowrealtime', 0);
@@ -113,7 +113,7 @@ public function definition() {
113113
$mform->addElement('advcheckbox',
114114
'workflowdebug',
115115
get_string('workflowdebug', 'tool_trigger'),
116-
'Enable', array(), array(0, 1));
116+
'Enable', [], [0, 1]);
117117
$mform->setType('workflowdebug', PARAM_INT);
118118
$mform->addHelpButton('workflowdebug', 'workflowdebug', 'tool_trigger');
119119
$mform->setDefault('workflowdebug', 0);

classes/event_processor.php

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Process trigger system events.
19-
*
20-
* @package tool_trigger
21-
* @copyright Matt Porritt <[email protected]>
22-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23-
*/
24-
2517
namespace tool_trigger;
2618

2719
use tool_trigger\helper\processor_helper;
@@ -138,7 +130,7 @@ protected function is_event_ignored(\core\event\base $event) {
138130
// If we do not have the triggers in the cache then return them from the DB.
139131
if ($sitesubscriptions === false) {
140132
// Set the array for the cache.
141-
$sitesubscriptions = array();
133+
$sitesubscriptions = [];
142134
if ($subscriptions = $DB->get_records_sql($sql)) {
143135
foreach ($subscriptions as $subscription) {
144136
$sitesubscriptions[$subscription->event] = true;
@@ -198,6 +190,21 @@ private function process_realtime_workflows($evententry) {
198190
}
199191
}
200192

193+
/**
194+
* Processes a real-time workflow by executing its steps immediately in response to an event.
195+
*
196+
* This method:
197+
* - Marks the workflow as triggered and updates its record in the database.
198+
* - Records the workflow trigger in history.
199+
* - Restores the triggering event from stored data.
200+
* - Iterates through workflow steps in order, executing each step and recording results.
201+
* - Stops execution early if a step fails or throws an error.
202+
* - Handles transactional safety for each step to prevent partial writes.
203+
* - If an error occurs, records the failed step and queues the workflow for retry via cron.
204+
*
205+
* @param \stdClass $workflow The workflow object containing workflow metadata.
206+
* @param \stdClass $evententry The event entry object representing the trigger event data.
207+
*/
201208
private function process_realtime_workflow($workflow, $evententry) {
202209
global $DB;
203210

@@ -292,20 +299,20 @@ public static function record_workflow_trigger(int $workflowid, $event, int $att
292299

293300
// Get new run number.
294301
$sqlfrag = "SELECT MAX(number) FROM {tool_trigger_workflow_hist} WHERE workflowid = :wfid";
295-
$runnumber = $DB->get_field_sql($sqlfrag, array('wfid' => $workflowid)) + 1;
302+
$runnumber = $DB->get_field_sql($sqlfrag, ['wfid' => $workflowid]) + 1;
296303

297304
// Encode event data as JSON.
298305
$eventdata = json_encode($event);
299306

300-
$id = $DB->insert_record('tool_trigger_workflow_hist', array(
307+
$id = $DB->insert_record('tool_trigger_workflow_hist', [
301308
'workflowid' => $workflowid,
302309
'number' => $runnumber,
303310
'timecreated' => time(),
304311
'event' => $eventdata,
305312
'eventid' => $event->id,
306313
'userid' => $event->userid,
307-
'attemptnum' => $attemptnum
308-
), true);
314+
'attemptnum' => $attemptnum,
315+
], true);
309316

310317
// Return the id for use in other tables.
311318
return $id;
@@ -488,7 +495,7 @@ public static function execute_next_step_historic(int $stepid, int $origrun = 0,
488495
'workflow' => $step->workflowid,
489496
'run' => $origrun,
490497
'number' => $step->number + 1,
491-
'previd' => $step->id
498+
'previd' => $step->id,
492499
];
493500
$nextstep = $DB->get_record_sql($nextstepsql, $params);
494501

@@ -529,7 +536,7 @@ public static function execute_next_step_historic(int $stepid, int $origrun = 0,
529536
'workflow' => $nextstep->workflowid,
530537
'run' => $runid,
531538
'stepname' => $nextstep->name,
532-
'previd' => $previd
539+
'previd' => $previd,
533540
]);
534541

535542
// Return the ID just executed for use in moving through the historic chain.
@@ -559,7 +566,7 @@ public static function execute_next_step_current(int $stepid) {
559566
$nextstep = $DB->get_record_sql($nextstepsql, [
560567
'workflow' => $step->workflowid,
561568
'run' => $step->runid,
562-
'number' => $step->number + 1
569+
'number' => $step->number + 1,
563570
]);
564571

565572
// If no nextstep is found, jump out.
@@ -582,7 +589,7 @@ public static function execute_next_step_current(int $stepid) {
582589
$newstepid = $DB->get_field_sql($newstepsql, [
583590
'workflow' => $nextstep->workflowid,
584591
'run' => $nextstep->runid,
585-
'stepname' => $nextstep->name
592+
'stepname' => $nextstep->name,
586593
]);
587594
return $newstepid;
588595
}
@@ -619,7 +626,7 @@ public static function execute_step_and_continue_historic(int $stepid, bool $com
619626
$newstep = $DB->get_record_sql($newstepsql, [
620627
'workflow' => $step->workflowid,
621628
'run' => $newrunid,
622-
'stepname' => $step->name
629+
'stepname' => $step->name,
623630
]);
624631

625632
// Now execute the next step in the historic chain.
@@ -660,7 +667,7 @@ public static function execute_step_and_continue_current(int $stepid, bool $comp
660667
$newstep = $DB->get_record_sql($newstepsql, [
661668
'workflow' => $step->workflowid,
662669
'run' => $step->runid,
663-
'stepname' => $step->name
670+
'stepname' => $step->name,
664671
]);
665672

666673
// Now execute the next step, based on the step we just created.
@@ -809,7 +816,7 @@ public static function record_cancelled_workflow($workflowid, $event, $runid = n
809816

810817
// Get new run number.
811818
$sqlfrag = "SELECT MAX(number) FROM {tool_trigger_workflow_hist} WHERE workflowid = :wfid";
812-
$runnumber = $DB->get_field_sql($sqlfrag, array('wfid' => $workflowid)) + 1;
819+
$runnumber = $DB->get_field_sql($sqlfrag, ['wfid' => $workflowid]) + 1;
813820

814821
// Encode event data as JSON.
815822
$eventdata = json_encode($event);
@@ -822,7 +829,7 @@ public static function record_cancelled_workflow($workflowid, $event, $runid = n
822829
'timecreated' => time(),
823830
'event' => $eventdata,
824831
'eventid' => $event->id,
825-
'failedstep' => $status
832+
'failedstep' => $status,
826833
];
827834

828835
if (empty($runid)) {

classes/helper/datafield_manager.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* A lookup step that takes a user's ID and adds standard data about the user.
19-
*
20-
* @package tool_trigger
21-
* @author Aaron Wells <[email protected]>
22-
* @copyright Catalyst IT, 2018
23-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24-
*/
25-
2617
namespace tool_trigger\helper;
2718

2819
/**
@@ -36,6 +27,10 @@
3627
*/
3728
trait datafield_manager {
3829

30+
/**
31+
* Data fields.
32+
* @var array
33+
*/
3934
protected $datafields = [];
4035

4136
/** @var string regex to determine data fields - should ideally be readonly */

classes/helper/processor_helper.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
namespace tool_trigger\helper;
18+
1719
/**
1820
* trait to help in processing events.
1921
*
@@ -22,9 +24,6 @@
2224
* @copyright 2019 Catalyst IT
2325
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2426
*/
25-
26-
namespace tool_trigger\helper;
27-
2827
trait processor_helper {
2928

3029
/**
@@ -37,11 +36,11 @@ public function restore_event(\stdClass $data) {
3736
if (empty((array)$data)) {
3837
return null;
3938
}
40-
$extra = array('origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid);
39+
$extra = ['origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid];
4140
$data = (array)$data;
4241
$data['other'] = unserialize($data['other']);
4342
if ($data['other'] === false) {
44-
$data['other'] = array();
43+
$data['other'] = [];
4544
}
4645

4746
// Insert eventid into other data.

classes/import_form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function definition() {
5858

5959
// Workflow file.
6060
$mform->addElement('filepicker', 'userfile', get_string('workflowfile', 'tool_trigger'), null,
61-
array('maxbytes' => 256000, 'accepted_types' => '.json'));
61+
['maxbytes' => 256000, 'accepted_types' => '.json']);
6262
$mform->addRule('userfile', get_string('required'), 'required');
6363
}
6464

@@ -73,7 +73,7 @@ public function definition() {
7373
public function validation($data, $files) {
7474
global $USER;
7575

76-
$validationerrors = array();
76+
$validationerrors = [];
7777

7878
// Get the file from the filestystem. $files will always be empty.
7979
$fs = get_file_storage();

classes/json/json_export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function get_workflow_json($workflowrecord) {
132132
*
133133
* @param string $workflowjson
134134
*/
135-
private function print_json_data ($workflowjson) {
135+
private function print_json_data($workflowjson) {
136136
echo $workflowjson;
137137
}
138138

classes/learn_process.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class learn_process {
3737
*
3838
* @var array
3939
*/
40-
private $typearray = array();
40+
private $typearray = [];
4141

4242
/**
4343
* Get a list of all the distinct events names in the learning table.
@@ -64,7 +64,7 @@ private function get_learnt_events() {
6464
private function get_learnt_records($learntevent) {
6565
global $DB;
6666

67-
$learntrecords = $DB->get_recordset('tool_trigger_learn_events', array('eventname' => $learntevent));
67+
$learntrecords = $DB->get_recordset('tool_trigger_learn_events', ['eventname' => $learntevent]);
6868

6969
return $learntrecords;
7070
}
@@ -161,7 +161,7 @@ public function store_json_fields($learntevent, $jsonfields) {
161161
$transaction = $DB->start_delegated_transaction();
162162

163163
// Check for existing record in DB.
164-
$exists = $DB->get_record('tool_trigger_event_fields', array('eventname' => $learntevent), '*', IGNORE_MISSING);
164+
$exists = $DB->get_record('tool_trigger_event_fields', ['eventname' => $learntevent], '*', IGNORE_MISSING);
165165

166166
if ($exists) { // If record exists update.
167167
$record->id = $exists->id;
@@ -180,24 +180,24 @@ public function store_json_fields($learntevent, $jsonfields) {
180180
/**
181181
* Process the learnt events and extract the field names.
182182
*/
183-
public function process () {
183+
public function process() {
184184
global $DB;
185185

186186
// Get a list of the event types from the learn table.
187187
$learntevents = $this->get_learnt_events();
188188

189189
// For each type of event get all the entries for that event from the learn table.
190190
foreach ($learntevents as $learntevent) {
191-
$processedrecords = array();
191+
$processedrecords = [];
192192
$learntrecords = $this->get_learnt_records($learntevent);
193193

194194
foreach ($learntrecords as $record) {
195-
$this->typearray = array(); // Reset typearray before calling convert_record_type.
195+
$this->typearray = []; // Reset typearray before calling convert_record_type.
196196
// Convert each record into an array where key is field name and value is type.
197197
$processedrecords[] = $this->convert_record_type($record, false);
198198

199199
// Remove learnt event from DB.
200-
$DB->delete_records('tool_trigger_learn_events', array('id' => $record->id));
200+
$DB->delete_records('tool_trigger_learn_events', ['id' => $record->id]);
201201
}
202202

203203
$learntrecords->close(); // Don't forget to close the recordset!
@@ -239,7 +239,7 @@ public function get_event_fields_json($eventname) {
239239
global $DB;
240240
$jsonfields = $DB->get_record(
241241
'tool_trigger_event_fields',
242-
array('eventname' => $eventname), 'jsonfields', IGNORE_MISSING);
242+
['eventname' => $eventname], 'jsonfields', IGNORE_MISSING);
243243

244244
return $jsonfields;
245245
}
@@ -252,30 +252,30 @@ public function get_event_fields_json($eventname) {
252252
*/
253253
public function get_event_fields_with_type($eventname) {
254254
global $DB;
255-
$fieldarray = array();
255+
$fieldarray = [];
256256

257257
$jsonfields = $DB->get_record(
258258
'tool_trigger_event_fields',
259-
array('eventname' => $eventname), 'jsonfields', IGNORE_MISSING);
259+
['eventname' => $eventname], 'jsonfields', IGNORE_MISSING);
260260

261261
if ($jsonfields) {
262262
$fields = json_decode($jsonfields->jsonfields, true);
263263
foreach ($fields as $field => $type) {
264-
$fieldarray[] = array(
264+
$fieldarray[] = [
265265
'field' => $field,
266-
'type' => $type
267-
);
266+
'type' => $type,
267+
];
268268
}
269269
}
270270

271-
$fieldarray[] = array(
271+
$fieldarray[] = [
272272
'field' => 'wwwroot',
273-
'type' => 'string'
274-
);
275-
$fieldarray[] = array(
273+
'type' => 'string',
274+
];
275+
$fieldarray[] = [
276276
'field' => 'wwwroot_domain',
277-
'type' => 'string'
278-
);
277+
'type' => 'string',
278+
];
279279

280280
return $fieldarray;
281281
}

0 commit comments

Comments
 (0)