Skip to content

Commit

Permalink
Merge branch 'main' into issue-182_oc-php-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Nov 3, 2023
2 parents 04adccf + 94f02e4 commit 3de7def
Show file tree
Hide file tree
Showing 22 changed files with 276 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [5.3.0]
- Implemented #193: The Chunk Size for Uploads is now configurable. The default value is 20MB, this can be changes in the plugin configuration.
- Fix #176: Fixed a static timeout in fileuploads, this now uses max_execution_time of the server.

## [5.2.0]
- Version 5.2.0 contains a large number of refactorings. The ILIAS 7 compatible version is continuously refactored so that an update to ILIAS 8 is easier possible. For example, libraries that are no longer compatible have to be removed. In this first step the internal use of srg/dic was removed.
- With the new release the plugin uses the new php-library `elan-ev/opencast-api` in version 1.4.0 for all API calls to Opencast.
Expand Down
36 changes: 31 additions & 5 deletions classes/Conf/class.xoctConfFormGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use srag\Plugins\Opencast\Model\Config\PluginConfig;
use srag\Plugins\Opencast\Model\User\xoctUser;
use srag\Plugins\Opencast\DI\OpencastDIC;

/**
* Class xoctConfFormGUI
Expand All @@ -25,12 +26,26 @@ class xoctConfFormGUI extends ilPropertyFormGUI
* @var string
*/
protected $subtab_active;
/**
* @var ilOpenCastPlugin
*/
protected $plugin;
/**
* @var \ilGlobalTemplateInterface
*/
private $main_tpl;

/**
* @param $parent_gui
*/
public function __construct(xoctConfGUI $parent_gui, $subtab_active)
{
global $DIC;
$container = OpencastDIC::getInstance();
$this->main_tpl = $DIC->ui()->mainTemplate();
$this->plugin = $container->plugin();
$this->main_tpl->addJavaScript($this->plugin->getDirectory().'/js/opencast/dist/index.js');
$this->main_tpl->addCss($this->plugin->getStyleSheetLocation('default/password_toggle.css'));
parent::__construct();
$this->parent_gui = $parent_gui;
$this->subtab_active = $subtab_active;
Expand Down Expand Up @@ -159,6 +174,9 @@ public static function checkItem($item)
*/
protected function initAPISection()
{
$code = "il.Opencast.Form.passwordToggle.init('" . PluginConfig::F_CURL_PASSWORD . "');";
$this->main_tpl->addOnLoadCode($code);

$h = new ilFormSectionHeaderGUI();
$h->setTitle($this->parent_gui->txt('curl'));
$this->addItem($h);
Expand All @@ -184,10 +202,8 @@ protected function initAPISection()
$this->addItem($te);
}

/**
*
*/
protected function initEventsSection()

protected function initEventsSection(): void
{
$h = new ilFormSectionHeaderGUI();
$h->setTitle($this->parent_gui->txt('events'));
Expand All @@ -203,7 +219,17 @@ protected function initEventsSection()
PluginConfig::F_CURL_MAX_UPLOADSIZE
);
$te->setInfo($this->parent_gui->txt(PluginConfig::F_CURL_MAX_UPLOADSIZE . '_info'));
$te->setRequired(false);
$te->setRequired(true);
$this->addItem($te);

$te = new ilNumberInputGUI(
$this->parent_gui->txt(PluginConfig::F_CURL_CHUNK_SIZE),
PluginConfig::F_CURL_CHUNK_SIZE
);
$te->setInfo($this->parent_gui->txt(PluginConfig::F_CURL_CHUNK_SIZE . '_info'));
$te->setRequired(true);
$te->setMinValue(1, true);
$te->setMaxValue(\ilUtil::getUploadSizeLimitBytes() / 1024 / 1024 / 2, true);
$this->addItem($te);

$te = new ilTextInputGUI(
Expand Down
11 changes: 6 additions & 5 deletions classes/Event/class.xoctEventGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ protected function create()
$this->ACLUtils->getBaseACLForUser(xoctUser::getInstance($this->user)),
new Processing(
PluginConfig::getConfig(PluginConfig::F_WORKFLOW),
$data['workflow_configuration']['object'] ?? $this->getDefaultWorkflowParameters()
$this->getDefaultWorkflowParameters($data['workflow_configuration']['object'])
),
xoctUploadFile::getInstanceFromFileArray($data['file']['file'])
)
Expand All @@ -675,15 +675,16 @@ protected function create()
$this->ctrl->redirect($this, self::CMD_STANDARD);
}

