Skip to content

Commit

Permalink
refactor: get object tag sync status count details separately
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Oct 22, 2024
1 parent 840cd1a commit 664c4aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
28 changes: 7 additions & 21 deletions classes/check/tagging_sync_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

use core\check\check;
use core\check\result;
use html_table;
use html_writer;
use tool_objectfs\local\tag\tag_manager;
use tool_objectfs\local\tag_sync_count_result;

/**
* Tagging sync status check
Expand All @@ -47,28 +46,15 @@ public function get_action_link(): ?\action_link {
*/
public function get_result(): result {
if (!tag_manager::is_tagging_enabled_and_supported()) {
return new result(result::NA, get_string('check:tagging:na', 'tool_objectfs'));
return new tag_sync_count_result(result::WARNING, get_string('check:tagging:na', 'tool_objectfs'));
}

$statuses = tag_manager::get_tag_sync_status_summary();
$table = new html_table();
$table->head = [
get_string('table:status', 'tool_objectfs'),
get_string('table:objectcount', 'tool_objectfs'),
];

foreach (tag_manager::SYNC_STATUSES as $status) {
// If no objects have a status, they won't appear in the SQL above.
// In this case, just show zero (so the use knows it exists, but is zero).
$count = isset($statuses[$status]->statuscount) ? $statuses[$status]->statuscount : 0;
$table->data[$status] = [tag_manager::get_sync_status_string($status), $count];
}
$table = html_writer::table($table);

if (!empty($statuses[tag_manager::SYNC_STATUS_ERROR])) {
return new result(result::WARNING, get_string('check:tagging:syncerror', 'tool_objectfs'), $table);
// We only do a lightweight check here, the get_details is overwritten in tag_sync_status_result
// to provide more information that is more computationally expensive to calculate.
if (tag_manager::tag_sync_errors_exist()) {
return new tag_sync_count_result(result::WARNING, get_string('check:tagging:syncerror', 'tool_objectfs'));
}

return new result(result::OK, get_string('check:tagging:syncok', 'tool_objectfs'), $table);
return new tag_sync_count_result(result::OK, get_string('check:tagging:syncok', 'tool_objectfs'));
}
}
10 changes: 10 additions & 0 deletions classes/local/tag/tag_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public static function get_sync_status_string(int $tagsyncstatus): string {

/**
* Returns a summary of the object tag sync statuses.
* Note on larger sites, this can be quite computationally difficult and should be used carefully.
* @return array
*/
public static function get_tag_sync_status_summary(): array {
Expand All @@ -230,4 +231,13 @@ public static function get_tag_sync_status_summary(): array {
FROM {tool_objectfs_objects}
GROUP BY tagsyncstatus");
}

/**
* This is a lightweight check to just check if any objects are reporting tag sync errors.
* @return bool
*/
public static function tag_sync_errors_exist(): bool {
global $DB;
return $DB->record_exists('tool_objectfs_objects', ['tagsyncstatus' => self::SYNC_STATUS_ERROR]);
}
}

0 comments on commit 664c4aa

Please sign in to comment.