Skip to content

Commit

Permalink
delete recordings: Only delete if API call succeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchamp committed May 2, 2024
1 parent e2f6f7b commit ca0cd5e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
28 changes: 16 additions & 12 deletions classes/task/delete_meeting_recordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,24 @@ public function execute() {
// Get all recordings stored in Moodle, grouped by meetinguuid.
$zoomrecordings = zoom_get_meeting_recordings_grouped();
foreach ($zoomrecordings as $meetinguuid => $recordings) {
// Now check which recordings still exist on Zoom.
$recordinglist = $service->get_recording_url_list($meetinguuid);
foreach ($recordinglist as $recordinginfo) {
$zoomrecordingid = trim($recordinginfo->recordingid);
if (isset($recordings[$zoomrecordingid])) {
mtrace('Recording id: ' . $zoomrecordingid . ' exist(s)...skipping');
unset($recordings[$zoomrecordingid]);
try {
// Now check which recordings still exist on Zoom.
$recordinglist = $service->get_recording_url_list($meetinguuid);
foreach ($recordinglist as $recordinginfo) {
$zoomrecordingid = trim($recordinginfo->recordingid);
if (isset($recordings[$zoomrecordingid])) {
mtrace('Recording id: ' . $zoomrecordingid . ' exist(s)...skipping');
unset($recordings[$zoomrecordingid]);
}
}
}

// If recordings are in Moodle but not in Zoom, we need to remove them from Moodle as well.
foreach ($recordings as $zoomrecordingid => $recording) {
mtrace('Deleting recording with id: ' . $zoomrecordingid . ' as corresponding record on zoom has been removed.');
$DB->delete_records('zoom_meeting_recordings', ['zoomrecordingid' => $zoomrecordingid]);
// If recordings are in Moodle but not in Zoom, we need to remove them from Moodle as well.
foreach ($recordings as $zoomrecordingid => $recording) {
mtrace('Deleting recording with id: ' . $zoomrecordingid . ' because the recording is no longer in Zoom.');
$DB->delete_records('zoom_meeting_recordings', ['zoomrecordingid' => $zoomrecordingid]);
}
} catch (moodle_exception $e) {
mtrace('Exception occurred: ' . $e->getMessage());
}
}
}
Expand Down
42 changes: 19 additions & 23 deletions classes/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ public function encode_uuid($uuid) {
*
* @param string $meetingid The string meeting UUID.
* @return array Returns the list of recording URLs and the type of recording that is being sent back.
* @throws moodle_exception
*/
public function get_recording_url_list($meetingid) {
$recordings = [];
Expand All @@ -1055,32 +1056,27 @@ public function get_recording_url_list($meetingid) {
'CC' => 'captions',
];

try {
// Classic: recording:read:admin.
// Granular: cloud_recording:read:list_recording_files:admin.
$url = 'meetings/' . $this->encode_uuid($meetingid) . '/recordings';
$response = $this->make_call($url);

if (!empty($response->recording_files)) {
foreach ($response->recording_files as $recording) {
$url = $recording->play_url ?? $recording->download_url ?? null;
if (!empty($url) && isset($allowedrecordingtypes[$recording->file_type])) {
$recordinginfo = new stdClass();
$recordinginfo->recordingid = $recording->id;
$recordinginfo->meetinguuid = $response->uuid;
$recordinginfo->url = $url;
$recordinginfo->filetype = $recording->file_type;
$recordinginfo->recordingtype = $recording->recording_type;
$recordinginfo->passcode = $response->password;
$recordinginfo->recordingstart = strtotime($recording->recording_start);
// Classic: recording:read:admin.
// Granular: cloud_recording:read:list_recording_files:admin.
$url = 'meetings/' . $this->encode_uuid($meetingid) . '/recordings';
$response = $this->make_call($url);

$recordings[$recording->id] = $recordinginfo;
}
if (!empty($response->recording_files)) {
foreach ($response->recording_files as $recording) {
$url = $recording->play_url ?? $recording->download_url ?? null;
if (!empty($url) && isset($allowedrecordingtypes[$recording->file_type])) {
$recordinginfo = new stdClass();
$recordinginfo->recordingid = $recording->id;
$recordinginfo->meetinguuid = $response->uuid;
$recordinginfo->url = $url;
$recordinginfo->filetype = $recording->file_type;
$recordinginfo->recordingtype = $recording->recording_type;
$recordinginfo->passcode = $response->password;
$recordinginfo->recordingstart = strtotime($recording->recording_start);

$recordings[$recording->id] = $recordinginfo;
}
}
} catch (moodle_exception $error) {
// No recordings found for this meeting id.
$recordings = [];
}

return $recordings;
Expand Down

0 comments on commit ca0cd5e

Please sign in to comment.