public function getDefaultWorkflowParameters(): \stdClass
public function getDefaultWorkflowParameters(?\stdClass $fromData = null): \stdClass
{
$WorkflowParameter = new WorkflowParameter();
$defaultParameter = new stdClass();
$defaultParameter = $fromData ?? new stdClass();
$admin = ilObjOpenCastAccess::hasPermission('edit_videos');
foreach ($WorkflowParameter::get() as $param) {
$id = $param->getId();
$defaultValue = $admin ? $param->getDefaultValueAdmin() : $param->getDefaultValueMember();
if ($defaultValue == WorkflowParameter::VALUE_ALWAYS_ACTIVE) {
$id = $param->getId();

if (!isset($fromData->$id) && $defaultValue == WorkflowParameter::VALUE_ALWAYS_ACTIVE) {
$defaultParameter->$id = "true";
}
}
Expand Down
1 change: 1 addition & 0 deletions js/opencast/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions js/opencast/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {terser} from 'rollup-plugin-terser';

export default {
external: [
'document',
'ilias',
'jquery',
],
input: './src/index.js',
output: {
file: './dist/index.js',
format: 'iife',
globals: {
document: 'document',
ilias: 'il',
jquery: '$',
}
},
plugins: [terser()]
};
123 changes: 123 additions & 0 deletions js/opencast/src/Form/PasswordToggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* PasswordToggle
*
* PasswordToggle class
*
* @author Fabian Schmid <fs@studer-raimann.ch>
* @author Farbod Zamani Boroujeni <zamani@elan-ev.de>
*/
export default class PasswordToggle {
/**
* @type {jQuery}
*/
jquery;
/**
* @type {Array<string>}
*/
password_input_ids;

constructor(
jquery,
){
this.jquery = jquery;
this.password_input_ids = [];
}


/**
* Init
* This function is designed to handle multiple password inputs, masking all at the same time.
* @param {string} password_input_ids_json_string possible values for this are:
* string: json encoded array of inputs like '["curl_password"]'
* string: single input id like: 'curl_password'
*/
init(password_input_ids_json_string) {
try {
let password_input_ids = JSON.parse(password_input_ids_json_string);
if (Array.isArray(password_input_ids)) {
this.password_input_ids = password_input_ids;
}
} catch (e) {
if (password_input_ids_json_string !== '') {
this.password_input_ids = [password_input_ids_json_string];
}
}

if (!Array.isArray(this.password_input_ids) || this.password_input_ids.length === 0) {
console.warn('Unable to find any input to mask!');
return;
}

var self = this;

$(document).ready(function () {
$('.xoct_pw_toggle_item').click( function(e) {
let element = e.target.nodeName == 'IMG' ? e.target.parentNode : e.element;
let toggle_element = $(element).siblings('.xoct_pw_toggle_item');
let input_siblings = $(element.parentNode).siblings('input');
if (input_siblings && input_siblings.length > 0) {
let password_input = input_siblings[0];
if ($(element).hasClass('toggle-show')) {
$(password_input).attr('type', 'text');
} else {
$(password_input).attr('type', 'password');
}
}

$(element).hide();
$(toggle_element).show();
});
});

this.password_input_ids.forEach(function (password_input_id, index) {
self.wrapper(password_input_id);
});
}


/**
* Wrapper function
* This function prepares the masking elements and wrap them around the password input element.
* @param {string} password_input_id The id of the password input element
*/
wrapper (password_input_id) {
let password_input = document.getElementById(password_input_id);
if (!password_input) {
return;
}
password_input.setAttribute('type', 'password');

let show_icon = document.createElement("img");
show_icon.setAttribute('alt', 'show password');
show_icon.setAttribute('class', 'xoct_pw_icon xoct_pw_eye');
show_icon.setAttribute('src', './Customizing/global/plugins/Services/Repository/RepositoryObject/OpenCast/templates/images/eye.svg');
let show_div = document.createElement('div');
show_div.setAttribute('class', 'xoct_pw_toggle_item toggle-show');
show_div.appendChild(show_icon);
let hide_icon = document.createElement("img");
hide_icon.setAttribute('alt', 'hide password');
hide_icon.setAttribute('class', 'xoct_pw_icon xoct_pw_eye-slash');
hide_icon.setAttribute('src', './Customizing/global/plugins/Services/Repository/RepositoryObject/OpenCast/templates/images/eye-slash.svg');
let hide_div = document.createElement('div');
hide_div.setAttribute('class', 'xoct_pw_toggle_item toggle-hide');
hide_div.appendChild(hide_icon);

let container_div = document.createElement('div');
container_div.setAttribute('class','xoct_pw_toggle_container');

container_div.appendChild(show_div);
container_div.appendChild(hide_div);

let current_parent = password_input.parentElement;
current_parent.classList.add('xoct_pw_main_container');

let wrapper_div = document.createElement('div');
wrapper_div.setAttribute('class', 'xoct_pw_wrapper');

wrapper_div.appendChild(password_input);
wrapper_div.appendChild(container_div);

current_parent.prepend(wrapper_div);
}

}
7 changes: 7 additions & 0 deletions js/opencast/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import il from 'ilias';
import $ from 'jquery';
import PasswordToggle from './Form/PasswordToggle';

il.Opencast = il.Opencast || {};
il.Opencast.Form = il.Opencast.Form || {};
il.Opencast.Form.passwordToggle = new PasswordToggle($);
2 changes: 2 additions & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ config_api_version#:#API-Version
config_api_version_info#:#Format: vX.Y.Z - z.B.: v1.0.0
config_curl_max_upload_size#:#Maximale Upload-Größe in MB
config_curl_max_upload_size_info#:#Definiert die maximal mögliche Uploadgröße für Video-Dateien in MB
config_curl_chunk_size#:#Chunk-Größe in MB
config_curl_chunk_size_info#:#Definiert die Grösse der einzelnen Upload-Chunks in MB. Grosse Dateien werden in einzelnen Teilen (Chunks) hochgeladen. Kleinere Chunks sind besser bei langsamen Internet-Verbindungen, grössere Chunks sind besser bei schnellen Internetverbindungen.
config_audio_allowed#:#Audio-Dateien
config_cancel#:#Abbrechen
config_create_scheduled_allowed#:#"Aufzeichnungstermin(e) planen" erlauben
Expand Down
2 changes: 2 additions & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ config_api_version#:#API Version
config_api_version_info#:#Format: vX.Y.Z - e.g.: v1.0.0
config_curl_max_upload_size#:#Max. File-Size in MB
config_curl_max_upload_size_info#:#Defines the maximum possible upload size for video files in MB
config_curl_chunk_size#:#Chunk size in MB
config_curl_chunk_size_info#:#Defines the size of individual upload chunks in MB. Large files are uploaded in single parts (chunks). Smaller chunks are better for slow internet connections, larger chunks are better for fast internet connections.
config_audio_allowed#:#Audio Files
config_cancel#:#Cancel
config_create_scheduled_allowed#:#Activate "Schedule Event(s)"
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$id = 'xoct';
$version = '5.2.1';
$version = '5.3.1';
$version_check = '44ac530093a998b525b0a73ba536e64f03bbaff47446cf99e1a31d6a042a4549';
$ilias_min_version = '6.0';
$ilias_max_version = '7.999';
Expand Down
12 changes: 11 additions & 1 deletion sql/dbupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,17 @@
?>
<#41>
<?php
/** @var $ilDB ilDBInterface */
$res = $ilDB->queryF('SELECT value FROM xoct_config WHERE name = %s', ['text'], ['curl_chunk_size']);
if ($res->rowCount() === 0) {
$ilDB->insert('xoct_config', [
'name' => ['text', 'curl_chunk_size'],
'value' => ['text', '20']
]);
}
?>
<#42>
<?php
// Introducing PublicationUsageGroup for grouping PublicationUsage.
\srag\Plugins\Opencast\Model\Publication\Config\PublicationUsageGroup::updateDB();
// Introducing PublicationSubUsage as for sub usages.
Expand Down Expand Up @@ -501,5 +512,4 @@
$publication_subusage->update();
}
}

