Skip to content

Commit

Permalink
bugfix: fix mysql query compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Aug 20, 2024
1 parent d0f301b commit 87327fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion classes/check/tagging_sync_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function get_result(): result {
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]) ? $statuses[$status]->count : 0;
$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);
Expand Down
2 changes: 1 addition & 1 deletion classes/local/tag/tag_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static function get_sync_status_string(int $tagsyncstatus): string {
*/
public static function get_tag_sync_status_summary(): array {
global $DB;
return $DB->get_records_sql("SELECT tagsyncstatus, COUNT(tagsyncstatus)
return $DB->get_records_sql("SELECT tagsyncstatus, COUNT(tagsyncstatus) as statuscount
FROM {tool_objectfs_objects}
GROUP BY tagsyncstatus");
}
Expand Down
15 changes: 9 additions & 6 deletions tests/local/tagging_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,22 @@ public function test_get_tag_sync_status_summary() {
$DB->delete_records('tool_objectfs_objects');

// Create an object with each status.
$object1 = $this->create_remote_object('test1');
$object2 = $this->create_remote_object('test2');
$object3 = $this->create_remote_object('test3');
$object1 = $this->create_local_object('test1');
$object2 = $this->create_local_object('test2');
$object3 = $this->create_local_object('test3');

// Delete the unit test object that is automatically created, it has a filesize of zero.
$DB->delete_records('tool_objectfs_objects', ['filesize' => 0]);

tag_manager::mark_object_tag_sync_status($object1->contenthash, tag_manager::SYNC_STATUS_COMPLETE);
tag_manager::mark_object_tag_sync_status($object2->contenthash, tag_manager::SYNC_STATUS_ERROR);
tag_manager::mark_object_tag_sync_status($object3->contenthash, tag_manager::SYNC_STATUS_NEEDS_SYNC);

// Ensure correctly counted.
$statuses = tag_manager::get_tag_sync_status_summary();
$this->assertEquals(1, $statuses[tag_manager::SYNC_STATUS_COMPLETE]->count);
$this->assertEquals(1, $statuses[tag_manager::SYNC_STATUS_ERROR]->count);
$this->assertEquals(1, $statuses[tag_manager::SYNC_STATUS_NEEDS_SYNC]->count);
$this->assertEquals(1, $statuses[tag_manager::SYNC_STATUS_COMPLETE]->statuscount);
$this->assertEquals(1, $statuses[tag_manager::SYNC_STATUS_ERROR]->statuscount);
$this->assertEquals(1, $statuses[tag_manager::SYNC_STATUS_NEEDS_SYNC]->statuscount);
}

/**
Expand Down

0 comments on commit 87327fc

Please sign in to comment.