1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Recycle bin cron task.
|
|
|
19 |
*
|
|
|
20 |
* @package tool_recyclebin
|
|
|
21 |
* @copyright 2015 University of Kent
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace tool_recyclebin\task;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* This task deletes expired category recyclebin items.
|
|
|
29 |
*
|
|
|
30 |
* @package tool_recyclebin
|
|
|
31 |
* @copyright 2015 University of Kent
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class cleanup_category_bin extends \core\task\scheduled_task {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Task name.
|
|
|
38 |
*/
|
|
|
39 |
public function get_name() {
|
|
|
40 |
return get_string('taskcleanupcategorybin', 'tool_recyclebin');
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Delete all expired items.
|
|
|
45 |
*/
|
|
|
46 |
public function execute() {
|
|
|
47 |
global $DB;
|
|
|
48 |
|
|
|
49 |
// Check if the category bin is disabled or there is no expiry time.
|
|
|
50 |
$lifetime = get_config('tool_recyclebin', 'categorybinexpiry');
|
|
|
51 |
if (!\tool_recyclebin\category_bin::is_enabled() || $lifetime <= 0) {
|
|
|
52 |
return true;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
// Get the items we can delete.
|
|
|
56 |
$items = $DB->get_recordset_select('tool_recyclebin_category', 'timecreated <= :timecreated',
|
|
|
57 |
array('timecreated' => time() - $lifetime));
|
|
|
58 |
foreach ($items as $item) {
|
|
|
59 |
mtrace("[tool_recyclebin] Deleting item '{$item->id}' from the category recycle bin ...");
|
|
|
60 |
$bin = new \tool_recyclebin\category_bin($item->categoryid);
|
|
|
61 |
$bin->delete_item($item);
|
|
|
62 |
}
|
|
|
63 |
$items->close();
|
|
|
64 |
|
|
|
65 |
return true;
|
|
|
66 |
}
|
|
|
67 |
}
|