Skip to content

Commit 280ae32

Browse files
committed
WIP docs
1 parent 2b0ee43 commit 280ae32

8 files changed

+377
-272
lines changed

classes/local/manager.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ public static function get_available_fs_list() {
330330
* @return string
331331
*/
332332
public static function get_client_classname_from_fs($filesystem) {
333-
// Unit tests.
334-
if($filesystem == '\tool_objectfs\tests\test_file_system') {
335-
return '\tool_objectfs\tests\test_client';
336-
}
333+
// Unit tests need to return the test client.
334+
if($filesystem == '\tool_objectfs\tests\test_file_system') {
335+
return '\tool_objectfs\tests\test_client';
336+
}
337337
$clientclass = str_replace('_file_system', '', $filesystem);
338338
return str_replace('tool_objectfs\\', 'tool_objectfs\\local\\store\\', $clientclass.'\\client');
339339
}

classes/local/store/object_client.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
namespace tool_objectfs\local\store;
2727

28+
use stdClass;
29+
2830
interface object_client {
2931

3032
/**
@@ -120,8 +122,6 @@ public function test_connection();
120122
*/
121123
public function test_permissions($testdelete);
122124

123-
public function test_set_object_tag();
124-
125125
/**
126126
* proxy_range_request
127127
* @param \stored_file $file
@@ -139,10 +139,24 @@ public function proxy_range_request(\stored_file $file, $ranges);
139139
*/
140140
public function test_range_request($filesystem);
141141

142-
public function set_object_tags(string $contenthash, array $tags);
142+
/**
143+
* Tests setting an objects tag.
144+
* @return stdClass containing 'success' and 'details' properties
145+
*/
146+
public function test_set_object_tag(): stdClass;
143147

144-
public function supports_object_tagging(): bool;
148+
/**
149+
* Set the given objects tags in the external store.
150+
* @param string $contenthash file content hash
151+
* @param array $tags array of key=>value pairs to set as tags.
152+
*/
153+
public function set_object_tags(string $contenthash, array $tags);
145154

155+
/**
156+
* If the client supports object tagging feature.
157+
* @return bool true if supports, else false
158+
*/
159+
public function supports_object_tagging(): bool;
146160
}
147161

148162

classes/local/store/object_client_base.php

+24-9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
namespace tool_objectfs\local\store;
2727

28+
use stdClass;
29+
2830
/**
2931
* [Description object_client_base]
3032
*/
@@ -188,15 +190,28 @@ public function test_permissions($testdelete) {
188190
return (object)['success' => false, 'details' => ''];
189191
}
190192

191-
public function test_set_object_tag() {
192-
return (object)['success' => false, 'details' => ''];
193-
}
193+
/**
194+
* Tests setting an objects tag.
195+
* @return stdClass containing 'success' and 'details' properties
196+
*/
197+
public function test_set_object_tag(): stdClass {
198+
return (object)['success' => false, 'details' => ''];
199+
}
194200

195-
public function set_object_tags(string $contenthash, array $tags) {
196-
return;
197-
}
201+
/**
202+
* Set the given objects tags in the external store.
203+
* @param string $contenthash file content hash
204+
* @param array $tags array of key=>value pairs to set as tags.
205+
*/
206+
public function set_object_tags(string $contenthash, array $tags) {
207+
return;
208+
}
198209

199-
public function supports_object_tagging(): bool {
200-
return false;
201-
}
210+
/**
211+
* If the client supports object tagging feature.
212+
* @return bool true if supports, else false
213+
*/
214+
public function supports_object_tagging(): bool {
215+
return false;
216+
}
202217
}

classes/local/store/object_file_system.php

