Skip to content

Commit

Permalink
add version information to co_videos and act upon it, fixes #1094 (#1106
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tgloeggl authored Dec 11, 2024
1 parent 9ffcbe2 commit b90c9d2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
37 changes: 26 additions & 11 deletions cronjobs/opencast_discover_videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function execute($last_result, $parameters = array())
*/
$db = DBManager::get();
$stmt_ids = $db->prepare("
SELECT episode FROM oc_video WHERE config_id = :config_id AND available=true
SELECT episode, version FROM oc_video WHERE config_id = :config_id AND available=true
");

// iterate over all active configured oc instances
Expand Down Expand Up @@ -61,24 +61,39 @@ public function execute($last_result, $parameters = array())
$event_ids = [];
$events = [];

// get all known events in Stud.IP
$stmt_ids->execute([':config_id' => $config['id']]);

$local_events = $stmt_ids->fetchAll(PDO::FETCH_KEY_PAIR);
$local_event_ids = array_keys($local_events);

// load events from opencast filter the processed ones
foreach ($api_client->getAll() as $event) {
// only add videos / reinspect videos if they are readily processed
if ($event->status == 'EVENTS.EVENTS.STATUS.PROCESSED') {
$event_ids[] = $event->identifier;
$events[$event->identifier] = $event;
}
}

// check if these event_ids have a corresponding entry in Stud.IP
// check archive versions and if they differ, reinspect the video
if (isset($local_events[$event->identifier])
&& $local_events[$event->identifier] != $event->archive_version
) {
$video = Videos::findOneBySql("config_id = ? AND episode = ?", [$config['id'], $event->identifier]);
echo 'schedule video for re-inspection, archive versions differ: ' . $video->id . ' (' . $video->title . ")\n";

$stmt_ids->execute([':config_id' => $config['id']]);
// create task to update permissions and everything else
$task = new VideoSync;

$local_event_ids = $stmt_ids->fetchAll(PDO::FETCH_COLUMN);
//echo 'found oc events:' . "\n";
//print_r($events);
$task->setData([
'video_id' => $video->id,
'state' => 'scheduled',
'scheduled' => date('Y-m-d H:i:s')
]);

//echo 'found local events:' . "\n";
//print_r($local_event_ids);
$task->store();
}
}
}

// Find new videos available in OC but not locally
foreach (array_diff($event_ids, $local_event_ids) as $new_event_id) {
Expand Down Expand Up @@ -135,7 +150,7 @@ public function execute($last_result, $parameters = array())
* FAILED wird nur jede Stunde neu inspiziert
* Das scheduled Feld wird genutzt, um Dinge für die Zukunft zu planen
*/
foreach (Videos::findBySql('preview IS NULL AND is_livestream = 0') as $video) {
foreach (Videos::findBySql('(preview IS NULL OR available = 0) AND is_livestream = 0') as $video) {
// check, if there is already a task scheduled
if (empty(VideoSync::findByVideo_id($video->id))) {
echo 'schedule video for re-inspection: ' . $video->id . ' (' . $video->title . ")\n";
Expand Down
2 changes: 2 additions & 0 deletions cronjobs/opencast_worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function execute($last_result, $parameters = array())
} else if ($event->status === "EVENTS.EVENTS.STATUS.PROCESSED" && !empty($event->publications)) {
$video->publication = json_encode($event->publications);
$video->state = null;
$video->available = 1;
$video->version = $event->archive_version;
$video->is_livestream = 0;
} else if ($event->status === "EVENTS.EVENTS.STATUS.PROCESSED" && empty($event->publications)) {
if ($is_livestream && !empty($event->scheduling)) {
Expand Down
22 changes: 22 additions & 0 deletions migrations/098_add_archive_version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

class AddArchiveVersion extends Migration
{
public function description()
{
return 'Add Opencast archive version to Stud.IP for finding videos worth to reinspect';
}

public function up()
{
$db = DBManager::get();

$stmt = $db->exec('ALTER TABLE oc_video
ADD COLUMN `version` INT NOT NULL DEFAULT 0 AFTER config_id');
}

public function down()
{

}
}

0 comments on commit b90c9d2

Please sign in to comment.