@@ -54,32 +54,51 @@ class processor {
5454 */
5555 public function call_trigger () {
5656 $ activeworkflows = workflow_manager::get_active_automatic_workflows ();
57- $ globallydelayedcourses = delayed_courses_manager:: get_globally_delayed_courses () ;
57+ $ exclude = [] ;
5858
5959 foreach ($ activeworkflows as $ workflow ) {
6060 $ countcourses = 0 ;
61+ $ counttriggered = 0 ;
62+ $ countexcluded = 0 ;
6163 mtrace ('Calling triggers for workflow " ' . $ workflow ->title . '" ' );
6264 $ triggers = trigger_manager::get_triggers_for_workflow ($ workflow ->id );
63- if ($ workflow ->includesitecourse ) {
64- $ sitecourse = [];
65- } else {
66- $ sitecourse = [1 ];
65+ if (!$ workflow ->includesitecourse ) {
66+ $ exclude [] = 1 ;
6767 }
68- if ($ workflow ->includedelayedcourses ) {
69- $ delayedcourses = [];
70- } else {
71- $ delayedcourses = array_merge (delayed_courses_manager::get_delayed_courses_for_workflow ($ workflow ->id ),
72- $ globallydelayedcourses );
68+ if (!$ workflow ->includedelayedcourses ) {
69+ $ exclude = array_merge (delayed_courses_manager::get_delayed_courses_for_workflow ($ workflow ->id ),
70+ $ exclude );
7371 }
74- $ recordset = $ this ->get_course_recordset ($ triggers , array_merge ( $ delayedcourses , $ sitecourse ) );
72+ $ recordset = $ this ->get_course_recordset ($ triggers , $ exclude );
7573 while ($ recordset ->valid ()) {
7674 $ course = $ recordset ->current ();
7775 $ countcourses ++;
76+ foreach ($ triggers as $ trigger ) {
77+ $ lib = lib_manager::get_automatic_trigger_lib ($ trigger ->subpluginname );
78+ $ response = $ lib ->check_course ($ course , $ trigger ->id );
79+ if ($ response == trigger_response::next ()) {
80+ $ recordset ->next ();
81+ continue 2 ;
82+ }
83+ if ($ response == trigger_response::exclude ()) {
84+ array_push ($ exclude , $ course ->id );
85+ $ countexcluded ++;
86+ $ recordset ->next ();
87+ continue 2 ;
88+ }
89+ if ($ response == trigger_response::trigger ()) {
90+ continue ;
91+ }
92+ }
93+ // If all trigger instances agree, that they want to trigger a process, we do so.
7894 $ process = process_manager::create_process ($ course ->id , $ workflow ->id );
7995 process_triggered::event_from_process ($ process )->trigger ();
96+ $ counttriggered ++;
8097 $ recordset ->next ();
8198 }
8299 mtrace (" $ countcourses courses processed. " );
100+ mtrace (" $ counttriggered courses triggered. " );
101+ mtrace (" $ countexcluded courses excluded. " );
83102 }
84103 }
85104
@@ -299,7 +318,7 @@ public function get_triggercourses_forcounting($trigger, $excluded, $delayed) {
299318 * Relevant means that there is currently no lifecycle process running for this course.
300319 * @param trigger_subplugin $trigger trigger, which will be asked for additional where requirements.
301320 * @param object $workflow workflow instance.
302- * @return \moodle_recordset with relevant courses.
321+ * @return array with relevant courses.
303322 * @throws \coding_exception
304323 * @throws \dml_exception
305324 */
0 commit comments