-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathopencast_sync_acls.php
93 lines (75 loc) · 2.85 KB
/
opencast_sync_acls.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require_once __DIR__.'/../bootstrap.php';
require_once __DIR__.'/../vendor/autoload.php';
use Opencast\Models\Config;
use Opencast\Models\Videos;
use Opencast\Models\REST\ApiEventsClient;
use Opencast\Models\REST\Config as OCConfig;
class OpencastSyncAcls extends CronJob
{
public static function getName()
{
return _('Opencast - Synchronisiert ACLs für Events');
}
public static function getDescription()
{
return _('Opencast: Synchronisiert ACLs für Events');
}
/**
* Iterate over all videos andf playlists from opencast known to Stud.IP
* and set the correct ACLs accordingly
*
* @param string $last_result
* @param array $parameters
*
* @return void
*/
public function execute($last_result, $parameters = array())
{
$db = DBManager::get();
// iterate over all active configured oc instances
$configs = Config::findBySql('active = 1');
foreach ($configs as $config) {
// check, if this opencast instance is accessible
$version = false;
echo 'working on config '. $config->id ."\n";
$version = OCConfig::getOCBaseVersion($config->id);
if (!$version) {
echo 'cannot connect to opencast, skipping!' ."\n";
continue;
} else {
echo "found opencast with version $version, continuing\n";
}
// update endpoints, just to make sure
// $config->updateEndpoints();
// call opencast to get all event ids
$api_client = ApiEventsClient::getInstance($config['id']);
// paginated fetch of events from opencast
$oc_events = [];
$offset = 0;
$limit = 100;
do {
$paged_events = $api_client->getAll([
'limit' => $limit,
'offset' => $offset,
'sort' => 'date:DESC',
'withacl' => 'true'
]);
$oc_events = array_merge($oc_events, $paged_events);
$offset += $limit;
} while (sizeof($paged_events) > 0);
foreach ($oc_events as $event) {
// only add videos / reinspect videos if they are readily processed
if ($event->status == 'EVENTS.EVENTS.STATUS.PROCESSED') {
// check if video exists in Stud.IP
$video = Videos::findByEpisode($event->identifier);
if ($video->config_id != $config->id) {
echo 'config id mismatch for Video with id: '. $video->id .", $config->id <> {$video->config_id}\n";
continue;
}
Videos::checkEventACL(null, $event, $video);
}
}
}
}
}