Skip to content

Commit

Permalink
fix scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
tgloeggl committed Aug 29, 2023
1 parent dd5fb98 commit e6e89e2
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 195 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"require": {
"slim/slim": "^3.12",
"elan-ev/opencast-api": "^1.3",
"elan-ev/opencast-api": "^1.4",
"symfony/console": "^5.3"
},
"require-dev": {
Expand Down
18 changes: 10 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 12 additions & 18 deletions lib/Models/REST/IngestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($config_id = 1)
public function createMediaPackage()
{
$response = $this->opencastApi->ingest->createMediaPackage();

if ($response['code'] == 200) {
return $response['body'];
}
Expand All @@ -46,7 +46,7 @@ public function createMediaPackage()
public function addDCCatalog($mediaPackage, $dublinCore, $flavor = '')
{
$response = $this->opencastApi->ingest->addDCCatalog($mediaPackage, $dublinCore, $flavor);

if ($response['code'] == 200) {
return $response['body'];
}
Expand All @@ -65,7 +65,7 @@ public function addDCCatalog($mediaPackage, $dublinCore, $flavor = '')
public function ingest($mediaPackage, $workflowDefinitionId = '', $workflowInstanceId = '')
{
$response = $this->opencastApi->ingest->ingest($mediaPackage, $workflowDefinitionId, $workflowInstanceId);

if ($response['code'] == 200) {
return $response['body'];
}
Expand All @@ -78,13 +78,13 @@ public function ingest($mediaPackage, $workflowDefinitionId = '', $workflowInsta
* @param string $mediaPackage The media package
* @param string $trackURI The location of the media
* @param string $flavor The kind of media track
*
*
* @return string augmented media package in xml format, or false if unable to add
*/
public function addTrack($mediaPackage, $trackURI, $flavor)
{
$response = $this->opencastApi->ingest->addTrackUrl($mediaPackage, $flavor, $trackURI);

if ($response['code'] == 200) {
return $response['body'];
}
Expand All @@ -93,21 +93,18 @@ public function addTrack($mediaPackage, $trackURI, $flavor)

/**
* Schedule an event based on the given media package.
*
*
* @param string $mediaPackage The media package
* @param string $workflowDefinitionId Workflow definition id
* @param string $capabilities Device Capabilities
* @param boolean $livestream Whether to schedule with publishLive param
*
*
* @return boolean whether the event is scheduled or not
*/
public function schedule($mediaPackage, $workflowDefinitionId = '', $capabilities = '', $livestream = false)
public function schedule($mediaPackage, $workflowDefinitionId = '', $capabilities = '')
{
// This part has been taken out from the old SOP which is intended to schedule an event
// with livestreaming capability, which does not work properly and must have further R&D!
if (!empty($capabilities) || $livestream) {
if (!empty($capabilities)) {
$uri = "/ingest/schedule";

if (!empty($workflowDefinitionId)) {
$uri .= "/{$workflowDefinitionId}";
}
Expand All @@ -120,18 +117,15 @@ public function schedule($mediaPackage, $workflowDefinitionId = '', $capabilitie
$query['capture.device.names'] = $capabilities;
}

if ($livestream) {
$query['publishLive'] = 'True';
}

$options = $this->ocRestClient->getQueryParams($query);
$response = $this->ocRestClient->performGet($uri, $options);

return $response['code'] == 200;
} else {
$response = $this->opencastApi->ingest->schedule($mediaPackage, $workflowDefinitionId);
return $response['code'] == 201;
return (in_array($response['code'], [200, 201]) !== false);
}

return false;
}
}
3 changes: 1 addition & 2 deletions lib/Models/REST/SeriesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public function createSeriesForSeminar($course_id)
];

$metadata = self::getSeriesDC($course_id);

$response = $this->opencastApi->seriesApi->create($metadata, $acl);

if ((int)$response['code'] === 201) {
Expand All @@ -95,7 +94,7 @@ private static function getSeriesDC($course_id)
$license = "© " . gmdate('Y') . " " . $GLOBALS['UNI_NAME_CLEAN'];
$inst = \Institute::find($course->institut_id);

$publisher = $inst->name;
$publisher = (string)$inst->name;
$instructors = $course->getMembers('dozent');
$instructor = array_shift($instructors);
$contributor = $GLOBALS['UNI_NAME_CLEAN'] ?: 'unbekannt';
Expand Down
73 changes: 42 additions & 31 deletions lib/Models/ScheduleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,22 @@ private static function getDCTime($timestamp)
*
* @param string $course_id - course identifier
* @param string $termin_id - termin identifier
* @param bool $livestream - livestream flag
*
* @return bool success or not
*/
public static function scheduleEventForSeminar($course_id, $termin_id, $livestream = false)
public static function scheduleEventForSeminar($course_id, $termin_id)
{
$date = new \SingleDate($termin_id);
$resource_id = $date->getResourceID();
if (!$resource_id) {
return false;
}

$oc_resource = Resources::findByResource_id($resource_id);
if (!$oc_resource
|| !self::checkCaptureAgent($oc_resource['config_id'], $oc_resource['capture_agent'])
|| !self::validateCourseAndResource($course_id, $oc_resource['config_id'])) {
|| !self::validateCourseAndResource($course_id, $oc_resource['config_id'])
) {
return false;
}

Expand All @@ -361,10 +362,9 @@ public static function scheduleEventForSeminar($course_id, $termin_id, $livestre
$metadata = self::createEventMetadata($course_id, $resource_id, $oc_resource['config_id'], $termin_id, null);
$media_package = $ingest_client->addDCCatalog($media_package, $metadata['dublincore']);

$result = $ingest_client->schedule($media_package, $metadata['workflow'], $metadata['device_capabilities'], $livestream);
$result = $ingest_client->schedule($media_package, $metadata['workflow'], $metadata['device_capabilities']);

if ($result) {

$xml = simplexml_load_string($media_package);
$event_id = (string)$xml['id'];
$scheduled = self::scheduleRecording($course_id, $resource_id, $termin_id, $event_id);
Expand All @@ -376,6 +376,7 @@ public static function scheduleEventForSeminar($course_id, $termin_id, $livestre
$scheduler_client = SchedulerClient::getInstance($oc_resource['config_id']);
$scheduler_client->deleteEvent($event_id);
}

return false;
}

Expand Down Expand Up @@ -679,23 +680,6 @@ public static function updateEventForSeminar($course_id, $termin_id, $start = nu
}
}

/**
* Gets the livestream parameter of the course's server config (if any)
*
* @param string $course_id course id
*
* @return bool
*/
public static function checkCourseConfigLivestream($course_id)
{
$livestream = false;
$config = Config::getConfigForCourse($course_id);
if ($config && isset($config['settings']['livestream'])) {
$livestream = $config['settings']['livestream'];
}
return $livestream;
}

/**
* Gets the list of scheduling dates for a course to be displayed in the scheduling list in a course
*
Expand All @@ -707,7 +691,6 @@ public static function checkCourseConfigLivestream($course_id)
public static function getScheduleList($course_id, $semester_filter)
{
$allow_schedule_alternate = \Config::get()->OPENCAST_ALLOW_ALTERNATE_SCHEDULE;
$allow_livestream = self::checkCourseConfigLivestream($course_id);

$dates = self::getDatesForSemester($course_id, $semester_filter);
$events = self::getCourseEvents($course_id);
Expand Down Expand Up @@ -814,14 +797,6 @@ public static function getScheduleList($course_id, $semester_filter)
'role' => 'clickable',
'title' => _('Aufzeichnung planen')
];
if ($allow_livestream) {
$actions['scheduleLive'] = [
'shape' => 'video',
'role' => 'clickable',
'title' => _('Livestream+Aufzeichnung planen'),
'info' => 'LIVE'
];
}
} else {
$actions['expire'] = [
'shape' => 'video+decline',
Expand Down Expand Up @@ -961,4 +936,40 @@ public static function deleteResource($resource_id)

return $success;
}

/**
* Send personal recording notifications to users for passed course
*
* @param string $course_id
*
* @return void
*/
public static function sendRecordingNotifications($course_id)
{
$course = \Course::find($course_id);
$members = $course->members;
$users = [];

foreach ($members as $member) {
$users[] = $member->user_id;
}

$notification = sprintf(
_('Die Veranstaltung "%s" wird für Sie mit Bild und Ton automatisiert aufgezeichnet.'),
htmlReady($course->name)
);

$plugin = \PluginEngine::getPlugin('OpenCast');
$assetsUrl = rtrim($plugin->getPluginURL(), '/') . '/assets';
$icon = \Icon::create($assetsUrl . '/images/opencast-black.svg');

\PersonalNotifications::add(
$users,
\PluginEngine::getURL('opencast', ['cid' => $course_id], 'course'),
$notification,
$course_id,
$icon
);
}

}
2 changes: 1 addition & 1 deletion lib/Routes/Course/CourseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __invoke(Request $request, Response $response, $args)

if (empty($series)) {
// only tutor or above should be able to trigger this series creation!
if ($perm->have_studip_perm('user', $course_id)) { // TODO: Set this to tutor!
if ($perm->have_studip_perm('tutor', $course_id)) {
// No series for this course yet! Create one!
$config_id = \Config::get()->OPENCAST_DEFAULT_SERVER;
$series_client = new SeriesClient($config_id);
Expand Down
9 changes: 4 additions & 5 deletions lib/Routes/Course/CourseListSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ public function __invoke(Request $request, Response $response, $args)
{
$course_id = $args['course_id'];
$semester_filter = $args['semester_filter'];

$semester_list = ScheduleHelper::getSemesterList($course_id);
$allow_schedule_alternate = \Config::get()->OPENCAST_ALLOW_ALTERNATE_SCHEDULE;
$allow_livestream = ScheduleHelper::checkCourseConfigLivestream($course_id);

$schedule_list = ScheduleHelper::getScheduleList($course_id, $semester_filter);

$response_data = [
'semester_list' => $semester_list,
'schedule_list' => $schedule_list,
'allow_schedule_alternate' => $allow_schedule_alternate,
'allow_livestream' => $allow_livestream
'allow_schedule_alternate' => $allow_schedule_alternate
];

return $this->createResponse($response_data, $response);
}
}
27 changes: 3 additions & 24 deletions lib/Routes/Schedule/ScheduleAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,19 @@ public function __invoke(Request $request, Response $response, $args)
}

$json = $this->getRequestData($request);
$livestream = isset($json['livestream']) ? $json['livestream'] : false;

$message = [
'type' => 'error',
'text' => _('Aufzeichnung konnte nicht geplant werden.')
];

if (ScheduleHelper::scheduleEventForSeminar($course_id, $termin_id, $livestream)) {
if (ScheduleHelper::scheduleEventForSeminar($course_id, $termin_id)) {
$message = [
'type' => 'success',
'text' => $livestream ? _('Livestream mit Aufzeichnung wurde geplant.') : _('Aufzeichnung wurde geplant.')
'text' => _('Aufzeichnung wurde geplant.')
];

$course = \Course::find($course_id);
$members = $course->members;
$users = [];
foreach ($members as $member) {
$users[] = $member->user_id;
}

$notification = sprintf(
_('Die Veranstaltung "%s" wird für Sie mit Bild und Ton automatisiert aufgezeichnet.'),
htmlReady($course->name)
);
$plugin = \PluginEngine::getPlugin('OpenCast');
$assetsUrl = rtrim($plugin->getPluginURL(), '/') . '/assets';
$icon = \Icon::create($assetsUrl . '/images/opencast-black.svg');
\PersonalNotifications::add(
$users,
\PluginEngine::getURL('opencast', ['cid' => $course_id], 'course'),
$notification,
$course_id,
$icon
);
ScheduleHelper::sendRecordingNotifications($course_id);

\StudipLog::log('OC_SCHEDULE_EVENT', $termin_id, $course_id);
}
Expand Down
Loading

0 comments on commit e6e89e2

Please sign in to comment.