Skip to content

Commit 2b0ee43

Browse files
committed
WIP more tagging stuff
1 parent 9ac34ae commit 2b0ee43

File tree

4 files changed

+83
-7
lines changed

4 files changed

+83
-7
lines changed

classes/check/tagging_status.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace tool_objectfs\check;
4+
5+
use core\check\check;
6+
use core\check\result;
7+
use tool_objectfs\local\tag\tag_manager;
8+
9+
class tagging_status extends check {
10+
// TODO action link.
11+
12+
public function get_result(): result {
13+
if(!tag_manager::is_tagging_enabled_and_supported()) {
14+
return new result(result::NA, 'Not enabled or supported by fs'); // TODO lang.
15+
}
16+
17+
// Do a tag set test.
18+
$config = \tool_objectfs\local\manager::get_objectfs_config();
19+
$client = \tool_objectfs\local\manager::get_client($config);
20+
$result = $client->test_set_object_tag();
21+
22+
if ($result->success) {
23+
// TODO lang.
24+
return new result(result::OK, 'tagging success', $result->details);
25+
} else {
26+
// TODO lang.
27+
return new result(result::ERROR, 'tagging failed', $result->details);
28+
}
29+
}
30+
}

classes/local/manager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static function get_objectfs_config() {
6464
$config->batchsize = 10000;
6565
$config->useproxy = 0;
6666
$config->deleteexternal = 0;
67-
$config->enabletagging = false;
67+
$config->enabletagging = false;
6868

6969
$config->filesystem = '';
7070
$config->enablepresignedurls = 0;

classes/local/store/s3/client.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ public function test_set_object_tag() {
403403
'Body' => 'test content'
404404
]);
405405

406-
// Next try to tag it.
407-
$res = $this->client->putObjectTagging([
406+
// Next try to tag it - this will throw an exception if cannot set
407+
// (for example, because it does not have permissions to).
408+
$this->client->putObjectTagging([
408409
'Bucket' => $this->bucket,
409410
'Key' => $key,
410411
'Tagging' => [
+49-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,63 @@
11
<?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/>.
216

317
namespace tool_objectfs\local\tag;
418

19+
/**
20+
* File type tag source.
21+
* Provides tag values for files based on their 'type' - these are categories (not necessarily equivalent to fileareas)
22+
* that make it possible to apply different permissions to. For example, move backups to a cheaper storage class but not general files.
23+
*
24+
* @package tool_objectfs
25+
* @author Matthew Hilton <[email protected]>
26+
* @copyright Catalyst IT
27+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28+
*/
529
class file_type_source implements tag_source {
6-
public const TYPE_STANDARD = 'standard';
30+
/**
31+
* @var string Unknown/uncategorised
32+
*/
33+
public const TYPE_UNCATEGORISED = 'uncategorised';
734

8-
public const TYPE_BACKUP = 'backup';
35+
/**
36+
* @var string A course backup
37+
*/
38+
public const TYPE_COURSE_BACKUP = 'course_backup';
939

40+
/**
41+
* Identifier used in tagging file. Is the 'key' of the tag.
42+
* @return string
43+
*/
1044
public static function get_identifier(): string {
1145
return 'type';
1246
}
1347

48+
/**
49+
* Returns the tag value for the given file contenthash
50+
* @param string $contenthash
51+
* @return string|null the category of the file, one of TYPE_*
52+
*/
1453
public function get_value_for_contenthash(string $contenthash): ?string {
15-
// TODO implement types e.g. is backup, etc..
16-
return self::TYPE_STANDARD;
54+
global $DB;
55+
// TODO are there other unknown course backup files ?
56+
$iscoursebackup = $DB->record_exists('files', ['contenthash' => $contenthash, 'component' => 'backup', 'filearea' => 'course']);
57+
if ($iscoursebackup) {
58+
return self::TYPE_COURSE_BACKUP;
59+
}
60+
61+
return self::TYPE_UNCATEGORISED;
1762
}
1863
}

0 commit comments

Comments
 (0)