Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic video size limitation for chunkuploader settings #409

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions lang/en/block_opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand All @@ -851,6 +853,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
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Loading