Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions step/deletecourse/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
10 changes: 9 additions & 1 deletion trigger/specificdate/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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),
];
}
Expand All @@ -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);
Expand Down