diff --git a/mod/bigbluebuttonbn/classes/local/proxy/recording_proxy.php b/mod/bigbluebuttonbn/classes/local/proxy/recording_proxy.php index 777f277badd21..aaef2aeff9591 100644 --- a/mod/bigbluebuttonbn/classes/local/proxy/recording_proxy.php +++ b/mod/bigbluebuttonbn/classes/local/proxy/recording_proxy.php @@ -193,6 +193,31 @@ public static function fetch_recordings(array $keyids = []): array { return $recordings; } + /** + * Helper function to retrieve recordings that failed to be fetched from a BigBlueButton server. + * + * @param array $keyids list of recordingids + * @return array array of recording recordingids not fetched from server + * and sorted by {@see recording_proxy::sort_recordings} + */ + public static function fetch_missing_recordings(array $keyids = []): array { + $unfetchedids = []; + $pagesize = 25; + // If $ids is empty return array() to prevent a getRecordings with meetingID and recordID set to ''. + if (empty($keyids)) { + return $unfetchedids; + } + while ($ids = array_splice($keyids, 0, $pagesize)) { + // We make getRecordings API call to check recordings are successfully retrieved. + $xml = self::fetch_endpoint_xml('getRecordings', ['recordID' => implode(',', $ids), 'state' => 'any']); + if (!$xml || $xml->returncode != 'SUCCESS' || !isset($xml->recordings)) { + $unfetchedids = array_merge($unfetchedids, $ids); + continue; // We will keep record of all unfetched ids. + } + } + return $unfetchedids; + } + /** * Helper function to fetch recordings from a BigBlueButton server. * diff --git a/mod/bigbluebuttonbn/classes/recording.php b/mod/bigbluebuttonbn/classes/recording.php index d0565a824267c..0f40fb620718e 100644 --- a/mod/bigbluebuttonbn/classes/recording.php +++ b/mod/bigbluebuttonbn/classes/recording.php @@ -714,13 +714,14 @@ protected static function fetch_records(array $selects, array $params): array { // Fetch all metadata for these recordings. $metadatas = recording_proxy::fetch_recordings($recordingids); + $failedids = recording_proxy::fetch_missing_recordings($recordingids); // Return the instances. - return array_filter(array_map(function ($recording) use ($metadatas, $withindays) { + return array_filter(array_map(function ($recording) use ($metadatas, $withindays, $failedids) { // Filter out if no metadata was fetched. if (!array_key_exists($recording->recordingid, $metadatas)) { - // Mark it as dismissed if it is older than 30 days. - if ($withindays > $recording->timecreated) { + // If the recording was successfully fetched, mark it as dismissed if it is older than 30 days. + if (!in_array($recording->recordingid, $failedids) && $withindays > $recording->timecreated) { $recording = new self(0, $recording, null); $recording->set_status(self::RECORDING_STATUS_DISMISSED); }