?>
5 changes: 4 additions & 1 deletion src/Container/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ static function () {
PluginConfig::getConfig(PluginConfig::F_API_BASE) ?? 'https://stable.opencast.org/api',
PluginConfig::getConfig(PluginConfig::F_CURL_USERNAME) ?? 'admin',
PluginConfig::getConfig(PluginConfig::F_CURL_PASSWORD) ?? 'opencast',
PluginConfig::getConfig(PluginConfig::F_API_VERSION) ?? '1.9.0'
PluginConfig::getConfig(PluginConfig::F_API_VERSION) ?? '1.9.0',
0,
0,
PluginConfig::getConfig(PluginConfig::F_PRESENTATION_NODE) ?? null
);
});

Expand Down
1 change: 1 addition & 0 deletions src/Model/Config/PluginConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PluginConfig extends ActiveRecord
public const F_CURL_USERNAME = 'curl_username';
public const F_CURL_PASSWORD = 'curl_password';
public const F_CURL_MAX_UPLOADSIZE = 'curl_max_upload_size';
public const F_CURL_CHUNK_SIZE = 'curl_chunk_size';
public const F_WORKFLOW = 'workflow';
public const F_WORKFLOW_UNPUBLISH = 'workflow_unpublish';
public const F_EULA = 'eula';
Expand Down
3 changes: 3 additions & 0 deletions src/Model/Metadata/Helper/MDParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ private function parseAPIResponseGeneric(array $fields, Metadata $metadata, MDCa
}
} else {
$key = array_search($fieldDefinition->getId(), array_column($fields, 'id'));
if ($key === false) {
continue;
}
$field = $fields[$key];
}
$metadata->addField(
Expand Down
5 changes: 5 additions & 0 deletions src/UI/EventFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,14 @@ public function upload(string $form_action, bool $with_terms_of_use, int $obj_id
? $configured_upload_limit * self::MB_IN_B
: self::DEFAULT_UPLOAD_LIMIT_IN_MIB * self::MB_IN_B;

// Chunk Size
$chunk_size = (int) PluginConfig::getConfig(PluginConfig::F_CURL_CHUNK_SIZE);
$chunk_size = $chunk_size > 0 ? $chunk_size * 1024 * 1024 : \ilUtil::getUploadSizeLimitBytes();

$file_input = $file_input->withAcceptedMimeTypes($this->getMimeTypes())
->withRequired(true)
->withMaxFileSize($upload_limit)
->withChunkSizeInBytes($chunk_size)
->withAdditionalTransformation(
$this->refinery_factory->custom()->transformation(
function ($file) use ($upload_storage_service): array {
Expand Down
14 changes: 14 additions & 0 deletions src/UI/Form/ChunkedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class ChunkedFile extends File
{
protected $chunk_size = 1;

public function __construct(
DataFactory $data_factory,
Factory $refinery,
Expand Down Expand Up @@ -42,6 +44,18 @@ public static function getInstance(
));
}

public function withChunkSizeInBytes(int $chunk_size_in_bytes): self
{
$clone = clone $this;
$clone->chunk_size = $chunk_size_in_bytes;
return $clone;
}

public function getChunkSizeInBytes(): int
{
return $this->chunk_size;
}

protected function isClientSideValueOk($value): bool
{
if (is_null($value)) {
Expand Down
Loading

0 comments on commit 3de7def

Please sign in to comment.