Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete recordings: Only delete if API call succeeded #593

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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