From 510c7f6d514f6fa9b0337848b6e3bc0a45301904 Mon Sep 17 00:00:00 2001 From: Michael Schink Date: Tue, 10 Sep 2024 15:56:18 +0200 Subject: [PATCH 1/3] Add checkbox to admin setting for trigger: specificdate to de & activate trigger only once a day --- .../lang/de/lifecycletrigger_specificdate.php | 2 +- .../lang/en/lifecycletrigger_specificdate.php | 2 +- trigger/specificdate/lib.php | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/trigger/specificdate/lang/de/lifecycletrigger_specificdate.php b/trigger/specificdate/lang/de/lifecycletrigger_specificdate.php index 5de91618..9781aea0 100644 --- a/trigger/specificdate/lang/de/lifecycletrigger_specificdate.php +++ b/trigger/specificdate/lang/de/lifecycletrigger_specificdate.php @@ -27,5 +27,5 @@ $string['dates_not_parseable'] = 'Daten müssen in dem Format Tag.Monat sein!'; $string['pluginname'] = 'Bestimmtes Datum - Trigger'; $string['privacy:metadata'] = 'Dieses Subplugin speichert keine persönlichen Daten.'; - +$string['timelastrunactive'] = 'Nur einmal pro Tag'; $string['timelastrun'] = 'Datum, an dem der Trigger zuletzt ausgeführt wurde.'; diff --git a/trigger/specificdate/lang/en/lifecycletrigger_specificdate.php b/trigger/specificdate/lang/en/lifecycletrigger_specificdate.php index 0133bab3..516e6ced 100644 --- a/trigger/specificdate/lang/en/lifecycletrigger_specificdate.php +++ b/trigger/specificdate/lang/en/lifecycletrigger_specificdate.php @@ -27,5 +27,5 @@ $string['dates_not_parseable'] = 'Dates must be of the format Day.Month'; $string['pluginname'] = 'Specific date trigger'; $string['privacy:metadata'] = 'This subplugin does not store any personal data.'; - +$string['timelastrunactive'] = 'Only once a day'; $string['timelastrun'] = 'Date when the trigger last run.'; diff --git a/trigger/specificdate/lib.php b/trigger/specificdate/lib.php index 67922207..0614f8d2 100644 --- a/trigger/specificdate/lib.php +++ b/trigger/specificdate/lib.php @@ -66,6 +66,8 @@ public function get_course_recordset_where($triggerid) { $settings = settings_manager::get_settings($triggerid, settings_type::TRIGGER); $datesraw = $settings['dates']; $dates = $this->parse_dates($datesraw); + // Get timelastrunactive + $timelastrunactive = $settings['timelastrunactive']; $lastrun = getdate($settings['timelastrun']); $current = time(); $today = getdate($current); @@ -74,7 +76,7 @@ public function get_course_recordset_where($triggerid) { // We want to trigger only if the $date is today. if ($date['mon'] == $today['mon'] && $date['day'] == $today['mday']) { // Now only make sure if $lastrun was today -> don't trigger. - if ($lastrun['yday'] == $today['yday'] && $lastrun['year'] == $today['year']) { + if ($timelastrunactive && $lastrun['yday'] == $today['yday'] && $lastrun['year'] == $today['year']) { continue; } else { $settings['timelastrun'] = $current; @@ -124,6 +126,8 @@ public function get_subpluginname() { public function instance_settings() { return [ new instance_setting('dates', PARAM_TEXT), + // Add activate timelastrun + new instance_setting('timelastrunactive', PARAM_INT), new instance_setting('timelastrun', PARAM_INT), ]; } @@ -138,6 +142,10 @@ public function extend_add_instance_form_definition($mform) { $mform->addElement('textarea', 'dates', get_string('dates', 'lifecycletrigger_specificdate')); $mform->setType('dates', PARAM_TEXT); $mform->addHelpButton('dates', 'dates', 'lifecycletrigger_specificdate'); + // Add activate timelastrun + $mform->addElement('advcheckbox', 'timelastrunactive', get_string('timelastrunactive', 'lifecycletrigger_specificjku')); + $mform->setDefault('timelastrunactive', 0); + //$mform->disabledIf('timelastrun', 'timelastrunactive'); $mform->addElement('hidden', 'timelastrun'); $mform->setDefault('timelastrun', 0); $mform->setType('timelastrun', PARAM_INT); From dde80f603dad93f0fa399e05c88dde6a23770f2b Mon Sep 17 00:00:00 2001 From: Michael Schink Date: Tue, 10 Sep 2024 15:56:18 +0200 Subject: [PATCH 2/3] Add checkbox to admin setting for trigger: specificdate to de & activate trigger only once a day --- .../lang/de/lifecycletrigger_specificdate.php | 2 +- .../lang/en/lifecycletrigger_specificdate.php | 2 +- trigger/specificdate/lib.php | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/trigger/specificdate/lang/de/lifecycletrigger_specificdate.php b/trigger/specificdate/lang/de/lifecycletrigger_specificdate.php index 5de91618..9781aea0 100644 --- a/trigger/specificdate/lang/de/lifecycletrigger_specificdate.php +++ b/trigger/specificdate/lang/de/lifecycletrigger_specificdate.php @@ -27,5 +27,5 @@ $string['dates_not_parseable'] = 'Daten müssen in dem Format Tag.Monat sein!'; $string['pluginname'] = 'Bestimmtes Datum - Trigger'; $string['privacy:metadata'] = 'Dieses Subplugin speichert keine persönlichen Daten.'; - +$string['timelastrunactive'] = 'Nur einmal pro Tag'; $string['timelastrun'] = 'Datum, an dem der Trigger zuletzt ausgeführt wurde.'; diff --git a/trigger/specificdate/lang/en/lifecycletrigger_specificdate.php b/trigger/specificdate/lang/en/lifecycletrigger_specificdate.php index 0133bab3..516e6ced 100644 --- a/trigger/specificdate/lang/en/lifecycletrigger_specificdate.php +++ b/trigger/specificdate/lang/en/lifecycletrigger_specificdate.php @@ -27,5 +27,5 @@ $string['dates_not_parseable'] = 'Dates must be of the format Day.Month'; $string['pluginname'] = 'Specific date trigger'; $string['privacy:metadata'] = 'This subplugin does not store any personal data.'; - +$string['timelastrunactive'] = 'Only once a day'; $string['timelastrun'] = 'Date when the trigger last run.'; diff --git a/trigger/specificdate/lib.php b/trigger/specificdate/lib.php index 67922207..c7b60169 100644 --- a/trigger/specificdate/lib.php +++ b/trigger/specificdate/lib.php @@ -66,6 +66,8 @@ public function get_course_recordset_where($triggerid) { $settings = settings_manager::get_settings($triggerid, settings_type::TRIGGER); $datesraw = $settings['dates']; $dates = $this->parse_dates($datesraw); + // Get timelastrunactive + $timelastrunactive = $settings['timelastrunactive']; $lastrun = getdate($settings['timelastrun']); $current = time(); $today = getdate($current); @@ -74,7 +76,7 @@ public function get_course_recordset_where($triggerid) { // We want to trigger only if the $date is today. if ($date['mon'] == $today['mon'] && $date['day'] == $today['mday']) { // Now only make sure if $lastrun was today -> don't trigger. - if ($lastrun['yday'] == $today['yday'] && $lastrun['year'] == $today['year']) { + if ($timelastrunactive && $lastrun['yday'] == $today['yday'] && $lastrun['year'] == $today['year']) { continue; } else { $settings['timelastrun'] = $current; @@ -124,6 +126,8 @@ public function get_subpluginname() { public function instance_settings() { return [ new instance_setting('dates', PARAM_TEXT), + // Add activate timelastrun + new instance_setting('timelastrunactive', PARAM_INT), new instance_setting('timelastrun', PARAM_INT), ]; } @@ -138,6 +142,10 @@ public function extend_add_instance_form_definition($mform) { $mform->addElement('textarea', 'dates', get_string('dates', 'lifecycletrigger_specificdate')); $mform->setType('dates', PARAM_TEXT); $mform->addHelpButton('dates', 'dates', 'lifecycletrigger_specificdate'); + // Add activate timelastrun + $mform->addElement('advcheckbox', 'timelastrunactive', get_string('timelastrunactive', 'lifecycletrigger_specificjku')); + $mform->setDefault('timelastrunactive', 1); + //$mform->disabledIf('timelastrun', 'timelastrunactive'); $mform->addElement('hidden', 'timelastrun'); $mform->setDefault('timelastrun', 0); $mform->setType('timelastrun', PARAM_INT); From bcb9682dbecd431ae16768fb26f95b39bca2caea Mon Sep 17 00:00:00 2001 From: Michael Schink Date: Thu, 12 Sep 2024 10:47:45 +0200 Subject: [PATCH 3/3] Fix 'delete & backup (other) course aftwerwards' error, which is created by moodle core issue MDL-65228 (https://tracker.moodle.org/browse/MDL-65228) --- step/deletecourse/lib.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/step/deletecourse/lib.php b/step/deletecourse/lib.php index 098f512a..6c8c470e 100644 --- a/step/deletecourse/lib.php +++ b/step/deletecourse/lib.php @@ -57,11 +57,20 @@ class deletecourse extends libbase { * @throws \dml_exception */ public function process_course($processid, $instanceid, $course) { + global $CFG; + if (self::$numberofdeletions >= settings_manager::get_settings( $instanceid, settings_type::STEP)['maximumdeletionspercron']) { return step_response::waiting(); // Wait with further deletions til the next cron run. } delete_course($course->id, true); + + // Fix 'delete & backup (other) course aftwerwards' error, which is created by moodle core issue MDL-65228 (https://tracker.moodle.org/browse/MDL-65228) + if(is_object($CFG) && property_exists($CFG, "forced_plugin_settings") && is_array($CFG->forced_plugin_settings) + && array_key_exists("backup", $CFG->forced_plugin_settings) && !is_array($CFG->forced_plugin_settings["backup"])) { + $CFG->forced_plugin_settings["backup"] = []; + } + self::$numberofdeletions++; return step_response::proceed(); }