Skip to content

Commit 74c9175

Browse files
committed
WIP more docs
1 parent 280ae32 commit 74c9175

9 files changed

+246
-58
lines changed

classes/check/tagging_status.php

+26
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
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\check;
418

519
use core\check\check;
620
use core\check\result;
721
use tool_objectfs\local\tag\tag_manager;
822

23+
/**
24+
* Tagging status check
25+
*
26+
* @package tool_objectfs
27+
* @author Matthew Hilton <[email protected]>
28+
* @copyright Catalyst IT
29+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30+
*/
931
class tagging_status extends check {
1032
// TODO action link.
1133

34+
/**
35+
* Get result
36+
* @return result
37+
*/
1238
public function get_result(): result {
1339
if(!tag_manager::is_tagging_enabled_and_supported()) {
1440
return new result(result::NA, 'Not enabled or supported by fs'); // TODO lang.

classes/local/tag/tag_source.php

+37-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
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+
* Tag source interface
21+
*
22+
* @package tool_objectfs
23+
* @author Matthew Hilton <[email protected]>
24+
* @copyright Catalyst IT
25+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
527
interface tag_source {
6-
/**
7-
* Returns an unchanging identifier for this source.
8-
* Must never change, otherwise it will lose connection with the tags replicated to objects.
9-
* If it ever must change, a migration step must be completed to trigger all objects to recalculate their tags.
10-
* Must not exceed 128 chars.
11-
* @return string
12-
*/
13-
public static function get_identifier(): string;
28+
/**
29+
* Returns an unchanging identifier for this source.
30+
* Must never change, otherwise it will lose connection with the tags replicated to objects.
31+
* If it ever must change, a migration step must be completed to trigger all objects to recalculate their tags.
32+
* Must not exceed 128 chars.
33+
* @return string
34+
*/
35+
public static function get_identifier(): string;
1436

15-
/**
16-
* Returns the value of this tag for the file with the given content hash.
17-
* This must be deterministic, and should never exceed 256 chars.
18-
* @param string $contenthash
19-
* @return string
20-
*/
21-
public function get_value_for_contenthash(string $contenthash): ?string;
37+
/**
38+
* Returns the value of this tag for the file with the given content hash.
39+
* This must be deterministic, and should never exceed 256 chars.
40+
* @param string $contenthash
41+
* @return string
42+
*/
43+
public function get_value_for_contenthash(string $contenthash): ?string;
2244
}
+48-19
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,61 @@
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\task;
418

519
use core\task\manager;
620
use core\task\scheduled_task;
721
use tool_objectfs\local\tag\tag_manager;
822

23+
/**
24+
* Queues objects needing tag syncing for tag syncing using an adhoc task.
25+
*
26+
* @package tool_objectfs
27+
* @author Matthew Hilton <[email protected]>
28+
* @copyright Catalyst IT
29+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30+
*/
931
class queue_objects_needing_tags extends scheduled_task {
10-
public function get_name() {
11-
return get_string('task:queueobjectsneedingtags', 'tool_objectfs');
12-
}
32+
/**
33+
* Get name
34+
* @return string
35+
*/
36+
public function get_name() {
37+
return get_string('task:queueobjectsneedingtags', 'tool_objectfs');
38+
}
1339

14-
public function execute() {
15-
if (!tag_manager::is_tagging_enabled_and_supported()) {
16-
mtrace("Tagging feature not available or supported, ignoring.");
17-
return;
18-
}
40+
/**
41+
* Execute task
42+
*/
43+
public function execute() {
44+
if (!tag_manager::is_tagging_enabled_and_supported()) {
45+
mtrace("Tagging feature not available or supported, ignoring.");
46+
return;
47+
}
1948

20-
// TODO configurable limit per run.
21-
$contenthashes = tag_manager::get_objects_needing_sync(1000);
22-
mtrace("Found " . count($contenthashes) . " objects needing tag sync");
49+
// TODO configurable limit per run.
50+
$contenthashes = tag_manager::get_objects_needing_sync(1000);
51+
mtrace("Found " . count($contenthashes) . " objects needing tag sync");
2352

24-
foreach ($contenthashes as $contenthash) {
25-
$task = new update_object_tags();
26-
$task->set_custom_data([
27-
'contenthash' => $contenthash
28-
]);
29-
manager::queue_adhoc_task($task, true);
30-
}
31-
}
53+
foreach ($contenthashes as $contenthash) {
54+
$task = new update_object_tags();
55+
$task->set_custom_data([
56+
'contenthash' => $contenthash
57+
]);
58+
manager::queue_adhoc_task($task, true);
59+
}
60+
}
3261
}

classes/task/update_object_tags.php

+40-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
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\task;
418

519
use core\task\adhoc_task;
620
use tool_objectfs\local\tag\tag_manager;
721

22+
/**
23+
* Calculates and updates an objects tags in the external store.
24+
*
25+
* @package tool_objectfs
26+
* @author Matthew Hilton <[email protected]>
27+
* @copyright Catalyst IT
28+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
*/
830
class update_object_tags extends adhoc_task {
9-
public function execute() {
10-
if (!tag_manager::is_tagging_enabled_and_supported()) {
11-
mtrace("Tagging feature not enabled or supported by filesystem, exiting early.");
12-
return;
13-
}
31+
/**
32+
* Execute task
33+
*/
34+
public function execute() {
35+
if (!tag_manager::is_tagging_enabled_and_supported()) {
36+
mtrace("Tagging feature not enabled or supported by filesystem, exiting early.");
37+
return;
38+
}
1439

15-
// Find the object from the customdata.
16-
$contenthash = $this->get_custom_data()->contenthash ?? null;
40+
// Find the object from the customdata.
41+
$contenthash = $this->get_custom_data()->contenthash ?? null;
1742

18-
if (empty($contenthash)) {
19-
mtrace("No content hash given, invalid customdata, exiting");
20-
return;
21-
}
43+
if (empty($contenthash)) {
44+
mtrace("No content hash given, invalid customdata, exiting");
45+
return;
46+
}
2247

23-
tag_manager::update_tags_if_necessary($contenthash);
24-
// TODO if this fails because of 404, just ignore since file is clearly not replicated yet
25-
tag_manager::replicate_local_to_external_tags_for_object($contenthash);
26-
}
48+
tag_manager::update_tags_if_necessary($contenthash);
49+
// TODO if this fails because of 404, just ignore since file is clearly not replicated yet
50+
tag_manager::replicate_local_to_external_tags_for_object($contenthash);
51+
}
2752
}

classes/tests/test_client.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,13 @@ public function get_maximum_upload_size() {
158158
return $this->maxupload;
159159
}
160160

161-
public function supports_object_tagging(): bool {
162-
global $CFG;
163-
return $CFG->phpunit_objectfs_supports_object_tagging;
164-
}
161+
/**
162+
* Object tagging support, for unit testing
163+
* @return bool
164+
*/
165+
public function supports_object_tagging(): bool {
166+
global $CFG;
167+
return $CFG->phpunit_objectfs_supports_object_tagging;
168+
}
165169
}
166170

db/upgrade.php

+2
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,7 @@ function xmldb_tool_objectfs_upgrade($oldversion) {
171171
upgrade_plugin_savepoint(true, 2023013100, 'tool', 'objectfs');
172172
}
173173

174+
// TODO db update step for db.
175+
174176
return true;
175177
}

lib.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ function tool_objectfs_pluginfile($course, $cm, context $context, $filearea, arr
121121
* @return array
122122
*/
123123
function tool_objectfs_status_checks() {
124-
$checks = [
125-
new tool_objectfs\check\tagging_status(),
126-
];
124+
$checks = [
125+
new tool_objectfs\check\tagging_status(),
126+
];
127127

128128
if (get_config('tool_objectfs', 'proxyrangerequests')) {
129-
$checks[] = new tool_objectfs\check\proxy_range_request();
129+
$checks[] = new tool_objectfs\check\proxy_range_request();
130130
}
131131

132132
return $checks;

settings.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@
250250
$settings->add(new admin_setting_configcheckbox('tool_objectfs/preferexternal',
251251
new lang_string('settings:preferexternal', 'tool_objectfs'), '', ''));
252252

253-
$settings->add(new admin_setting_heading('tool_objectfs/taggingsettings',
253+
$settings->add(new admin_setting_heading('tool_objectfs/taggingsettings',
254254
new lang_string('settings:taggingheader', 'tool_objectfs'), ''));
255+
256+
// TODO some info here about tagging, maybe a link to doc in git.
255257

256258
$settings->add(new admin_setting_configcheckbox('tool_objectfs/taggingenabled',
257259
new lang_string('settings:taggingenabled', 'tool_objectfs'), '', ''));

0 commit comments

Comments
 (0)