-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathlib.php
More file actions
144 lines (123 loc) · 4.22 KB
/
lib.php
File metadata and controls
144 lines (123 loc) · 4.22 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?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/>.
/**
* S3 file system lib
*
* @package tool_objectfs
* @author Kenneth Hendricks <kennethhendricks@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use tool_objectfs\local\object_manipulator\manipulator_builder;
define('OBJECTFS_PLUGIN_NAME', 'tool_objectfs');
/**
* Location enum of the object
* ORPHANED is when the {objectfs_objects} table contains a record linking to a
* moodle {files} record which is no longer present.
*/
define('OBJECT_LOCATION_ORPHANED', -2);
/**
* Location enum of the object
* ERROR is when the file is missing when it is expected to be there.
* @see tests/object_file_system_test.php for examples.
*/
define('OBJECT_LOCATION_ERROR', -1);
/**
* Location enum of the object
* LOCAL is when the object exists locally only.
*/
define('OBJECT_LOCATION_LOCAL', 0);
/**
* Location enum of the object
* DUPLICATED is when the object exists both locally, and remotely.
*/
define('OBJECT_LOCATION_DUPLICATED', 1);
/**
* Location enum of the object
* EXTERNAL is when when the object lives remotely only.
*/
define('OBJECT_LOCATION_EXTERNAL', 2);
define('OBJECTFS_REPORT_OBJECT_LOCATION', 0);
define('OBJECTFS_REPORT_LOG_SIZE', 1);
define('OBJECTFS_REPORT_MIME_TYPE', 2);
define('OBJECTFS_BYTES_IN_TERABYTE', 1099511627776);
define('TOOL_OBJECTFS_DELETE_EXTERNAL_NO', 0);
define('TOOL_OBJECTFS_DELETE_EXTERNAL_TRASH', 1);
define('TOOL_OBJECTFS_DELETE_EXTERNAL_FULL', 2);
// Legacy cron function.
function tool_objectfs_cron() {
mtrace('RUNNING legacy cron objectfs');
global $CFG;
if ($CFG->branch <= 26) {
// Unlike the task system, we do not get fine grained control over
// when tasks/manipulators run. Every cron we just run all the manipulators.
(new manipulator_builder())->execute_all();
\tool_objectfs\local\report\objectfs_report::cleanup_reports();
\tool_objectfs\local\report\objectfs_report::generate_status_report();
}
return true;
}
/**
* Sends a plugin file to the browser.
* @param $course
* @param $cm
* @param \context $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @param array $options
* @return bool
* @throws coding_exception
*/
function tool_objectfs_pluginfile($course, $cm, context $context, $filearea, array $args, bool $forcedownload,
array $options = []) {
$fs = get_file_storage();
$file = $fs->get_file($context->id, OBJECTFS_PLUGIN_NAME, $filearea, $args[0], '/', $args[1]);
if (!$file || (is_object($file) && $file->is_directory())) {
send_file_not_found();
}
$lifetime = optional_param('expires', null, PARAM_INT);
\core\session\manager::write_close();
send_stored_file($file, $lifetime, 0, $forcedownload, $options);
return true;
}
/**
* Get status checks for tool_objectfs.
*
* @return array
*/
function tool_objectfs_status_checks() {
if (get_config('tool_objectfs', 'proxyrangerequests')) {
return [
new tool_objectfs\check\proxy_range_request()
];
}
return [];
}
/**
* Convert presigned URLs in $text to the origin URL.
*
* @param string $text The content that may contain ULRs in need of rewriting.
* @param int $contextid This parameter and the next two identify the file area to use.
* @return string The processed text.
*/
function tool_objectfs_file_rewrite_urls($text, $contextid) {
$fs = get_file_storage()->get_file_system();
if (!isset($fs->objectfs)) {
return $text;
}
return $fs->rewrite_pluginfile_urls($text);
}