Skip to content

Commit

Permalink
refs #800, use token to redirect to correct video
Browse files Browse the repository at this point in the history
  • Loading branch information
tgloeggl committed Oct 10, 2023
1 parent 6bf72c8 commit f030cd9
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 34 deletions.
4 changes: 2 additions & 2 deletions app/controllers/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function before_filter(&$action, &$args)
public function perform_action($action, $token)
{
$video = null;
$$video_share = null;
$video_share = null;
if ($action == 'share') {
$video_share = VideosShares::findByToken($token);
$video = Videos::findById($video_share->video_id);
Expand All @@ -54,7 +54,7 @@ public function perform_action($action, $token)
$customtool = $this->getLtiCustomTool($video, $action);
$lti = LtiHelper::getLaunchData($video->config_id, $customtool, $video_share);
if (empty($lti) || empty($customtool)) {
throw new Error('Es fehlen Parameter!', 422);
throw new Error('Could not load video!', 422);
}

// get correct endpoint for redirect type
Expand Down
18 changes: 7 additions & 11 deletions courseware/vueapp/courseware-plugin-opencast-video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
>
<template #content>
<div>
<span v-if="!currentEpisodeId" v-translate v-text="'Es wurde bisher kein Video ausgewählt'"></span>
<span v-if="!currentVideoId" v-translate v-text="'Es wurde bisher kein Video ausgewählt'"></span>
<span v-else-if="!currentEpisodeURL" v-translate v-text="'Dieses Video hat keinen Veröffentlichungs-URL-Link'"></span>
<iframe v-else :src="currentEpisodeURL"
class="oc_cw_iframe"
Expand Down Expand Up @@ -86,7 +86,6 @@ export default {
videos: {},
loadingVideos : false,
currentVideoId : null,
currentEpisodeId : null,
currentEpisodeURL : null,
currentVisible : '',
}
Expand Down Expand Up @@ -115,6 +114,7 @@ export default {
companionError: 'companionError',
updateBlock: 'updateBlockInContainer',
}),
resetPaging() {
this.paging = {
currPage: 0,
Expand All @@ -141,9 +141,8 @@ export default {
},
performSelectVideo(video) {
this.currentVideoId = video.id;
this.currentEpisodeId = video.episode;
this.currentEpisodeURL = video?.publication?.track_link || '';
this.currentVideoId = video.token;
this.currentEpisodeURL = STUDIP.ABSOLUTE_URI_STUDIP + 'plugins.php/opencast/redirect/perform/video/' + video.token;
this.currentVisible = video?.visibility || 'public';
},
Expand All @@ -156,9 +155,7 @@ export default {
}
let attributes = {};
attributes.payload = {};
attributes.payload.video_id = this.currentVideoId;
attributes.payload.episode_id = this.currentEpisodeId;
attributes.payload.url = this.currentEpisodeURL;
attributes.payload.token = this.currentVideoId;
attributes.payload.visible = this.currentVisible;
if (this.container?.id && this.block?.id) {
Expand All @@ -175,9 +172,8 @@ export default {
},
initCurrentData() {
this.currentVideoId = get(this.block, "attributes.payload.video_id", "");
this.currentEpisodeId = get(this.block, "attributes.payload.episode_id", "");
this.currentEpisodeURL = get(this.block, "attributes.payload.url", "");
this.currentVideoId = get(this.block, "attributes.payload.token", "");
this.currentEpisodeURL =STUDIP.ABSOLUTE_URI_STUDIP + 'plugins.php/opencast/redirect/perform/video/' + this.currentVideoId;
this.currentVisible = get(this.block, "attributes.payload.visible", "");
let copied_from = get(this.block, "attributes.payload.copied_from", "");
Expand Down
2 changes: 1 addition & 1 deletion cronjobs/opencast_courseware_block_copy_mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function execute($last_result, $parameters = array())

// Add record into the VideoCoursewareBlocks
$msg = 'Record is added into oc_video_cw_blocks';
$added = VideoCoursewareBlocks::setRecord($mapping->new_seminar_id, $mapping->video_id, $new_block_record['id']);
$added = VideoCoursewareBlocks::setRecord($mapping->new_seminar_id, $mapping->token, $new_block_record['id']);
if (!$added) {
$msg = 'No record is added into oc_video_cw_blocks!';
}
Expand Down
10 changes: 2 additions & 8 deletions lib/BlockTypes/OpencastBlock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
"title": "Payload schema of OpencastBlock",
"type": "object",
"properties": {
"episode_id": {
"type": "string"
},
"url": {
"type": "string"
},
"video_id" : {
"token" : {
"type": "string"
},
"visible": {
Expand All @@ -18,6 +12,6 @@
"type": "string"
}
},
"required": ["episode_id", "url"],
"required": ["token"],
"additionalProperties": false
}
7 changes: 3 additions & 4 deletions lib/BlockTypes/OpencastBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static function getDescription(): string
public function initialPayload(): array
{
return [
'id' => '',
'url' => ''
'token' => ''
];
}

Expand Down Expand Up @@ -64,15 +63,15 @@ public function copyPayload(string $rangeId = ''): array
$token = md5($this->block['id'] . time());
$payload['copied_token'] = $token;

CoursewareBlockMappings::setRecord($token, $payload['video_id'], $rangeId);
CoursewareBlockMappings::setRecord($token, $payload['token'], $rangeId);

return $payload;
}

public function setPayload($payload): void
{
$rangeId = $this->block->container->structural_element->range_id;
VideoCoursewareBlocks::setRecord($rangeId, $payload['video_id'], $this->block['id']);
VideoCoursewareBlocks::setRecord($rangeId, $payload['token'], $this->block['id']);
parent::setPayload($payload);
}
}
16 changes: 8 additions & 8 deletions lib/Models/VideoCoursewareBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ protected static function configure($config = [])
}
/**
* Adds or updates a video courseware block record
*
* @param string $seminar_id id of course
* @param int $video_id id of video
* @param string $block_id id of block
*
*
* @param string $seminar_id id of course
* @param int $token token of video
* @param string $block_id id of block
*
* @return bool
* @throws Exception
*/
public static function setRecord($seminar_id, $video_id, $block_id)
public static function setRecord($seminar_id, $token, $block_id)
{
// Preventing record entry except for a course!
if (empty($seminar_id) || !Course::find($seminar_id)) {
return false;
}

if (!empty($seminar_id) && !empty($video_id) && !empty($block_id)) {
if (!empty($seminar_id) && !empty($token) && !empty($block_id)) {
if (!$video_cw = self::findOneBySQL('block_id = ? AND seminar_id = ?', [$block_id, $seminar_id])) {
$video_cw = new self();
}

$video_cw->setData(compact('seminar_id', 'video_id', 'block_id'));
$video_cw->setData(compact('seminar_id', 'token', 'block_id'));
return $video_cw->store();
} else {
throw new \Exception(_('Falsche Informationen zum Speichern von Daten.'));
Expand Down
64 changes: 64 additions & 0 deletions migrations/077_update_cw_block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
class UpdateCwBlock extends Migration
{
public function up()
{
$db = DBManager::get();

$results = $db->query("SELECT DISTINCT video_id, oc_video.token
FROM oc_video_cw_blocks
LEFT JOIN oc_video ON (oc_video.id = oc_video_cw_blocks.video_id)
");
$entries = $results->fetchAll(PDO::FETCH_ASSOC);

$db->exec('START TRANSACTION');

$db->exec('ALTER TABLE oc_video_cw_blocks
ADD `token` varchar(12) AFTER video_id');


$stmt = $db->prepare('UPDATE oc_video_cw_blocks
SET token = :token
WHERE video_id = :video_id
');

foreach ($entries as $data) {
// update mapping table
$stmt->execute([
':token' => $data['token'],
':video_id' => $data['video_id']
]);

// update block payloads
$db->exec($q = "UPDATE cw_blocks
SET payload = REPLACE(payload, '\"video_id\":\"". $data['video_id'] ."\"', '\"token\":\"". $data['token'] ."\"')
WHERE payload LIKE '%\"video_id\":\"". $data['video_id'] ."\"%'
AND block_type = 'plugin-opencast-video'
");
}

$db->exec('ALTER TABLE oc_video_cw_blocks
DROP FOREIGN KEY `oc_video_cw_blocks_ibfk_1`
');

$db->exec('ALTER TABLE oc_video_cw_blocks
ADD PRIMARY KEY `token_block_id` (`token`, `block_id`),
DROP INDEX `PRIMARY`
');

$db->exec('ALTER TABLE oc_video_cw_blocks
ADD CONSTRAINT `token` FOREIGN KEY (`token`) REFERENCES `oc_video` (`token`) ON DELETE CASCADE ON UPDATE RESTRICT
');

$db->exec('ALTER TABLE oc_video_cw_blocks
DROP video_id
');

$db->exec('COMMIT');
}

public function down()
{

}
}

0 comments on commit f030cd9

Please sign in to comment.