-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathghost.php
More file actions
115 lines (97 loc) · 3.2 KB
/
ghost.php
File metadata and controls
115 lines (97 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Ghost files management page for cleanup plugin.
*
* @package local_cleanup
* @copyright 2024 Grinchenko University
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @var moodle_page $PAGE
* @var moodle_database $DB
* @var stdClass $USER
* @var stdClass $CFG
* @var renderer_base $OUTPUT
*/
require_once(__DIR__ . '/../../config.php');
use core\task\manager as task_manager;
use local_cleanup\task\cleanup;
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/local/cleanup/ghost.php');
$PAGE->set_title(get_string('ghostfiles', 'local_cleanup'));
$PAGE->set_heading(get_string('ghostfiles', 'local_cleanup'));
$PAGE->set_pagelayout('admin');
require_login();
if (!is_siteadmin()) {
header('HTTP/1.1 403 Forbidden');
exit('Forbidden!');
}
$task = task_manager::get_scheduled_task(cleanup::class);
$page = optional_param('page', 0, PARAM_INT);
$limit = 250;
$items = $DB->get_recordset('local_cleanup_files', [], 'size DESC', '*', $page * $limit, $limit);
$totalitems = $DB->count_records('local_cleanup_files');
$totalsize = $DB->get_field('local_cleanup_files', 'SUM(size)', []);
$table = new html_table();
$table->head = [
get_string('file'),
'MIME',
get_string('size'),
'',
];
while ($items->valid()) {
$item = $items->current();
$actions = [
html_writer::link(
new moodle_url('/local/cleanup/download.php', ['path' => $item->path]),
$OUTPUT->pix_icon('i/down', get_string('download'))
),
];
$table->data[] = [
$item->path,
$item->mime,
sprintf(
'%.1f %s',
$item->size / pow(1024, 2),
get_string('sizemb')
),
implode(' ', $actions),
];
$items->next();
}
$pagination = $OUTPUT->paging_bar($totalitems, $page, $limit, $PAGE->url);
echo $OUTPUT->header();
echo $OUTPUT->box(
html_writer::tag('p',
html_writer::tag('b',
get_string(
'ghosttotalheader',
'local_cleanup',
[
'files' => $totalitems,
'size' => sprintf('%.3f', $totalsize / pow(1024, 3)),
'cleanup_date' => date(DATE_ISO8601, $task->get_next_run_time()),
]
)
)
)
);
if (count($table->data) !== 0) {
echo html_writer::table($table);
} else {
echo $OUTPUT->notification(get_string('nothingtoshow', 'local_cleanup'), 'notifysuccess');
}
echo $OUTPUT->box($pagination, 'text-center');
echo $OUTPUT->footer();