88use Opencast \VersionHelper ;
99use Opencast \Providers \Perm ;
1010use Opencast \Models \Videos ;
11+ use Opencast \Models \REST \ApiEventsClient ;
12+ use Opencast \Models \REST \ApiWorkflowsClient ;
1113
1214class 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}
0 commit comments