Skip to content

Commit 78bbf79

Browse files
committed
Introduce series-based event discovery to limit processing to relevant events,
This PR introduces a new discovery method to ensure only events related to the current Stud.IP instance are processed. - Events without a series ID will still be processed, as there's no reliable way to determine their relevance. - Events with a series ID will be checked against the list of known series for the current instance. If the series is unknown, the event is skipped as unrelated.
1 parent 034a519 commit 78bbf79

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

cronjobs/opencast_discover_videos.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Opencast\Models\PlaylistVideos;
1010
use Opencast\Models\WorkflowConfig;
1111
use Opencast\Models\REST\ApiEventsClient;
12+
use Opencast\Models\Helpers;
1213

1314
class OpencastDiscoverVideos extends CronJob
1415
{
@@ -94,6 +95,14 @@ public function execute($last_result, $parameters = array())
9495
if (!empty($oc_events)) foreach ($oc_events as $event) {
9596
$current_event = null;
9697

98+
// Is the episode related to this studip?
99+
// We need to check this, because it might happen that the Opencast server is connected to multiple Stud.IP instances,
100+
// and we only want to process events that are related to this Stud.IP instance.
101+
if (!Helpers::isEventInThisStudip($event)) {
102+
echo 'Event not related to this Stud.IP instance, skipping: ' . $event->identifier . "\n";
103+
continue;
104+
}
105+
97106
// only add videos / reinspect videos if they are readily processed
98107
if ($event->status == 'EVENTS.EVENTS.STATUS.PROCESSED') {
99108
$event_ids[] = $event->identifier;

lib/Models/Helpers.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
class Helpers
1313
{
14+
const RECORDED_SERIES_ID_CACHE_ID = 'OpencastV3/series/recorded_series_ids';
15+
1416
static function getConfigurationstate()
1517
{
1618
$stmt = DBManager::get()->prepare("SELECT COUNT(*) AS c FROM oc_config WHERE active = 1");
@@ -426,4 +428,76 @@ public static function isWorldReadable($oc_acls)
426428

427429
return $has_anonymous_role;
428430
}
431+
432+
/**
433+
* Retrieves all known recorded Opencast series IDs from the cache or database.
434+
*
435+
* This method returns an array of all series IDs that are known to the system,
436+
* combining both user-specific and seminar-specific series. It first attempts
437+
* to read the list from the cache. If the cache is empty or if the $force
438+
* parameter is set to true, it queries the database for all user and seminar
439+
* series IDs, merges and deduplicates them, and then updates the cache.
440+
*
441+
* @param bool $force If true, forces a refresh from the database instead of using the cache.
442+
* @return array List of unique recorded series IDs.
443+
*/
444+
public static function getAllRecordedSeriesIds(bool $force = false)
445+
{
446+
$cache = StudipCacheFactory::getCache();
447+
$all_known_seriesids = $cache->read(self::RECORDED_SERIES_ID_CACHE_ID);
448+
if ($force || empty($cache_data)) {
449+
$all_known_seriesids = [];
450+
$user_series_ids =\SimpleCollection::createFromArray(
451+
UserSeries::findBySql('1')
452+
)->toArray()->pluck('series_id');
453+
$seminar_series_ids =\SimpleCollection::createFromArray(
454+
SeminarSeries::findBySql('1')
455+
)->toArray()->pluck('series_id');
456+
$all_known_seriesids = array_merge($user_series_ids, $seminar_series_ids);
457+
$all_known_seriesids = array_unique($all_known_seriesids);
458+
$cache->write(self::RECORDED_SERIES_ID_CACHE_ID, $all_known_seriesids);
459+
}
460+
return $all_known_seriesids;
461+
}
462+
463+
/**
464+
* Determines whether a given Opencast event belongs to this Stud.IP instance.
465+
*
466+
* This method checks if the provided Opencast event's series ID (`is_part_of`)
467+
* is known to the current Stud.IP system. If the event does not have a series ID,
468+
* it is considered valid for this Stud.IP instance. Otherwise, the method checks
469+
* if the series ID exists in the list of all recorded series IDs known to Stud.IP.
470+
*
471+
* @param object $oc_event The Opencast event object to check.
472+
* @return bool True if the event belongs to this Stud.IP instance, false otherwise.
473+
*/
474+
public static function isEventInThisStudip($oc_event)
475+
{
476+
if (empty($oc_event->is_part_of)) {
477+
// No series id, so we consider it as a valid event for this studip to be processed!
478+
return true;
479+
}
480+
481+
$all_known_seriesids = self::getAllRecordedSeriesIds();
482+
if (in_array($event->is_part_of, $all_known_seriesids)) {
483+
return true;
484+
}
485+
486+
return false;
487+
}
488+
489+
/**
490+
* Invalidates the cache for recorded series IDs.
491+
*
492+
* This method clears the cache entry that stores all known recorded series IDs.
493+
* It should be called whenever a series is created or deleted to ensure
494+
* that the cache remains consistent with the database.
495+
* @see \Opencast\Models\UserSeries
496+
* @see \Opencast\Models\SeminarSeries
497+
*/
498+
public static function invalidateRecordedSeriesIdsCache()
499+
{
500+
$cache = StudipCacheFactory::getCache();
501+
$cache->expire(self::RECORDED_SERIES_ID_CACHE_ID);
502+
}
429503
}

lib/Models/SeminarSeries.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,22 @@ public static function getSeries($course_id, $offline = false)
7070

7171
return $return;
7272
}
73+
74+
/**
75+
* Invalidate the cache of recorded series IDs before storing a series.
76+
* Then proceeds with the parent store method.
77+
*/
78+
public function store() {
79+
Helpers::invalidateRecordedSeriesIdsCache();
80+
return parent::store();
81+
}
82+
83+
/**
84+
* Invalidate the cache of recorded series IDs before deleting a series.
85+
* Then proceeds with the parent delete method.
86+
*/
87+
public function delete() {
88+
Helpers::invalidateRecordedSeriesIdsCache();
89+
return parent::delete();
90+
}
7391
}

lib/Models/UserSeries.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,22 @@ public static function createSeries($user_id) {
5353
// Throw error
5454
}
5555
}
56+
57+
/**
58+
* Invalidate the cache of recorded series IDs before storing a series.
59+
* Then proceeds with the parent store method.
60+
*/
61+
public function store() {
62+
Helpers::invalidateRecordedSeriesIdsCache();
63+
return parent::store();
64+
}
65+
66+
/**
67+
* Invalidate the cache of recorded series IDs before deleting a series.
68+
* Then proceeds with the parent delete method.
69+
*/
70+
public function delete() {
71+
Helpers::invalidateRecordedSeriesIdsCache();
72+
return parent::delete();
73+
}
5674
}

0 commit comments

Comments
 (0)