Skip to content

Commit

Permalink
MDL-74468 mod_bigbluebuttonbn: Fix logger count method
Browse files Browse the repository at this point in the history
* The logger::count_callback_events was confusing and needs clarification
and small refactoring.
  • Loading branch information
laurentdavid committed Nov 4, 2022
1 parent f75aed1 commit 79153d9
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions mod/bigbluebuttonbn/classes/logger.php
Expand Up @@ -447,21 +447,30 @@ protected static function log_moodle_event(instance $instance, string $type, arr
*/
protected static function count_callback_events(string $id, string $callbacktype = 'recording_ready'): int {
global $DB;
$sql = 'SELECT count(DISTINCT id) FROM {bigbluebuttonbn_logs} WHERE log = ? AND meta LIKE ? AND meta LIKE ?';
// Callback type added on version 2.4, validate recording_ready first or assume it on records with no callback.
if ($callbacktype == 'recording_ready') {
$sql .= ' AND (meta LIKE ? OR meta NOT LIKE ? )';
$count =
$DB->count_records_sql($sql, [
self::EVENT_CALLBACK, '%recordid%',
"%$id%",
$callbacktype, 'callback'
]);
return $count;
// Look for a log record that is of "Callback" type and is related to the given event.
$conditions = [
"log = :logtype",
$DB->sql_like('meta', ':cbtypelike')
];

$params = [
'logtype' => self::EVENT_CALLBACK,
'cbtypelike' => "%meeting_events%" // All callbacks are meeting events, even recording events.
];

$basesql = 'SELECT COUNT(DISTINCT id) FROM {bigbluebuttonbn_logs}';
switch ($callbacktype) {
case 'recording_ready':
$conditions[] = $DB->sql_like('meta', ':isrecordid');
$params['isrecordid'] = '%recordid%'; // The recordid field in the meta field (json encoded).
break;
case 'meeting_events':
$conditions[] = $DB->sql_like('meta', ':idlike');
$params['idlike'] = "%$id%"; // The unique id of the meeting is the meta field (json encoded).
break;
}
$count = $DB->count_records_sql($sql,
[self::EVENT_CALLBACK, "%$id%", "%$callbacktype%"]);
return $count;
$wheresql = join(' AND ', $conditions);
return $DB->count_records_sql($basesql . ' WHERE ' . $wheresql, $params);
}

/**
Expand Down

0 comments on commit 79153d9

Please sign in to comment.