Skip to content

Commit

Permalink
Dynamic video size limitation for chunkuploader settings (#409)
Browse files Browse the repository at this point in the history
* more dynamic video size limitation for chunkuploader settings,
This PR fixes #376

* missing setting dependency

---------

Co-authored-by: Thomas Niedermaier <[email protected]>
  • Loading branch information
ferishili and bluetom authored Jan 13, 2025
1 parent a68896a commit 2862949
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 17 deletions.
9 changes: 7 additions & 2 deletions batchupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@
if ($series) {
$customdata['series'] = $series;
}
$maxuploadsize = (int) get_config('block_opencast', 'uploadfilelimit_' . $ocinstanceid);

$uploadfilesizelimitmode = (int) get_config('block_opencast', 'uploadfilesizelimitmode_' . $ocinstanceid);
$maxuploadsize = defined('USER_CAN_IGNORE_FILE_SIZE_LIMITS') ? USER_CAN_IGNORE_FILE_SIZE_LIMITS : -1; // Unlimited.
if ($uploadfilesizelimitmode !== 1) { // The flag for unlimited size is "1", and "0" for limited.
$maxuploadsize = (int) get_config('block_opencast', 'uploadfilelimit_' . $ocinstanceid);
}

$videotypescfg = get_config('block_opencast', 'uploadfileextensions_' . $ocinstanceid);
if (empty($videotypescfg)) {
Expand All @@ -157,7 +162,7 @@

$filemanageroptions = [
'accepted_types' => $videotypes,
'maxbytes' => $maxuploadsize ,
'maxbytes' => $maxuploadsize,
'subdirs' => false,
'maxfiles' => -1,
'mainfile' => false,
Expand Down
6 changes: 5 additions & 1 deletion classes/local/addvideo_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ public function definition() {
}
}

$maxuploadsize = (int)get_config('block_opencast', 'uploadfilelimit_' . $ocinstanceid);
$uploadfilesizelimitmode = (int) get_config('block_opencast', 'uploadfilesizelimitmode_' . $ocinstanceid);
$maxuploadsize = defined('USER_CAN_IGNORE_FILE_SIZE_LIMITS') ? USER_CAN_IGNORE_FILE_SIZE_LIMITS : -1; // Unlimited.
if ($uploadfilesizelimitmode !== 1) { // The flag for unlimited size is "1", and "0" for limited.
$maxuploadsize = (int) get_config('block_opencast', 'uploadfilelimit_' . $ocinstanceid);
}

$presenterdesc = html_writer::tag('p', get_string('presenterdesc', 'block_opencast'));
$mform->addElement('html', $presenterdesc);
Expand Down
31 changes: 29 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,37 @@ function xmldb_block_opencast_upgrade($oldversion) {
upgrade_block_savepoint(true, 2024093000, 'opencast');
}

// Taking care of new "location" metadata field for events.
if ($oldversion < 2024111103) {
// First, we read all the current "metadata" config settings if exist.

// Taking care of new dynamic file size limitation chunkuploader config settings.
// First, we read all the current "uploadfilelimit" config settings if exist.
$params = ['plugin' => 'block_opencast', 'configname' => 'uploadfilelimit%'];
$whereclause = $DB->sql_equal('plugin', ':plugin') . ' AND ' . $DB->sql_like('name', ':configname');
if ($entries = $DB->get_records_select('config_plugins', $whereclause, $params, '', 'name, value')) {
$defaultfilelimit = 2147483648; // It is 2 GB default.
$limitedmodeflag = 0;
$unlimitedmodeflag = 1;
foreach ($entries as $entry) {
// We prepate the config names, by a simple replacement to maintain the ocinstance number at the end.
$newconfigname = str_replace('uploadfilelimit', 'uploadfilesizelimitmode', $entry->name);
// We decide the value,
// if the value is "-1", then it is unlimited, otherwise it is limited.
$value = (int) $entry->value;
// Unlimited.
if ($value === -1) {
// We set the "uploadfilesizelimitmode" to "1" (unlimited).
set_config($newconfigname, $unlimitedmodeflag, 'block_opencast');
// We set the "uploadfilelimit" to the default value of 2 GB.
set_config($entry->name, $defaultfilelimit, 'block_opencast');
} else { // Limited.
// We only set the "uploadfilesizelimitmode" to "0" (limited), and NO change for "uploadfilelimit".
set_config($newconfigname, $limitedmodeflag, 'block_opencast');
}
}
}

// Taking care of new "location" metadata field for events.
// First, we read all the current "metadata" config settings if exist.
$params = ['plugin' => 'block_opencast', 'configname' => '%metadata\_%'];
$whereclause = $DB->sql_equal('plugin', ':plugin') . ' AND ' . $DB->sql_like('name', ':configname');
if ($entries = $DB->get_records_select('config_plugins', $whereclause, $params, '', 'name, value')) {
Expand Down
6 changes: 6 additions & 0 deletions lang/en/block_opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@
$string['unarchiveuploadjobconfirmbtn_save'] = 'Proceed';
$string['unarchiveuploadjobconfirmtext'] = 'You are about to unarchive the video upload job. Please ensure that the upload issue has been resolved. Would you like to proceed?';
$string['unexpected_api_response'] = 'Unexpected API response.';
$string['unlimiteduploadfilesize'] = 'Unlimited Video Size';
$string['unlimiteduploadfilesize_desc'] = 'If enabled, there is no size limit to the video being upload. If you want to apply the size limit, make sure to diable this option, then you will be offered to enter the video size limit in respected setting.';
$string['updatemetadata'] = 'Update metadata for this event';
$string['updatemetadata_massaction'] = 'Update metadata for selected video(s)';
$string['updatemetadata_massaction_emptyformsubmission'] = 'At least one field must be enabled.';
Expand All @@ -854,6 +856,10 @@
$string['uploadfileextensionsdesc'] = 'Comma separated list of allowed video file extensions (extensions must exist in Moodle\'s <a href="{$a}">File types</a> list). If left blank all extensions with type group \'video\' are allowed (again see <a href="{$a}">File types</a>).';
$string['uploadfilelimit'] = 'Video size limit';
$string['uploadfilelimitdesc'] = 'Limit the file size of uploaded videos through the chunkupload.';
$string['uploadfilesizelimited'] = 'Limited video size';
$string['uploadfilesizelimitmode'] = 'Video file size limitation mode';
$string['uploadfilesizelimitmode_desc'] = 'Use this option to specify whether to limit the video file size. If "Limited video size" is selected, you can define the video size limit in the corresponding setting.';
$string['uploadfilesizeunlimited'] = 'Unlimited video Size';
$string['uploadingeventfailed'] = 'Creating of event failed';
$string['uploadjobnotfound'] = 'The video upload job could not be found.';
$string['uploadjobssaved'] = 'Video upload successful.<br />The video is scheduled to be transferred to Opencast now. You do not need to wait on this page for this transfer to finish.';
Expand Down
40 changes: 28 additions & 12 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use block_opencast\setting_helper;
use block_opencast\setting_default_manager;
use core\notification;
use core_admin\local\settings\filesize;
use tool_opencast\empty_configuration_exception;
use tool_opencast\local\environment_util;
use tool_opencast\local\settings_api;
Expand Down Expand Up @@ -432,21 +433,36 @@
get_string('enablechunkupload', 'block_opencast'),
get_string('enablechunkupload_desc', 'block_opencast'), true));

$sizelist = [-1, 53687091200, 21474836480, 10737418240, 5368709120, 2147483648, 1610612736, 1073741824,
536870912, 268435456, 134217728, 67108864, ];
$filesizes = [];
foreach ($sizelist as $sizebytes) {
$filesizes[(string)intval($sizebytes)] = display_size($sizebytes);
}
// File size limitation mode config setting.
$uploadsizelimitmodes = [
0 => get_string('uploadfilesizelimited', 'block_opencast'), // Limited.
1 => get_string('uploadfilesizeunlimited', 'block_opencast'), // Unlimited.
];

$defaultsizelimitmode = 1; // Unlimited as default.

$additionalsettings->add(new admin_setting_configselect('block_opencast/uploadfilesizelimitmode_' . $instance->id,
get_string('uploadfilesizelimitmode', 'block_opencast'),
get_string('uploadfilesizelimitmode_desc', 'block_opencast'),
$defaultsizelimitmode, $uploadsizelimitmodes));

$additionalsettings->hide_if('block_opencast/uploadfilesizelimitmode_' . $instance->id,
'block_opencast/enablechunkupload_' . $instance->id, 'notchecked');

$additionalsettings->add(new admin_setting_configselect('block_opencast/uploadfilelimit_' . $instance->id,
// Dynamic file size limit config setting.
$defaultuploadfilelimit = 2 * filesize::UNIT_GB;
$additionalsettings->add(new filesize(
'block_opencast/uploadfilelimit_' . $instance->id,
get_string('uploadfilelimit', 'block_opencast'),
get_string('uploadfilelimitdesc', 'block_opencast'),
2147483648, $filesizes));
if ($CFG->branch >= 37) { // The hide_if functionality for admin settings is not available before Moodle 3.7.
$additionalsettings->hide_if('block_opencast/uploadfilelimit_' . $instance->id,
'block_opencast/enablechunkupload_' . $instance->id, 'notchecked');
}
$defaultuploadfilelimit,
filesize::UNIT_GB
));
// Double dependencies.
$additionalsettings->hide_if('block_opencast/uploadfilelimit_' . $instance->id,
'block_opencast/uploadfilesizelimitmode_' . $instance->id, 'eq', 1);
$additionalsettings->hide_if('block_opencast/uploadfilelimit_' . $instance->id,
'block_opencast/enablechunkupload_' . $instance->id, 'notchecked');

$additionalsettings->add(
new admin_setting_configcheckbox('block_opencast/offerchunkuploadalternative_' . $instance->id,
Expand Down

0 comments on commit 2862949

Please sign in to comment.