Skip to content

Commit 101783a

Browse files
authored
Behattests one by one (#238)
* behat link to workflowdrafts * new wf edit header * change to tab links * add_workflow.feature * new line at end of file * disable_workflow.feature * new line! * interaction.feature * interaction_forms.feature * exclude hidden courses of remaining course list if user has not capability viewhiddencourses * manual_trigger.feature * upload_workflow.feature * fix settings to work with subplugins correctly * fix settings problems, subplugin descriptions, version.php of subplugins, counters in the tabs * codechecker/phpdoc issues * change ci to test only against 4.5 * behat and php 8.3 issues * lint issue * remove additional process class fields for error message table * fix error writing wf error table * fix name of uploadfile * use label of filepicker for testing
1 parent 3c8128e commit 101783a

File tree

54 files changed

+281
-117
lines changed

Some content is hidden

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

54 files changed

+281
-117
lines changed

.github/workflows/config.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
"main-moodle": "MOODLE_405_STABLE",
33
"main-php": "8.3",
44
"moodle-php": {
5-
"MOODLE_401_STABLE": ["7.4", "8.1"],
6-
"MOODLE_402_STABLE": ["8.0", "8.2"],
7-
"MOODLE_403_STABLE": ["8.0", "8.2"],
8-
"MOODLE_404_STABLE": ["8.1", "8.3"],
95
"MOODLE_405_STABLE": ["8.1", "8.2", "8.3"]
106
},
117
"moodle-plugin-ci": "4.4.5"

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CHANGELOG
2+
=========
3+
4+
4.5.0 (2025-03-13)
5+
------------------
6+
* [FEATURE]
7+
* [FIXED]
8+
* Moodle 4.5 compatible version

classes/local/form/form_trigger_instance.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public function __construct($url, $workflowid, $trigger = null, $subpluginname =
101101
* Defines forms elements
102102
*/
103103
public function definition() {
104+
global $OUTPUT;
105+
104106
$mform = $this->_form;
105107

106108
$mform->addElement('hidden', 'id'); // Save the record's id.

classes/local/manager/process_manager.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use core\event\course_deleted;
2727
use Exception;
28+
use stdClass;
2829
use tool_lifecycle\local\entity\process;
2930
use tool_lifecycle\event\process_proceeded;
3031
use tool_lifecycle\event\process_rollback;
@@ -255,7 +256,12 @@ public static function abort_process($process) {
255256
public static function insert_process_error(process $process, Exception $e) {
256257
global $DB;
257258

258-
$procerror = (object) clone $process;
259+
$procerror = new stdClass();
260+
$procerror->id = $process->id;
261+
$procerror->courseid = $process->courseid;
262+
$procerror->workflowid = $process->workflowid;
263+
$procerror->stepindex = $process->stepindex;
264+
$procerror->timestepchanged = $process->timestepchanged;
259265
$procerror->errormessage = get_class($e) . ': ' . $e->getMessage();
260266
$procerror->errortrace = $e->getTraceAsString();
261267
$procerror->errortimecreated = time();
@@ -264,7 +270,7 @@ public static function insert_process_error(process $process, Exception $e) {
264270
$m .= $v['file'] . ':' . $v['line'] . '::';
265271
}
266272
$procerror->errorhash = md5($m);
267-
$procerror->waiting = intval($procerror->waiting);
273+
$procerror->waiting = intval($process->waiting);
268274

269275
$DB->insert_record_raw('tool_lifecycle_proc_error', $procerror, false, false, true);
270276
$DB->delete_records('tool_lifecycle_process', ['id' => $process->id]);

classes/local/manager/workflow_manager.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ public static function get_manual_trigger_tools_for_active_workflows() {
233233
$tools = [];
234234
foreach ($triggers as $trigger) {
235235
$settings = settings_manager::get_settings($trigger->id, settings_type::TRIGGER);
236-
$tools[] = new manual_trigger_tool($trigger->id, $settings['icon'], $settings['displayname'], $settings['capability']);
236+
if (isset($settings['displayname'])) {
237+
$tools[] = new manual_trigger_tool($trigger->id, $settings['icon'],
238+
$settings['displayname'], $settings['capability']);
239+
}
237240
}
238241
return $tools;
239242
}

classes/tabs.php

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,98 @@ class tabs {
3636
/**
3737
* Generates a Moodle tabrow i.e. an array of tabs
3838
*
39-
* @return array
39+
* @param bool $activelink display active workflows tab as link
40+
* @param bool $deactivatelink display deactivated workflows tab as link
41+
* @param bool $draftlink display draft workflows tab as link
42+
* @return array of tabobjects
4043
* @throws \coding_exception
44+
* @throws \dml_exception
4145
* @throws moodle_exception
4246
*/
43-
public static function get_tabrow() {
47+
public static function get_tabrow($activelink = false, $deactivatelink = false, $draftlink = false) {
48+
global $DB;
4449

45-
$targeturl = new \moodle_url('/admin/settings.php', ['section' => 'lifecycle']);
50+
$classnotnull = 'badge badge-primary badge-pill ml-1';
51+
$classnull = 'badge badge-secondary badge-pill ml-1';
52+
53+
// Get number of drafts.
54+
$sql = "select count(id)
55+
from {tool_lifecycle_workflow}
56+
where timeactive IS NULL AND timedeactive IS NULL";
57+
$i = $DB->count_records_sql($sql);
58+
$drafts = \html_writer::span($i, $i > 0 ? $classnotnull : $classnull);
59+
60+
// Get number of active workflows.
61+
$sql = "select count(id)
62+
from {tool_lifecycle_workflow}
63+
where timeactive IS NOT NULL";
64+
$i = $DB->count_records_sql($sql);
65+
$activewf = \html_writer::span($i, $i > 0 ? $classnotnull : $classnull);
66+
67+
// Get number of deactivated workflows.
68+
$sql = "select count(id)
69+
from {tool_lifecycle_workflow}
70+
where timeactive IS NULL AND timedeactive IS NOT NULL";
71+
$i = $DB->count_records_sql($sql);
72+
$deactivatedewf = \html_writer::span($i, $i > 0 ? $classnotnull : $classnull);
73+
74+
// Get number of delayed courses.
75+
$sql = "select count(id)
76+
from {tool_lifecycle_delayed}";
77+
$i = $DB->count_records_sql($sql);
78+
$delayedcourses = \html_writer::span($i, $i > 0 ? $classnotnull : $classnull);
79+
80+
// Get number of lifecycle course backups.
81+
$sql = "select count(id)
82+
from {tool_lifecycle_backups}";
83+
$i = $DB->count_records_sql($sql);
84+
$coursebackups = \html_writer::span($i, $i > 0 ? $classnotnull : $classnull);
85+
86+
// Get number of stores lifecycle errors.
87+
$sql = "select count(id)
88+
from {tool_lifecycle_proc_error}";
89+
$i = $DB->count_records_sql($sql);
90+
$lcerrors = \html_writer::span($i, $i > 0 ? $classnotnull : $classnull);
91+
92+
// General Settings and Subplugins.
93+
$targeturl = new \moodle_url('/admin/category.php', ['category' => 'lifecycle']);
4694
$tabrow[] = new \tabobject('settings', $targeturl,
4795
get_string('general_config_header', 'tool_lifecycle'));
4896

97+
// Tab to the draft workflows page.
4998
$targeturl = new \moodle_url('/admin/tool/lifecycle/workflowdrafts.php', ['id' => 'workflowdrafts']);
5099
$tabrow[] = new \tabobject('workflowdrafts', $targeturl,
51-
get_string('workflow_drafts_header', 'tool_lifecycle'));
100+
get_string('workflow_drafts_header', 'tool_lifecycle').$drafts,
101+
get_string('workflow_drafts_header', 'tool_lifecycle'), $draftlink);
52102

103+
// Tab to the active workflows page.
53104
$targeturl = new \moodle_url('/admin/tool/lifecycle/activeworkflows.php', ['id' => 'activeworkflows']);
54105
$tabrow[] = new \tabobject('activeworkflows', $targeturl,
55-
get_string('active_workflows_header', 'tool_lifecycle'));
106+
get_string('active_workflows_header', 'tool_lifecycle').$activewf,
107+
get_string('active_workflows_header', 'tool_lifecycle'), $activelink);
56108

109+
// Tab to the deactivated workflows page.
57110
$targeturl = new \moodle_url('/admin/tool/lifecycle/deactivatedworkflows.php', ['id' => 'deactivatedworkflows']);
58111
$tabrow[] = new \tabobject('deactivatedworkflows', $targeturl,
59-
get_string('deactivated_workflows_header', 'tool_lifecycle'));
60-
61-
$targeturl = new \moodle_url('/admin/tool/lifecycle/coursebackups.php', ['id' => 'coursebackups']);
62-
$tabrow[] = new \tabobject('coursebackups', $targeturl,
63-
get_string('course_backups_list_header', 'tool_lifecycle'));
112+
get_string('deactivated_workflows_header', 'tool_lifecycle').$deactivatedewf,
113+
get_string('deactivated_workflows_header', 'tool_lifecycle'), $deactivatelink);
64114

115+
// Tab to the delayed courses list page.
65116
$targeturl = new \moodle_url('/admin/tool/lifecycle/delayedcourses.php', ['id' => 'delayedcourses']);
66117
$tabrow[] = new \tabobject('delayedcourses', $targeturl,
118+
get_string('delayed_courses_header', 'tool_lifecycle').$delayedcourses,
67119
get_string('delayed_courses_header', 'tool_lifecycle'));
68120

121+
// Tab to the course backups list page.
122+
$targeturl = new \moodle_url('/admin/tool/lifecycle/coursebackups.php', ['id' => 'coursebackups']);
123+
$tabrow[] = new \tabobject('coursebackups', $targeturl,
124+
get_string('course_backups_list_header', 'tool_lifecycle').$coursebackups,
125+
get_string('course_backups_list_header', 'tool_lifecycle'));
126+
127+
// Tab to the lifecycle errors page.
69128
$targeturl = new \moodle_url('/admin/tool/lifecycle/errors.php', ['id' => 'errors']);
70129
$tabrow[] = new \tabobject('errors', $targeturl,
130+
get_string('process_errors_header', 'tool_lifecycle').$lcerrors,
71131
get_string('process_errors_header', 'tool_lifecycle'));
72132

73133
return $tabrow;

classes/view_controller.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,31 @@ class view_controller {
5252
* @throws \invalid_parameter_exception
5353
*/
5454
public function handle_view($renderer, $filterdata) {
55-
global $DB;
55+
global $DB, $USER;
5656

57-
$courses = get_user_capability_course('tool/lifecycle:managecourses', null, false);
57+
$coursesasmanager = get_user_capability_course('tool/lifecycle:managecourses', null, false);
58+
$courseids1 = array_column($coursesasmanager, 'id');
59+
$usercourses = enrol_get_users_courses($USER->id);
60+
$courseids2 = array_column($usercourses, 'id');
61+
$courses = array_intersect($courseids1, $courseids2);
5862
if (!$courses) {
5963
echo 'no courses';
6064
// TODO show error.
6165
return;
6266
}
6367

64-
$arrayofcourseids = [];
65-
foreach ($courses as $course) {
66-
$arrayofcourseids[$course->id] = $course->id;
67-
}
68-
$listofcourseids = implode(',', $arrayofcourseids);
69-
70-
$processes = $DB->get_recordset_sql("SELECT p.id as processid, c.id as courseid, c.fullname as coursefullname, " .
71-
"c.shortname as courseshortname, s.id as stepinstanceid, s.instancename as stepinstancename, s.subpluginname " .
68+
[$insql, $inparams] = $DB->get_in_or_equal($courses);
69+
$sql = "SELECT p.id as processid, c.id as courseid, c.fullname as coursefullname, " .
70+
"c.shortname as courseshortname, s.id as stepinstanceid, s.instancename as stepinstancename, s.subpluginname " .
7271
"FROM {tool_lifecycle_process} p join " .
7372
"{course} c on p.courseid = c.id join " .
7473
"{tool_lifecycle_step} s ".
7574
"on p.workflowid = s.workflowid AND p.stepindex = s.sortindex " .
76-
"WHERE p.courseid IN (". $listofcourseids . ")");
75+
"WHERE p.courseid $insql";
76+
$processes = $DB->get_recordset_sql($sql, $inparams);
7777

7878
$requiresinteraction = [];
79-
$remainingcourses = $arrayofcourseids;
79+
$remainingcourses = $inparams;
8080

8181
foreach ($processes as $process) {
8282
$step = step_manager::get_step_instance($process->stepinstanceid);

lang/de/tool_lifecycle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
$string['step_settings_header'] = 'Einstellungen des Schritts';
151151
$string['step_show'] = 'Anzeigen';
152152
$string['step_sortindex'] = 'Hoch/Runter';
153-
$string['step_subpluginname'] = 'Subpluginname';
153+
$string['step_subpluginname'] = 'Schritt Typ';
154154
$string['step_subpluginname_help'] = 'Name des Schritt/Trigger-Subplugins (nur für Admins sichtbar).';
155155
$string['step_type'] = 'Typ';
156156
$string['steps_installed'] = 'Installierte Schritt-Subplugins';
@@ -172,7 +172,7 @@
172172
$string['trigger_instancename_help'] = 'Titel der Trigger-Instanz (nur sichtbar für Admins).';
173173
$string['trigger_settings_header'] = 'Einstellungen des Triggers';
174174
$string['trigger_sortindex'] = 'Hoch/Runter';
175-
$string['trigger_subpluginname'] = 'Subplugin Name';
175+
$string['trigger_subpluginname'] = 'Trigger Typ';
176176
$string['trigger_subpluginname_help'] = 'Name des Schritt/Trigger-Subplugins (nur für Admins sichtbar).';
177177
$string['trigger_workflow'] = 'Workflow';
178178
$string['triggers_installed'] = 'Installierte Trigger';

lang/en/tool_lifecycle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
$string['step_settings_header'] = 'Settings of the step';
183183
$string['step_show'] = 'Show';
184184
$string['step_sortindex'] = 'Up/Down';
185-
$string['step_subpluginname'] = 'Subplugin name';
185+
$string['step_subpluginname'] = 'Step type';
186186
$string['step_subpluginname_help'] = 'Step subplugin/trigger title (visible for admins only).';
187187
$string['step_type'] = 'Type';
188188
$string['steps_installed'] = 'Installed Steps';
@@ -204,7 +204,7 @@
204204
$string['trigger_instancename_help'] = 'Trigger instance title (visible for admins only).';
205205
$string['trigger_settings_header'] = 'Settings of the trigger';
206206
$string['trigger_sortindex'] = 'Up/Down';
207-
$string['trigger_subpluginname'] = 'Subplugin name';
207+
$string['trigger_subpluginname'] = 'Trigger type';
208208
$string['trigger_subpluginname_help'] = 'Step subplugin/trigger title (visible for admins only).';
209209
$string['trigger_workflow'] = 'Workflow';
210210
$string['triggers_installed'] = 'Installed Triggers';

settings.php

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,49 @@
3030
// Check for the moodle/site:config permission.
3131
if ($hassiteconfig) {
3232

33-
$settings = new admin_settingpage('lifecycle', get_string('pluginname', 'tool_lifecycle'));
34-
$ADMIN->add('tools', $settings);
35-
3633
$triggers = core_component::get_plugin_list('lifecycletrigger');
3734
$steps = core_component::get_plugin_list('lifecyclestep');
3835

36+
$ADMIN->add('tools', new admin_category('lifecycle',
37+
get_string('pluginname', 'tool_lifecycle')));
38+
$settings = new admin_settingpage('lifecycle_settings',
39+
get_string('general_config_header', 'tool_lifecycle'));
40+
3941
if (!$ADMIN->fulltree) {
40-
// Include settings page of each trigger subplugin, if there is one.
42+
$stepsortriggersettings = false;
43+
// Check if there are trigger settings pages.
4144
if ($triggers) {
4245
foreach ($triggers as $trigger => $path) {
4346
if (file_exists($settingsfile = $path . '/settings.php')) {
44-
include($settingsfile);
47+
$stepsortriggersettings = true;
48+
break;
4549
}
4650
}
4751
}
48-
// Include settings page of each step subplugin, if there is one.
49-
if ($steps) {
52+
// Check if there are step settings pages.
53+
if (!$stepsortriggersettings && $steps) {
5054
foreach ($steps as $step => $path) {
5155
if (file_exists($settingsfile = $path . '/settings.php')) {
52-
include($settingsfile);
56+
$stepsortriggersettings = true;
57+
break;
58+
}
59+
}
60+
}
61+
if ($stepsortriggersettings) {
62+
// Include settings page of each trigger subplugin, if there is one.
63+
if ($triggers) {
64+
foreach ($triggers as $trigger => $path) {
65+
if (file_exists($settingsfile = $path . '/settings.php')) {
66+
include($settingsfile);
67+
}
68+
}
69+
}
70+
// Include settings page of each step subplugin, if there is one.
71+
if ($steps) {
72+
foreach ($steps as $step => $path) {
73+
if (file_exists($settingsfile = $path . '/settings.php')) {
74+
include($settingsfile);
75+
}
5376
}
5477
}
5578
}
@@ -80,10 +103,8 @@
80103
get_string('triggers_installed', 'tool_lifecycle'), ''));
81104
foreach ($triggers as $trigger => $path) {
82105
$settings->add(new admin_setting_description('lifecycletriggersetting_'.$trigger,
83-
get_string('pluginname', 'lifecycletrigger_' . $trigger), ''));
84-
if (file_exists($settingsfile = $path . '/settings.php')) {
85-
include($settingsfile);
86-
}
106+
get_string('pluginname', 'lifecycletrigger_' . $trigger),
107+
get_string('plugindescription', 'lifecycletrigger_' . $trigger)));
87108
}
88109
} else {
89110
$settings->add(new admin_setting_heading('adminsettings_notriggers',
@@ -95,14 +116,13 @@
95116
get_string('steps_installed', 'tool_lifecycle'), ''));
96117
foreach ($steps as $step => $path) {
97118
$settings->add(new admin_setting_description('lifecyclestepsetting_'.$step,
98-
get_string('pluginname', 'lifecyclestep_' . $step), ''));
99-
if (file_exists($settingsfile = $path . '/settings.php')) {
100-
include($settingsfile);
101-
}
119+
get_string('pluginname', 'lifecyclestep_' . $step),
120+
get_string('plugindescription', 'lifecyclestep_' . $step)));
102121
}
103122
} else {
104123
$settings->add(new admin_setting_heading('adminsettings_nosteps',
105124
get_string('adminsettings_nosteps', 'tool_lifecycle'), ''));
106125
}
126+
$ADMIN->add('lifecycle', $settings);
107127
}
108128
}

0 commit comments

Comments
 (0)