-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ public function copy_object_from_local_to_external_by_hash($contenthash, $object
354354

355355
if ($initiallocation === OBJECT_LOCATION_LOCAL) {
356356
$success = $this->copy_from_local_to_external($contenthash);
357-
358357
if ($success) {
359358
$finallocation = OBJECT_LOCATION_DUPLICATED;
360359
}

classes/local/store/s3/client.php

+77-62
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use tool_objectfs\local\store\object_client_base;
3030
use tool_objectfs\local\store\signed_url;
3131
use local_aws\admin_settings_aws_region;
32+
use stdClass;
3233
use Throwable;
3334

3435
define('AWS_API_VERSION', '2006-03-01');
@@ -391,42 +392,6 @@ public function test_permissions($testdelete) {
391392
return $permissions;
392393
}
393394

394-
public function test_set_object_tag() {
395-
try {
396-
// First ensure a test object exists to put tags on.
397-
// Note this will override the existing object if exists.
398-
$key = $this->bucketkeyprefix . 'tagging_check_file';
399-
400-
$this->client->putObject([
401-
'Bucket' => $this->bucket,
402-
'Key' => $key,
403-
'Body' => 'test content'
404-
]);
405-
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([
409-
'Bucket' => $this->bucket,
410-
'Key' => $key,
411-
'Tagging' => [
412-
'TagSet' => [
413-
[
414-
'Key' => 'test',
415-
'Value' => 'test',
416-
]
417-
]
418-
]
419-
]);
420-
} catch (Throwable $e) {
421-
return (object) [
422-
'success' => false,
423-
'details' => $e->getMessage(),
424-
];
425-
}
426-
427-
// Success - no exceptions thrown.
428-
return (object) ['success' => true, 'details' => ''];
429-
}
430395

431396
/**
432397
* get_exception_details
@@ -905,30 +870,80 @@ public function test_range_request($filesystem) {
905870
return (object)['result' => false, 'error' => get_string('fixturefilemissing', 'tool_objectfs')];
906871
}
907872

908-
public function set_object_tags(string $contenthash, array $tags) {
909-
// First convert PHP array tags to XML string.
910-
$s3tags = [];
911-
912-
foreach($tags as $key => $value) {
913-
$s3tags[] = [
914-
'Key' => $key,
915-
'Value' => $value,
916-
];
917-
}
918-
919-
$key = $this->bucketkeyprefix . $this->get_filepath_from_hash($contenthash);
920-
921-
// Then put onto object.
922-
$this->client->putObjectTagging([
923-
'Bucket' => $this->bucket,
924-
'Key' => $key,
925-
'Tagging' => [
926-
'TagSet' => $s3tags
927-
]
928-
]);
929-
}
930-
931-
public function supports_object_tagging(): bool {
932-
return true;
933-
}
873+
/**
874+
* Tests setting an objects tag.
875+
* @return stdClass containing 'success' and 'details' properties
876+
*/
877+
public function test_set_object_tag(): stdClass {
878+
try {
879+
// First ensure a test object exists to put tags on.
880+
// Note this will override the existing object if exists.
881+
$key = $this->bucketkeyprefix . 'tagging_check_file';
882+
883+
$this->client->putObject([
884+
'Bucket' => $this->bucket,
885+
'Key' => $key,
886+
'Body' => 'test content'
887+
]);
888+
889+
// Next try to tag it - this will throw an exception if cannot set
890+
// (for example, because it does not have permissions to).
891+
$this->client->putObjectTagging([
892+
'Bucket' => $this->bucket,
893+
'Key' => $key,
894+
'Tagging' => [
895+
'TagSet' => [
896+
[
897+
'Key' => 'test',
898+
'Value' => 'test',
899+
]
900+
]
901+
]
902+
]);
903+
} catch (Throwable $e) {
904+
return (object) [
905+
'success' => false,
906+
'details' => $e->getMessage(),
907+
];
908+
}
909+
910+
// Success - no exceptions thrown.
911+
return (object) ['success' => true, 'details' => ''];
912+
}
913+
914+
/**
915+
* Set the given objects tags in the external store.
916+
* @param string $contenthash file content hash
917+
* @param array $tags array of key=>value pairs to set as tags.
918+
*/
919+
public function set_object_tags(string $contenthash, array $tags) {
920+
// First convert PHP array tags to XML string.
921+
$s3tags = [];
922+
923+
foreach($tags as $key => $value) {
924+
$s3tags[] = [
925+
'Key' => $key,
926+
'Value' => $value,
927+
];
928+
}
929+
930+
$key = $this->bucketkeyprefix . $this->get_filepath_from_hash($contenthash);
931+
932+
// Then put onto object.
933+
$this->client->putObjectTagging([
934+
'Bucket' => $this->bucket,
935+
'Key' => $key,
936+
'Tagging' => [
937+
'TagSet' => $s3tags
938+
]
939+
]);
940+
}
941+
942+
/**
943+
* If the client supports object tagging feature.
944+
* @return bool true if supports, else false
945+
*/
946+
public function supports_object_tagging(): bool {
947+
return true;
948+
}
934949
}

classes/local/store/s3/file_system.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function copy_from_local_to_external($contenthash) {
9696
return false;
9797
}
9898
}
99-
99+
100100
/**
101101
* supports_presigned_urls
102102
* @return bool

classes/local/tag/file_type_source.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,34 @@ class file_type_source implements tag_source {
3030
/**
3131
* @var string Unknown/uncategorised
3232
*/
33-
public const TYPE_UNCATEGORISED = 'uncategorised';
33+
public const TYPE_UNCATEGORISED = 'uncategorised';
3434

3535
/**
3636
* @var string A course backup
3737
*/
38-
public const TYPE_COURSE_BACKUP = 'course_backup';
38+
public const TYPE_COURSE_BACKUP = 'course_backup';
3939

4040
/**
4141
* Identifier used in tagging file. Is the 'key' of the tag.
4242
* @return string
4343
*/
44-
public static function get_identifier(): string {
45-
return 'type';
46-
}
44+
public static function get_identifier(): string {
45+
return 'type';
46+
}
4747

4848
/**
4949
* Returns the tag value for the given file contenthash
5050
* @param string $contenthash
5151
* @return string|null the category of the file, one of TYPE_*
5252
*/
53-
public function get_value_for_contenthash(string $contenthash): ?string {
53+
public function get_value_for_contenthash(string $contenthash): ?string {
5454
global $DB;
5555
// TODO are there other unknown course backup files ?
5656
$iscoursebackup = $DB->record_exists('files', ['contenthash' => $contenthash, 'component' => 'backup', 'filearea' => 'course']);
5757
if ($iscoursebackup) {
5858
return self::TYPE_COURSE_BACKUP;
5959
}
6060

61-
return self::TYPE_UNCATEGORISED;
62-
}
61+
return self::TYPE_UNCATEGORISED;
62+
}
6363
}

0 commit comments

Comments
 (0)