diff --git a/classes/task/lifecycle_cleanup_task.php b/classes/task/lifecycle_cleanup_task.php new file mode 100644 index 0000000000000000000000000000000000000000..7a8f6f91c8ae4dccb5f6651c238e28e6831c1d72 --- /dev/null +++ b/classes/task/lifecycle_cleanup_task.php @@ -0,0 +1,56 @@ +<?php +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. + +/** + * Scheduled task for cleanup past delays + * + * @package tool_lifecycle + * @copyright 2019 Justus Dieckmann WWU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace tool_lifecycle\task; + +defined('MOODLE_INTERNAL') || die; + +/** + * Scheduled task for cleanup past delays + * + * @package tool_lifecycle + * @copyright 2019 Justus Dieckmann WWU + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class lifecycle_cleanup_task extends \core\task\scheduled_task { + + /** + * Get a descriptive name for this task (shown to admins). + * + * @return string + * @throws \coding_exception + */ + public function get_name() { + return get_string('lifecycle_cleanup_task', 'tool_lifecycle'); + } + + /** + * Do the job. + */ + public function execute() { + global $DB; + $twomonthago = time() - 60 * 24 * 60 * 60; + $DB->delete_records_select('tool_lifecycle_delayed', 'delayeduntil <= :time', array('time' => $twomonthago)); + $DB->delete_records_select('tool_lifecycle_delayed_workf', 'delayeduntil <= :time', array('time' => $twomonthago)); + } +} \ No newline at end of file diff --git a/db/tasks.php b/db/tasks.php index 22611f5f696b7faabf38cc6fe0bb2b7488fb2004..227744d3e6f8c3203542882eb5b7679a2f6e3a1b 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -35,5 +35,14 @@ $tasks = array( 'month' => '*', 'dayofweek' => '*', 'faildelay' => 1, + ), + array( + 'classname' => 'tool_lifecycle\task\lifecycle_cleanup_task', + 'blocking' => 0, + 'minute' => '0', + 'hour' => '4', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '0', ) ); \ No newline at end of file diff --git a/lang/en/tool_lifecycle.php b/lang/en/tool_lifecycle.php index 875144a0f395796591f1626eb1711da247a0e95e..f657848cfcc0b863cfa7b75efec1f48a86fa0de6 100644 --- a/lang/en/tool_lifecycle.php +++ b/lang/en/tool_lifecycle.php @@ -60,6 +60,7 @@ $string['cannot_trigger_workflow_manually'] = 'The requested workflow could not $string['error_wrong_trigger_selected'] = 'You tried to request a non-manual trigger.'; $string['lifecycle_task'] = 'Run the life cycle processes'; +$string['lifecycle_cleanup_task'] = 'Runs the life cycle cleanup'; $string['trigger_subpluginname'] = 'Subplugin name'; $string['trigger_subpluginname_help'] = 'Step subplugin/trigger title (visible for admins only).'; diff --git a/version.php b/version.php index 03546b64f0e9cf8a7a390bf93bf1d33e963623ad..68e10b16997001dff40179fb97a57f33bdc9c3ce 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die; $plugin->maturity = MATURITY_BETA; -$plugin->version = 2019102900; +$plugin->version = 2019103100; $plugin->component = 'tool_lifecycle'; $plugin->requires = 2017111300; // Require Moodle 3.4 (or above). $plugin->release = 'v3.7-r1';