Skip to content

Commit bb0af5a

Browse files
mikeJKUmikenetcode
andauthored
Add checkbox to admin setting for trigger: specificdate and fix 'delete & backup (other) course afterwards' error, which is created by moodle core issue MDL-65228 (#221)
* Add checkbox to admin setting for trigger: specificdate to de & activate trigger only once a day * Fix 'delete & backup (other) course aftwerwards' error, which is created by moodle core issue MDL-65228 (https://tracker.moodle.org/browse/MDL-65228) --------- Co-authored-by: Michael Schink <[email protected]>
1 parent ac5ae48 commit bb0af5a

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

step/deletecourse/lib.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,20 @@ class deletecourse extends libbase {
5757
* @throws \dml_exception
5858
*/
5959
public function process_course($processid, $instanceid, $course) {
60+
global $CFG;
61+
6062
if (self::$numberofdeletions >= settings_manager::get_settings(
6163
$instanceid, settings_type::STEP)['maximumdeletionspercron']) {
6264
return step_response::waiting(); // Wait with further deletions til the next cron run.
6365
}
6466
delete_course($course->id, true);
67+
68+
// Fix 'delete & backup (other) course aftwerwards' error, which is created by moodle core issue MDL-65228 (https://tracker.moodle.org/browse/MDL-65228)
69+
if(is_object($CFG) && property_exists($CFG, "forced_plugin_settings") && is_array($CFG->forced_plugin_settings)
70+
&& array_key_exists("backup", $CFG->forced_plugin_settings) && !is_array($CFG->forced_plugin_settings["backup"])) {
71+
$CFG->forced_plugin_settings["backup"] = [];
72+
}
73+
6574
self::$numberofdeletions++;
6675
return step_response::proceed();
6776
}

trigger/specificdate/lang/de/lifecycletrigger_specificdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
$string['dates_not_parseable'] = 'Daten müssen in dem Format Tag.Monat sein!';
2828
$string['pluginname'] = 'Bestimmtes Datum - Trigger';
2929
$string['privacy:metadata'] = 'Dieses Subplugin speichert keine persönlichen Daten.';
30-
30+
$string['timelastrunactive'] = 'Nur einmal pro Tag';
3131
$string['timelastrun'] = 'Datum, an dem der Trigger zuletzt ausgeführt wurde.';

trigger/specificdate/lang/en/lifecycletrigger_specificdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
$string['dates_not_parseable'] = 'Dates must be of the format Day.Month';
2828
$string['pluginname'] = 'Specific date trigger';
2929
$string['privacy:metadata'] = 'This subplugin does not store any personal data.';
30-
30+
$string['timelastrunactive'] = 'Only once a day';
3131
$string['timelastrun'] = 'Date when the trigger last run.';

trigger/specificdate/lib.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function get_course_recordset_where($triggerid) {
6666
$settings = settings_manager::get_settings($triggerid, settings_type::TRIGGER);
6767
$datesraw = $settings['dates'];
6868
$dates = $this->parse_dates($datesraw);
69+
// Get timelastrunactive
70+
$timelastrunactive = $settings['timelastrunactive'];
6971
$lastrun = getdate($settings['timelastrun']);
7072
$current = time();
7173
$today = getdate($current);
@@ -74,7 +76,7 @@ public function get_course_recordset_where($triggerid) {
7476
// We want to trigger only if the $date is today.
7577
if ($date['mon'] == $today['mon'] && $date['day'] == $today['mday']) {
7678
// Now only make sure if $lastrun was today -> don't trigger.
77-
if ($lastrun['yday'] == $today['yday'] && $lastrun['year'] == $today['year']) {
79+
if ($timelastrunactive && $lastrun['yday'] == $today['yday'] && $lastrun['year'] == $today['year']) {
7880
continue;
7981
} else {
8082
$settings['timelastrun'] = $current;
@@ -124,6 +126,8 @@ public function get_subpluginname() {
124126
public function instance_settings() {
125127
return [
126128
new instance_setting('dates', PARAM_TEXT),
129+
// Add activate timelastrun
130+
new instance_setting('timelastrunactive', PARAM_INT),
127131
new instance_setting('timelastrun', PARAM_INT),
128132
];
129133
}
@@ -138,6 +142,10 @@ public function extend_add_instance_form_definition($mform) {
138142
$mform->addElement('textarea', 'dates', get_string('dates', 'lifecycletrigger_specificdate'));
139143
$mform->setType('dates', PARAM_TEXT);
140144
$mform->addHelpButton('dates', 'dates', 'lifecycletrigger_specificdate');
145+
// Add activate timelastrun
146+
$mform->addElement('advcheckbox', 'timelastrunactive', get_string('timelastrunactive', 'lifecycletrigger_specificjku'));
147+
$mform->setDefault('timelastrunactive', 1);
148+
//$mform->disabledIf('timelastrun', 'timelastrunactive');
141149
$mform->addElement('hidden', 'timelastrun');
142150
$mform->setDefault('timelastrun', 0);
143151
$mform->setType('timelastrun', PARAM_INT);

0 commit comments

Comments
 (0)