Skip to content

Commit

Permalink
refs #779, keep Stud.IP and OC in sync
Browse files Browse the repository at this point in the history
  • Loading branch information
tgloeggl committed May 30, 2024
1 parent d07f241 commit 5996998
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
38 changes: 31 additions & 7 deletions cronjobs/opencast_refresh_scheduling.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ public function execute($last_result, $parameters = array())
foreach ($config as $conf) {
$config_id = $conf['id'];
$scheduled_events = [];

try {
$events_client = ApiEventsClient::getInstance($config_id);
// Adding config_id to each record for easier use later on!
$scheduled_events = array_map(function ($event) use ($config_id) {
$event->config_id = $config_id;
return $event;
}, $events_client->getAllScheduledEvents());
} catch (\Throwable $th) {}
} catch (\Throwable $th) {
echo 'Fehler beim abrufen der Events für config_id '. $config_id
.': '. $th->getMessage() . "\n";
}

$oc_scheduled_events[] = [
'config_id' => $config_id,
'scheduled_events' => $scheduled_events
Expand All @@ -75,6 +80,8 @@ public function execute($last_result, $parameters = array())
if (!$cd || !$course || !$course_config_id || !$resource_obj // Any requirement fails
|| !ScheduleHelper::validateCourseAndResource($scheduled_events['seminar_id'], $resource_obj['config_id']) // The server config id of the course and the oc_resource does not match
|| $cd->room_booking->resource_id != $scheduled_events['resource_id'] // The resource of the record and course date does not match
|| $cd->room_booking->begin != $scheduled_events['start'] // Start or Enddate are different
|| $cd->room_booking->end != $scheduled_events['end']
/* || intval($cd->end_time) < $time */ // TODO: decide whether to remove those records that are expired!
) {

Expand All @@ -88,26 +95,30 @@ public function execute($last_result, $parameters = array())

$oc_event_id = $scheduled_events['event_id'];
$oc_config_id = $course_config_id;

// Delete the record in SOP.
ScheduledRecordings::unscheduleRecording($oc_event_id, $scheduled_events['resource_id'], $scheduled_events['date_id']);

// Delete the record in OC.

// Delete the recording in OC.
if (!ScheduleHelper::validateCourseAndResource($scheduled_events['seminar_id'], $resource_obj['config_id'])) {
$oc_config_id = $resource_obj['config_id'];
}

$oc_set_index = array_search($oc_config_id, array_column($oc_scheduled_events, 'config_id'));
$oc_event_to_delete = null;

// search for the corresponding event in Opencast
if ($oc_set_index !== false && isset($oc_scheduled_events[$oc_set_index]['scheduled_events'][$oc_event_id])) {
$oc_event_to_delete = $oc_scheduled_events[$oc_set_index]['scheduled_events'][$oc_event_id];
}

if (!empty($oc_event_to_delete)) {
$scheduler_client = SchedulerClient::getInstance($oc_config_id);
$result = $scheduler_client->deleteEvent($oc_event_id);
if ($result) {
unset($oc_scheduled_events[$oc_set_index]['scheduled_events'][$oc_event_id]);
}
}

// Delete the recording in SOP.
ScheduledRecordings::unscheduleRecording($oc_event_id, $scheduled_events['resource_id'], $scheduled_events['date_id']);
} else {
// If validation is passed, we try to update to the record on both sides.
// Update the record.
Expand All @@ -116,13 +127,26 @@ public function execute($last_result, $parameters = array())
$cd->getFullname(), $course->name
);

$result = ScheduleHelper::updateEventForSeminar($scheduled_events['seminar_id'], $scheduled_events['date_id']);
$result = ScheduleHelper::updateEventForSeminar(
$scheduled_events['seminar_id'], $scheduled_events['date_id']
);

if ($result) {
$oc_set_index = array_search($course_config_id, array_column($oc_scheduled_events, 'config_id'));
$oc_event_id = $scheduled_events['event_id'];
if ($oc_set_index !== false && isset($oc_scheduled_events[$oc_set_index]['scheduled_events'][$oc_event_id])) {
unset($oc_scheduled_events[$oc_set_index]['scheduled_events'][$oc_event_id]);
}
} else {
// try to (re-)create event in opencast
echo 'Eintrag fehlt im Opencast, versuche ihn zu erstellen...';
$result = ScheduleHelper::scheduleEventForSeminar(
$scheduled_events['seminar_id'], $scheduled_events['date_id'],
$scheduled_event['is_livestream'] ? true : false
);

echo $result ? ' erfolgreich' : 'fehlgeschlagen';
echo "\n";
}
}
} catch (\Throwable $th) {
Expand Down
18 changes: 14 additions & 4 deletions lib/Models/REST/ApiEventsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,25 @@ public function getAll($params = [])
*/
public function getAllScheduledEvents()
{
// filters are AND concatenated, to get all events, we need to split the calls

// EVENTS.EVENTS.STATUS.RECORDING should also be added here... which refers to live events
$params = [
$params[0] = [
'filter' => ['status' => [
'EVENTS.EVENTS.STATUS.SCHEDULED'
]],
];

$params[1] = [
'filter' => ['status' => [
'EVENTS.EVENTS.STATUS.SCHEDULED',
'EVENTS.EVENTS.STATUS.RECORDING',
'EVENTS.EVENTS.STATUS.RECORDING'
]],
];

$data = $this->getAll($params);
$data = array_merge(
$this->getAll($params[0]),
$this->getAll($params[1])
);

if (is_array($data)) foreach ($data as $event) {
$events[$event->identifier] = $event;
Expand Down

0 comments on commit 5996998

Please sign in to comment.