Skip to content

Commit ca1e1a7

Browse files
committed
Make sure event has required properties,
It includes a mechanism that checks the integrity of the event before any operation by checking properties against a local array which can be adjusted later on!
1 parent 2b4ecc8 commit ca1e1a7

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

cronjobs/opencast_discover_videos.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
class OpencastDiscoverVideos extends CronJob
1414
{
1515

16+
/**
17+
* @var array The required properties of the event object which will be checked before any operation.
18+
*/
19+
private static $required_event_properties = [
20+
'archive_version'
21+
];
22+
1623
public static function getName()
1724
{
1825
return _('Opencast - Neue Videos finden');
@@ -26,8 +33,8 @@ public static function getDescription()
2633
public function execute($last_result, $parameters = array())
2734
{
2835
/*
29-
- Neue Videos in OC identifizieren (die Stud.IP noch nicht kennt)
30-
- Eintragen der Videos und setzen der Rechte (Queue)
36+
- Neue Videos in OC identifizieren (die Stud.IP noch nicht kennt)
37+
- Eintragen der Videos und setzen der Rechte (Queue)
3138
*/
3239
$db = DBManager::get();
3340
$stmt_ids = $db->prepare("
@@ -94,6 +101,12 @@ public function execute($last_result, $parameters = array())
94101
if (!empty($oc_events)) foreach ($oc_events as $event) {
95102
$current_event = null;
96103

104+
// Check the required properties of the event.
105+
if (!self::checkEventIntegrity($event)) {
106+
echo '[Skipped] The event does not have all required properties, skipping: ' . $event->identifier . "\n";
107+
continue;
108+
}
109+
97110
// only add videos / reinspect videos if they are readily processed
98111
if ($event->status == 'EVENTS.EVENTS.STATUS.PROCESSED') {
99112
$event_ids[] = $event->identifier;
@@ -197,6 +210,23 @@ public function execute($last_result, $parameters = array())
197210
echo 'Finished updating videos and workflows' . "\n";
198211
}
199212

213+
/**
214+
* Check if the event has all required properties.
215+
*
216+
* @param object $event The event object to check.
217+
* @return bool True if the event has all required properties, false otherwise.
218+
*/
219+
private static function checkEventIntegrity($event) {
220+
// Check if the event has all required properties
221+
foreach (self::$required_event_properties as $property) {
222+
if (!property_exists($event, $property)) {
223+
return false;
224+
}
225+
}
226+
227+
return true;
228+
}
229+
200230
private static function parseEvent($event, $video)
201231
{
202232
if (in_array($event->processing_state, ['FAILED', 'STOPPED']) === true) { // It failed.

0 commit comments

Comments
 (0)