From 67b5a6ec855262477c360b6001223a829d970385 Mon Sep 17 00:00:00 2001 From: ferishili Date: Fri, 20 Dec 2024 13:12:53 +0100 Subject: [PATCH 1/2] more dynamic video size limitation for chunkuploader settings, This PR fixes #376 --- batchupload.php | 9 +++++++-- classes/local/addvideo_form.php | 6 +++++- db/upgrade.php | 30 +++++++++++++++++++++++++++ lang/en/block_opencast.php | 6 ++++++ settings.php | 36 ++++++++++++++++++++++----------- version.php | 2 +- 6 files changed, 73 insertions(+), 16 deletions(-) diff --git a/batchupload.php b/batchupload.php index 568cfef7..6a75abe2 100644 --- a/batchupload.php +++ b/batchupload.php @@ -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)) { @@ -157,7 +162,7 @@ $filemanageroptions = [ 'accepted_types' => $videotypes, - 'maxbytes' => $maxuploadsize , + 'maxbytes' => $maxuploadsize, 'subdirs' => false, 'maxfiles' => -1, 'mainfile' => false, diff --git a/classes/local/addvideo_form.php b/classes/local/addvideo_form.php index 1137d82d..aeb4cb23 100644 --- a/classes/local/addvideo_form.php +++ b/classes/local/addvideo_form.php @@ -348,7 +348,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); diff --git a/db/upgrade.php b/db/upgrade.php index db571bb1..9f1565ba 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -885,5 +885,35 @@ function xmldb_block_opencast_upgrade($oldversion) { upgrade_block_savepoint(true, 2024093000, 'opencast'); } + // Taking care of new dynamic file size limitation chunkuploader config settings. + if ($oldversion < 2024111103) { + // 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'); + } + } + } + upgrade_block_savepoint(true, 2024111103, 'opencast'); + } + return true; } diff --git a/lang/en/block_opencast.php b/lang/en/block_opencast.php index aa97fb7d..2987f629 100644 --- a/lang/en/block_opencast.php +++ b/lang/en/block_opencast.php @@ -835,6 +835,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.'; @@ -851,6 +853,10 @@ $string['uploadfileextensionsdesc'] = 'Comma separated list of allowed video file extensions (extensions must exist in Moodle\'s File types list). If left blank all extensions with type group \'video\' are allowed (again see File types).'; $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.
The video is scheduled to be transferred to Opencast now. You do not need to wait on this page for this transfer to finish.'; diff --git a/settings.php b/settings.php index 1e730221..47b16fc6 100644 --- a/settings.php +++ b/settings.php @@ -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; @@ -432,21 +433,32 @@ 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/uploadfilelimit_' . $instance->id, + $additionalsettings->add(new admin_setting_configselect('block_opencast/uploadfilesizelimitmode_' . $instance->id, + get_string('uploadfilesizelimitmode', 'block_opencast'), + get_string('uploadfilesizelimitmode_desc', 'block_opencast'), + $defaultsizelimitmode, $uploadsizelimitmodes)); + + // 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 + )); + $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, diff --git a/version.php b/version.php index 47ec07f5..4c2ea166 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ $plugin->component = 'block_opencast'; $plugin->release = 'v4.5-r3'; -$plugin->version = 2024111102; +$plugin->version = 2024111103; $plugin->requires = 2024100700; // Requires Moodle 4.5+. $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = [ From 6444159579e70aa54e939e6b673c61b39901c653 Mon Sep 17 00:00:00 2001 From: ferishili Date: Fri, 20 Dec 2024 13:36:31 +0100 Subject: [PATCH 2/2] missing setting dependency --- settings.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/settings.php b/settings.php index 47b16fc6..1c71fcdd 100644 --- a/settings.php +++ b/settings.php @@ -446,6 +446,9 @@ get_string('uploadfilesizelimitmode_desc', 'block_opencast'), $defaultsizelimitmode, $uploadsizelimitmodes)); + $additionalsettings->hide_if('block_opencast/uploadfilesizelimitmode_' . $instance->id, + 'block_opencast/enablechunkupload_' . $instance->id, 'notchecked'); + // Dynamic file size limit config setting. $defaultuploadfilelimit = 2 * filesize::UNIT_GB; $additionalsettings->add(new filesize( @@ -455,6 +458,7 @@ $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,