Skip to content
Snippets Groups Projects
Commit 4a81288d authored by Felix Di Lenarda's avatar Felix Di Lenarda Committed by Justus Dieckmann
Browse files

Refined 'specificdate'-trigger, so it works and triggers 'todays'-date. #147

parent 51dcf1fa
Branches
No related tags found
No related merge requests found
......@@ -27,5 +27,6 @@ $string['privacy:metadata'] = 'Dieses Subplugin speichert keine persönlichen Da
$string['dates'] = 'Daten, an denen der Workflow ausgeführt werden soll.';
$string['dates_desc'] = 'Ein Datum pro Zeile in dem Format Tag.Monat';
$string['dates_desc_help'] = 'Ein Datum pro Zeile z.B.: 04.08 , für den 4. August. Wenn Sie das heutige Datum wählen wird es getriggert';
$string['timelastrun'] = 'Datum, an dem der Trigger zuletzt ausgeführt wurde.';
$string['dates_not_parseable'] = 'Daten müssen in dem Format Tag.Monat sein!';
......@@ -27,5 +27,6 @@ $string['privacy:metadata'] = 'This subplugin does not store any personal data.'
$string['dates'] = 'Dates at which the workflow should run.';
$string['dates_desc'] = 'Write one date per line with the format Day.Month';
$string['dates_desc_help'] = 'One date per line for example: 04.08 , for 4th of august. If you are putting todays date it will be triggered';
$string['timelastrun'] = 'Date when the trigger last run.';
$string['dates_not_parseable'] = 'Dates must be of the format Day.Month';
......@@ -64,40 +64,26 @@ class specificdate extends base_automatic {
*/
public function get_course_recordset_where($triggerid) {
$settings = settings_manager::get_settings($triggerid, settings_type::TRIGGER);
$lastrun = getdate($settings['timelastrun']);
$datesraw = $settings['dates'];
$dates = $this->parse_dates($datesraw);
$triggerat = array();
foreach ($dates as $dateparts) {
if ($dateparts['mon'] > $lastrun['mon']) {
$date = new DateTime($lastrun['year'].'-'.$dateparts['mon'].'-'.$dateparts['day']);
} else if ($dateparts['mon'] === $lastrun['mon']) {
if ($dateparts['day'] > $lastrun['day']) {
$date = new DateTime($lastrun['year'].'-'.$dateparts['mon'].'-'.$dateparts['day']);
} else {
$date = new DateTime(($lastrun['year'] + 1) .'-'.$dateparts['mon'].'-'.$dateparts['day']);
}
} else {
$date = new DateTime(($lastrun['year'] + 1) .'-'.$dateparts['mon'].'-'.$dateparts['day']);
}
$triggerat[] = $date->getTimestamp();
}
sort($triggerat);
$lastrun = getdate($settings['timelastrun']);
$current = time();
$today = getdate($current);
foreach ($triggerat as $timestamp) {
if ($timestamp < $current) {
foreach ($dates as $date) {
// 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']) {
continue;
} else {
$settings['timelastrun'] = $current;
$trigger = trigger_manager::get_instance($triggerid);
settings_manager::save_settings($triggerid, settings_type::TRIGGER, $trigger->subpluginname, $settings);
return array('true', array());
}
}
}
return array('false', array());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment