if (!($context = context_module::instance($cm->id))) { print_error('badcontext', null, $return_course); } $allclips = []; $sc_obj = new mod_opencast_series(); $sc_obj->fetch($opencast->id, true); $sc_user = new mod_opencast_user(); $arr_filter = []; $filters = explode('&', urldecode($filterstr)); foreach ($filters as $filter) { $parts = explode('=', $filter); if (count($parts) == 2) { $arr_filter[$parts[0]] = $parts[1]; } } $xml_clips = $sc_obj->getEvents($arr_filter); $xml_clips_access_allowed = $sc_obj->checkAccess($xml_clips); $clips = []; foreach ($xml_clips_access_allowed as $xml_clip) { $clips[] = (array) $xml_clip; } if (mod_opencast_series::getValueForKey('display_select_columns')) { $xml_all_clips = $sc_obj->getEvents(); $xml_all_clips_access_allowed = $sc_obj->checkAccess($xml_all_clips); $all_clips = []; foreach ($xml_all_clips_access_allowed as $xml_all_clip) { $all_clips[] = (array) $xml_all_clip; } } $clip_objs = []; foreach ($clips as $clip) {
/** * @return array * @throws coding_exception */ public static function processUploadedClips() { global $CFG, $DB; $admin = get_admin(); $opencasts = $DB->get_records('opencast'); // first, some maintenance: delete stale records (e.g. if an error occured at SCast) $staletime = time() - OPENCAST_STALE_PERIOD; $stale_records = $DB->get_records_select('opencast_uploadedclip', 'status = ' . OPENCAST_CLIP_UPLOADED . ' AND timestamp < ' . $staletime); foreach ($stale_records as $stale_record) { $user_stale = $DB->get_record('user', ['id' => $stale_record->userid]); if ($user_stale) { // notify uploader $a_s = new stdClass(); $a_s->filename = $stale_record->filename; $cm_s = get_coursemodule_from_instance('opencast', $stale_record->opencastid); $a_s->link = $CFG->wwwroot . '/mod/opencast/view.php?id=' . $cm_s->id; email_to_user($user_stale, $admin, get_string('clipstale_subject', 'opencast'), get_string('clipstale_body', 'opencast', $a_s)); // notify admin too $a_s->userlink = $CFG->wwwroot . '/user/profile.php?id=' . $user_stale->id; $a_s->userfullname = fullname($user_stale); email_to_user($admin, $admin, get_string('clipstale_subject_admin', 'opencast'), get_string('clipstale_body_admin', 'opencast', $a_s)); } } $DB->delete_records_select('opencast_uploadedclip', 'status = ' . OPENCAST_CLIP_UPLOADED . ' AND timestamp < ' . $staletime); // now, let's deal with the remaining ones, checking one by one if they have been processed $pending = []; $uploaded = []; foreach ($opencasts as $opencast) { $uploaded_videos = $DB->get_records('opencast_uploadedclip', ['opencastid' => $opencast->id]); if (!$uploaded_videos) { continue; } $series = new mod_opencast_series(); try { // try and fetch the series on the back-end BUT do not halt on error $fetch_result = $series->fetch($opencast->id, true, true, false); if ($fetch_result == false) { throw new moodle_exception('api_404', 'opencast'); } } catch (Exception $e) { // error with this channel: do not halt because we might be processing other jobs (unattended) if ($e->errorcode === 'channel_not_found') { // TODO figure out the errorcode for the new API // channel not existing anymore: stop looking for it ever again $opencast->userupload = 0; $DB->update_record('opencast', $opencast); } continue; } $series_events = $series->getEvents(); $series_event_indentifiers = []; foreach ($series_events as $series_event) { $series_event_indentifiers[] = (string) $series_event->identifier; } foreach ($uploaded_videos as $uploaded_video) { if ($uploaded_video->status == OPENCAST_CLIP_READY) { // encoding finished if (!in_array($uploaded_video->ext_id, $series_event_indentifiers)) { // clip deleted $DB->delete_records('opencast_uploadedclip', ['id' => $uploaded_video->id]); } else { $uploaded[] = $uploaded_video->filename; } } else { if (in_array($uploaded_video->ext_id, $series_event_indentifiers)) { // clip being processed: check whether it's ready foreach ($series_events as $series_event) { if ($series_event->identifier == $uploaded_video->ext_id) { if ($series_event->processing_state == OPENCAST_PROCESSING_SUCCEEDED && count($series_event->publications)) { // it's ready! $uploaded[] = $uploaded_video->filename; $uploaded_video->status = OPENCAST_CLIP_READY; $DB->update_record('opencast_uploadedclip', $uploaded_video); $user = $DB->get_record('user', ['id' => $uploaded_video->userid]); if ($user !== false) { // notify user $a = new stdClass(); $a->filename = $uploaded_video->filename; $a->cliptitle = $uploaded_video->title; $cm = get_coursemodule_from_instance('opencast', $opencast->id); $a->link = $CFG->wwwroot . '/mod/opencast/view.php?id=' . $cm->id; email_to_user($user, $admin, get_string('clipready_subject', 'opencast'), get_string('clipready_body', 'opencast', $a)); } } } } } else { // clip still pending $pending[] = $uploaded_video->filename; } } } } return [$pending, $uploaded]; }