-
Notifications
You must be signed in to change notification settings - Fork 72
/
lib.php
113 lines (97 loc) · 3.27 KB
/
lib.php
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
<?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);
/**
* Sends a plugin file to the browser.
* @param mixed $course
* @param mixed $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() {
$checks = [
new tool_objectfs\check\token_expiry(),
];
if (get_config('tool_objectfs', 'proxyrangerequests')) {
$checks[] = new tool_objectfs\check\proxy_range_request();
}
return $checks;
}