Skip to content

Commit e34f895

Browse files
authored
Merge branch 'main' into issue-1243
2 parents 835e215 + 393db00 commit e34f895

37 files changed

+711
-142
lines changed

app/controllers/redirect.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function before_filter(&$action, &$args)
2727

2828
public function perform_action($action, $token)
2929
{
30+
$this->set_layout(null);
31+
$this->assets_url = rtrim($this->plugin->getPluginUrl(), '/') . '/assets';
32+
3033
$video = null;
3134
$video_share = null;
3235
if ($action == 'share') {
@@ -38,8 +41,10 @@ public function perform_action($action, $token)
3841

3942
if (empty($video)) {
4043
$this->error = _('Das Video wurde nicht gefunden, ist defekt oder momentan (noch) nicht verfügbar.');
44+
return;
4145
} else if ($video->trashed) {
4246
$this->error = _('Das Video wurde zur Löschung markiert und kann daher nicht abgerufen werden.');
47+
return;
4348
}
4449

4550
/*
@@ -53,6 +58,7 @@ public function perform_action($action, $token)
5358
$lti = LtiHelper::getLaunchData($video->config_id, $customtool, $video_share);
5459
if (empty($lti) || empty($customtool)) {
5560
$this->error = _('Das Video wurde nicht gefunden, ist defekt oder momentan (noch) nicht verfügbar.');
61+
return;
5662
}
5763

5864
// get correct endpoint for redirect type
@@ -64,12 +70,6 @@ public function perform_action($action, $token)
6470

6571
$this->launch_data = $ltilink['launch_data'];
6672
$this->launch_url = $ltilink['launch_url'];
67-
68-
if (!empty($this->error)) {
69-
$this->assets_url = rtrim($this->plugin->getPluginUrl(), '/') . '/assets';
70-
}
71-
72-
$this->set_layout(null);
7373
}
7474

7575
public function download_action($token, $type, $index)

courseware/package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cronjobs/opencast_courseware_block_copy_mapping.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Opencast\Models\CoursewareBlockMappings;
77
use Opencast\Models\VideoCoursewareBlocks;
8+
use Opencast\Models\Videos;
89
use Courseware\Block;
910

1011
class OpencastCoursewareBlockCopyMapping extends CronJob
@@ -36,23 +37,24 @@ public function execute($last_result, $parameters = array())
3637
$token = $mapping->token;
3738
$new_block_query->execute([':token' => $token]);
3839
$new_block_record = $new_block_query->fetchOne(PDO::FETCH_ASSOC);
39-
if (!empty($new_block_record)) {
40+
$video = Videos::find($mapping->video_id);
41+
if (!empty($new_block_record) && !empty($video)) {
4042
echo 'Peform mapping for block: ' . $new_block_record['id'] . "\n";
4143

4244
// Add record into the VideoCoursewareBlocks
4345
$msg = 'Record is added into oc_video_cw_blocks';
44-
$added = VideoCoursewareBlocks::setRecord($mapping->new_seminar_id, $mapping->token, $new_block_record['id']);
46+
$added = VideoCoursewareBlocks::setRecord($mapping->new_seminar_id, $video->token, $new_block_record['id']);
4547
if (!$added) {
4648
$msg = 'No record is added into oc_video_cw_blocks!';
4749
}
48-
echo $msg;
50+
echo $msg . "\n";
4951

5052
// Get the actual block object.
5153
$new_block = Block::find($new_block_record['id']);
5254
if (!empty($new_block)) {
5355
// Remove extra param from block's payload.
5456
$palyload = json_decode($new_block->payload, true);
55-
unset($palyload['copied_from']);
57+
unset($palyload['copied_token']);
5658
$new_block->payload = json_encode($palyload);
5759
$new_block->store();
5860
echo "Block's Playload cleared \n";

cronjobs/opencast_refresh_scheduling.php

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ public function execute($last_result, $parameters = array())
8282

8383
// Validate SOP resource.
8484
// In case validation fails, we try to remove the record on both sides!
85-
if (!$cd || !$course || !$course_config_id || !$resource_obj // Any requirement fails
85+
echo '-----------------------------------------------------' . "\n";
86+
87+
if (empty($cd) || empty($course) || empty($course_config_id) || empty($resource_obj) // Any requirement fails
8688
|| !ScheduleHelper::validateCourseAndResource($scheduled_events['seminar_id'], $resource_obj['config_id']) // The server config id of the course and the oc_resource does not match
8789
|| $cd->room_booking->resource_id != $scheduled_events['resource_id'] // The resource of the record and course date does not match
88-
|| $cd->room_booking->begin != $scheduled_events['start'] // Start or Enddate are different
89-
|| $cd->room_booking->end != $scheduled_events['end']
90+
|| $cd->room_booking->begin != $scheduled_events['coursedate_start'] // Start or Enddate are different
91+
|| $cd->room_booking->end != $scheduled_events['coursedate_end']
9092
/* || intval($cd->end_time) < $time */ // TODO: decide whether to remove those records that are expired!
9193
) {
9294

@@ -98,6 +100,25 @@ public function execute($last_result, $parameters = array())
98100
$print_date, $print_course
99101
);
100102

103+
echo 'Grund der Abweichung:' . "\n";
104+
if (empty($cd)) {
105+
echo 'Konnte den zugehörigen Termin nicht finden. Termin-ID: '. $scheduled_events['date_id'] ."\n";
106+
} else if (empty($course)) {
107+
echo 'Konnte den zugehörigen Kurs nicht finden. Kurs-ID: '. $scheduled_events['seminar_id'] ."\n";
108+
} else if (empty($course_config_id)) {
109+
echo 'Konnte die zugehörige Kurskonfiguration nicht finden. Kurs-ID: '. $scheduled_events['seminar_id'] ."\n";
110+
} else if (empty($resource_obj)) {
111+
echo 'Konnte Raum nicht finden. Raum-ID: '. $scheduled_events['resource_id'] ."\n";
112+
} else if (!ScheduleHelper::validateCourseAndResource($scheduled_events['seminar_id'], $resource_obj['config_id'])) {
113+
echo 'Die Opencast-Konfiguration für den Raum und den Kurs unterscheiden sich!' . "\n";
114+
} else if ($cd->room_booking->resource_id != $scheduled_events['resource_id']) {
115+
echo 'Der Raum hat sich geändert. Event: '. $scheduled_events['resource_id'] .', Buchung: '. $cd->room_booking->resource_id ."\n";
116+
} else if ($cd->room_booking->begin != $scheduled_events['coursedate_start']) {
117+
echo 'Die Startzeit ist unterschiedlich! Event: '. date('c', $scheduled_events['coursedate_start']) .', Buchung: '. date('c', $cd->room_booking->begin) . "\n";
118+
} else if ($cd->room_booking->end != $scheduled_events['coursedate_end']) {
119+
echo 'Die Startzeit ist unterschiedlich! Event: '. date('c', $scheduled_events['coursedate_end']) .', Buchung: '. date('c', $cd->room_booking->end) . "\n";
120+
}
121+
101122
$oc_event_id = $scheduled_events['event_id'];
102123
$oc_config_id = $course_config_id;
103124

@@ -125,8 +146,7 @@ public function execute($last_result, $parameters = array())
125146
// Delete the recording in SOP.
126147
ScheduledRecordings::unscheduleRecording($oc_event_id, $scheduled_events['resource_id'], $scheduled_events['date_id']);
127148
} else {
128-
// If validation is passed, we try to update to the record on both sides.
129-
// Update the record.
149+
// If validation is passed, we try to update the record on both sides.
130150
echo sprintf(
131151
"Aktualisiere die Aufzeichnungsdaten am %s für den Kurs %s\n",
132152
$cd->getFullname(), $course->name
@@ -170,16 +190,20 @@ public function execute($last_result, $parameters = array())
170190
} else {
171191
echo _('Nicht über Stud.IP Termine geplante Events:') . "\n";
172192
}
193+
173194
// Loop through the opencast scheduled events that are not yet proccessed above!
174195
// Each set is based on each opencast server config.
175196
foreach ($oc_scheduled_events as $oc_set) {
176197
if (!empty($oc_set['scheduled_events'])) {
177198
echo _('Opencast Server Config:') . " #{$oc_set['config_id']} \n";
178199
foreach ($oc_set['scheduled_events'] as $scheduled_event) {
179-
echo $scheduled_event->identifier . ' ' . $scheduled_event->title . "\n";
180-
if (StudipConfig::get()->OPENCAST_MANAGE_ALL_OC_EVENTS) {
181-
$scheduler_client = SchedulerClient::getInstance($oc_set['config_id']);
182-
$scheduler_client->deleteEvent($scheduled_event->identifier);
200+
// only touch events in the future
201+
if (strtotime($scheduled_event->start) > time()) {
202+
echo $scheduled_event->identifier . ' ' . $scheduled_event->title . "\n";
203+
if (StudipConfig::get()->OPENCAST_MANAGE_ALL_OC_EVENTS) {
204+
$scheduler_client = SchedulerClient::getInstance($oc_set['config_id']);
205+
$scheduler_client->deleteEvent($scheduled_event->identifier);
206+
}
183207
}
184208
}
185209
}

cronjobs/opencast_sync_acls.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public function execute($last_result, $parameters = array())
7979
// check if video exists in Stud.IP
8080
$video = Videos::findByEpisode($event->identifier);
8181

82+
$video->created = date('Y-m-d H:i:s', strtotime($event->created));
83+
$video->store();
84+
8285
if ($video->config_id != $config->id) {
8386
echo 'config id mismatch for Video with id: '. $video->id .", $config->id <> {$video->config_id}\n";
8487
continue;

lib/BlockTypes/OpencastBlockV3.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Opis\JsonSchema\Schema;
55
use Opencast\Models\VideoCoursewareBlocks;
66
use Opencast\Models\CoursewareBlockMappings;
7+
use Opencast\Models\Videos;
78
/**
89
* This class represents the content of a Courseware test block.
910
*
@@ -63,7 +64,10 @@ public function copyPayload(string $rangeId = ''): array
6364
$token = md5($this->block['id'] . time());
6465
$payload['copied_token'] = $token;
6566

66-
CoursewareBlockMappings::setRecord($token, $payload['token'], $rangeId);
67+
if (!empty($payload['token']) && Course::exists($rangeId)) {
68+
$video = Videos::findByToken($payload['token']);
69+
CoursewareBlockMappings::setRecord($token, $video->id, $rangeId);
70+
}
6771

6872
return $payload;
6973
}

lib/Models/Config.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,31 @@ public function updateEndpoints()
188188
$this->service_version = $version;
189189
$this->store();
190190

191-
Endpoints::setEndpoint($this->id, $service_host .'/services', 'services');
191+
$custom_config = [
192+
'config_id' => $this->id,
193+
'service_url' => $service_host,
194+
'service_user' => $this->service_user,
195+
'service_password' => $this->service_password,
196+
'service_version' => $this->service_version,
197+
'settings' => [
198+
'ssl_ignore_cert_errors' => $this->settings['ssl_ignore_cert_errors']
199+
]
200+
];
192201

193-
$services_client = new ServicesClient($this->id);
202+
$services_client = new ServicesClient($this->id, $custom_config);
194203

195204
$comp = null;
196205
try {
197206
$comp = $services_client->getRESTComponents();
198207
}
199-
catch(\Exception $e) {
200-
if (str_starts_with($e->getMessage(), 'cURL error 6')) {
208+
catch (\Exception $e) {
209+
if (str_starts_with($e->getMessage(), 'cURL error')) {
201210
return [
202211
'type' => 'error',
203212
'text' => sprintf(
204213
_('Die angegebene URL %s konnte nicht gefunden werden. Überprüfen Sie bitte ihre Eingabe und versuchen Sie es erneut.'),
205214
$service_host
206-
)
215+
) . " -> " . $e->getMessage()
207216
];
208217
}
209218
else {
@@ -217,8 +226,6 @@ public function updateEndpoints()
217226
}
218227
}
219228
} catch (AccessDeniedException $e) {
220-
Endpoints::removeEndpoint($this->id, 'services');
221-
222229
return [
223230
'type' => 'error',
224231
'text' => sprintf(
@@ -232,7 +239,6 @@ public function updateEndpoints()
232239
$services = RESTConfig::retrieveRESTservices($comp, $service_url);
233240

234241
if (empty($services)) {
235-
Endpoints::removeEndpoint($this->id, 'services');
236242
$message = [
237243
'type' => 'error',
238244
'text' => sprintf(

lib/Models/REST/IngestClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function createMediaPackage()
2828
{
2929
$response = $this->opencastApi->ingest->createMediaPackage();
3030

31-
if ($response['code'] == 200) {
31+
if (in_array($response['code'], [200, 201]) !== false) {
3232
return $response['body'];
3333
}
3434
return false;
@@ -47,7 +47,7 @@ public function addDCCatalog($mediaPackage, $dublinCore, $flavor = '')
4747
{
4848
$response = $this->opencastApi->ingest->addDCCatalog($mediaPackage, $dublinCore, $flavor);
4949

50-
if ($response['code'] == 200) {
50+
if (in_array($response['code'], [200, 201]) !== false) {
5151
return $response['body'];
5252
}
5353
return false;

lib/Models/REST/ServicesClient.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ class ServicesClient extends RestClient
88
{
99
public static $me;
1010

11-
public function __construct($config_id = 1)
11+
public function __construct($config_id = 1, $custom_config = null)
1212
{
1313
$this->serviceName = 'ServicesClient';
1414

15-
if ($config = Config::getConfigForService('services', $config_id)) {
15+
if ($custom_config) {
16+
parent::__construct($custom_config);
17+
} else if ($config = Config::getConfigForService('services', $config_id)) {
1618
parent::__construct($config);
1719
} else {
1820
throw new \Exception ($this->serviceName . ': '

lib/Models/ScheduleHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,11 @@ public static function getScheduleList($course_id, $semester_filter)
794794
$issue = new \Issue(['issue_id' => $is]);
795795
$titles[] = my_substr($issue->getTitle(), 0, 80);
796796
}
797-
$title = count($titles) ? 'Themen: ' . htmlReady(my_substr(implode(', ', $titles), 0, 80)) : '';
797+
$title = count($titles) ? 'Themen: ' . my_substr(implode(', ', $titles), 0, 80) : '';
798798
} else {
799799
foreach ($issues as $is) {
800800
$issue = new \Issue(['issue_id' => $is]);
801-
$title = htmlReady(my_substr($issue->getTitle(), 0, 80));
801+
$title = my_substr($issue->getTitle(), 0, 80);
802802
}
803803
}
804804
}

0 commit comments

Comments
 (0)