Skip to content

Commit b09ea37

Browse files
committed
changes according to discussion:
- pass user series when uploading from workspace - add a checker/mapper to insert user series for those events without series based on perms "owner"
1 parent a67f516 commit b09ea37

File tree

4 files changed

+84
-9
lines changed

4 files changed

+84
-9
lines changed

bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
NotificationCenter::addObserver('Opencast\Models\Videos', 'parseEvent', 'OpencastVideoSync');
88
NotificationCenter::addObserver('Opencast\Models\Videos', 'checkEventACL', 'OpencastVideoSync');
99
NotificationCenter::addObserver('Opencast\Models\VideosUserPerms', 'setPermissions', 'OpencastVideoSync');
10+
NotificationCenter::addObserver('Opencast\Models\Helpers', 'mapEventUserSeriesUserPerms', 'OpencastVideoSync');
1011
NotificationCenter::addObserver('Opencast\Models\Helpers', 'notifyUsers', 'OpencastNotifyUsers');
1112

cronjobs/opencast_discover_videos.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function execute($last_result, $parameters = array())
111111
// Is the episode related to this studip?
112112
// We need to check this, because it might happen that the Opencast server is connected to multiple Stud.IP instances,
113113
// and we only want to process events that are related to this Stud.IP instance.
114-
if (!Helpers::isEventInThisStudip($event)) {
114+
if (!Helpers::isEventInAnyKnownSeries($event)) {
115115
echo '[Skipped] Event not related to this Stud.IP instance, skipping: ' . $event->identifier . "\n";
116116
continue;
117117
}

lib/Models/Helpers.php

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Opencast\VersionHelper;
99
use Opencast\Providers\Perm;
1010
use Opencast\Models\Videos;
11+
use Opencast\Models\REST\ApiEventsClient;
12+
use Opencast\Models\REST\ApiWorkflowsClient;
1113

1214
class Helpers
1315
{
@@ -462,7 +464,7 @@ public static function getAllRecordedSeriesIds(bool $force = false)
462464
}
463465

464466
/**
465-
* Determines whether a given Opencast event belongs to this Stud.IP instance.
467+
* Determines whether a given Opencast event belongs to any know series in this Stud.IP instance.
466468
*
467469
* This method checks if the provided Opencast event's series ID (`is_part_of`)
468470
* is known to the current Stud.IP system. If the event does not have a series ID,
@@ -472,7 +474,7 @@ public static function getAllRecordedSeriesIds(bool $force = false)
472474
* @param object $oc_event The Opencast event object to check.
473475
* @return bool True if the event belongs to this Stud.IP instance, false otherwise.
474476
*/
475-
public static function isEventInThisStudip($oc_event)
477+
public static function isEventInAnyKnownSeries($oc_event)
476478
{
477479
if (empty($oc_event->is_part_of)) {
478480
// No series id, so we consider it as a valid event for this studip to be processed!
@@ -502,4 +504,57 @@ public static function invalidateRecordedSeriesIdsCache()
502504
$cache = \StudipCacheFactory::getCache();
503505
$cache->expire(self::RECORDED_SERIES_ID_CACHE_ID);
504506
}
507+
508+
/**
509+
* Gives the events without series id a chance of getting one by mapping user perms and user series.
510+
*
511+
* @Notification OpencastVideoSync
512+
*
513+
* @param string $eventType
514+
* @param object $event
515+
* @param Opencast\Models\Videos $video
516+
*/
517+
public static function mapEventUserSeriesUserPerms($eventType, $event, $video)
518+
{
519+
if (!empty($event->is_part_of)) {
520+
// Already has a series id, then we are done here!
521+
return;
522+
}
523+
524+
// Get the (a) video owner.
525+
$video_owner = VideosUserPerms::findOneBySQL('video_id = ? AND perm = ?', [$video->id, 'owner']);
526+
if (empty($video_owner)) {
527+
// No owner, then we have nothing to do here!
528+
return;
529+
}
530+
531+
// Make sure the owner has a user series!
532+
$user_series = null;
533+
534+
$all_user_series = UserSeries::getSeries($video_owner->user_id);
535+
// Enforce user series creation!
536+
if (empty($all_user_series)) {
537+
$user_series = UserSeries::createSeries($video_owner->user_id);
538+
} else {
539+
$user_series = $all_user_series[0];
540+
}
541+
542+
// Update the event with the new series id.
543+
$api_event_client = ApiEventsClient::getInstance($video->config_id);
544+
545+
$metadata[] = [
546+
'id' => 'isPartOf',
547+
'value' => $user_series['series_id']
548+
];
549+
$response = $api_event_client->updateMetadata($video->episode, $metadata);
550+
$republish = in_array($response['code'], [200, 204]) === true;
551+
552+
if ($republish) {
553+
$api_wf_client = ApiWorkflowsClient::getInstance($video->config_id);
554+
555+
if ($api_wf_client->republish($video->episode)) {
556+
echo 'Event metadata has been updated by the owner specific series id: ' . $video->episode . "\n";
557+
}
558+
}
559+
}
505560
}

vueapp/components/Videos/VideoUpload.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,19 @@ export default {
261261
262262
computed: {
263263
...mapGetters({
264-
'config' : 'simple_config_list',
265-
'course_config' : 'course_config',
266-
'cid' : 'cid',
267-
'playlist' : 'playlist',
268-
'playlists' : 'playlists',
269-
'currentLTIUser': 'currentLTIUser'
264+
'config' : 'simple_config_list',
265+
'course_config' : 'course_config',
266+
'cid' : 'cid',
267+
'playlist' : 'playlist',
268+
'playlists' : 'playlists',
269+
'currentLTIUser' : 'currentLTIUser',
270+
'currentUserSeries' : 'currentUserSeries'
270271
}),
271272
273+
fragment() {
274+
return this.$route.name;
275+
},
276+
272277
upload_playlists() {
273278
let upload_playlists = [...this.playlists];
274279
@@ -405,6 +410,9 @@ export default {
405410
406411
if (this.cid) {
407412
uploadData['seriesId'] = this.course_config['series']['series_id'];
413+
} else if (this.fragment === 'videos' && this.currentUserSeries) {
414+
// Force to add user series if when in work space!
415+
uploadData['seriesId'] = this.currentUserSeries;
408416
}
409417
410418
uploadData['created'] = new Date(this.upload.recordDate).toISOString();
@@ -437,6 +445,17 @@ export default {
437445
438446
let view = this;
439447
448+
// We need to force the seriesId from now on in order to make sure everything is in place.
449+
if (!uploadData?.seriesId) {
450+
this.$store.dispatch('addMessage', {
451+
'type': 'error',
452+
'text': this.$gettext('Leider kann das Video momentan nicht hochgeladen werden,' +
453+
' da notwendige Daten fehlen. Bitte kontaktieren Sie Ihre Systemadministration.'),
454+
dialog: true
455+
});
456+
return;
457+
}
458+
440459
this.uploadService.upload(files, uploadData, this.selectedWorkflow.name, ltiUploader, {
441460
uploadProgress: (track, loaded, total) => {
442461
view.uploadProgress = {

0 commit comments

Comments
 (0)