Skip to content

Commit

Permalink
MDL-60817 core_repository: Show a warning if file extension is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Geshoski committed Mar 13, 2020
1 parent 73f8c56 commit 17ddce9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
6 changes: 4 additions & 2 deletions files/renderer.php
Expand Up @@ -114,8 +114,10 @@ public function render_form_filemanager($fm) {
array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'),
array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'),
array('confirmrenamefile', 'repository'), array('newfolder', 'repository'), array('edit', 'moodle'),
['nofilesselected', 'repository'], ['confirmdeleteselectedfile', 'repository'],
['selectall', 'moodle'], ['deselectall', 'moodle'], ['selectallornone', 'form'],
array('originalextensionchange', 'repository'), array('originalextensionremove', 'repository'),
array('aliaseschange', 'repository'), ['nofilesselected', 'repository'],
['confirmdeleteselectedfile', 'repository'], ['selectall', 'moodle'], ['deselectall', 'moodle'],
['selectallornone', 'form'],
)
);
if ($this->page->requires->should_create_one_time_item_now('core_file_managertemplate')) {
Expand Down
5 changes: 4 additions & 1 deletion lang/en/repository.php
Expand Up @@ -29,6 +29,7 @@
$string['addfile'] = 'Add...';
$string['addfiletext'] = 'Add file';
$string['addplugin'] = 'Add a repository plugin';
$string['aliaseschange'] = 'There are {$a} alias/shortcut files that use this file as their source. If you proceed then those aliases will be converted to true copies.';
$string['allowexternallinks'] = 'Allow external links';
$string['areamainfile'] = 'Main file';
$string['coursebackup'] = 'Course backups';
Expand Down Expand Up @@ -68,7 +69,7 @@
$string['confirmdelete'] = 'Are you sure you want to delete the repository {$a}? If you choose "Continue and download", file references to external contents will be downloaded to Moodle. This could take a long time to process.';
$string['confirmdeletefile'] = 'Are you sure you want to delete this file?';
$string['confirmdeleteselectedfile'] = 'Are you sure you want to delete the selected {$a} file(s)?';
$string['confirmrenamefile'] = 'Are you sure you want to rename/move this file? There are {$a} alias/shortcut files that use this file as their source. If you proceed then those aliases will be converted to true copies.';
$string['confirmrenamefile'] = 'Are you sure you want to rename/move this file?';
$string['confirmdeletefilewithhref'] = 'Are you sure you want to delete this file? There are {$a} alias/shortcut files that use this file as their source. If you proceed then those aliases will be converted to true copies.';
$string['confirmdeletefolder'] = 'Are you sure you want to delete this folder? All files and subfolders will be deleted.';
$string['confirmremove'] = 'Are you sure you want to remove this repository plugin, its options and <strong>all of its instances</strong> - {$a}? If you choose "Continue and download", file references to external contents will be downloaded to Moodle. This could take a long time to process.';
Expand Down Expand Up @@ -187,6 +188,8 @@
$string['notyourinstances'] = 'You can not view/edit repository instances of another user';
$string['off'] = 'Enabled but hidden';
$string['original'] = 'Original';
$string['originalextensionchange'] = 'The original file extension has been modified as a part of the file name change. Changing the extension from ".{$a->originalextension}" to ".{$a->newextension}" could potentially cause some side effects.';
$string['originalextensionremove'] = 'The original file extension has been removed as a part of the file name change. Removing the extension ".{$a}" could potentially cause some side effects.';
$string['openpicker'] = 'Choose a file...';
$string['operation'] = 'Operation';
$string['on'] = 'Enabled and visible';
Expand Down
36 changes: 32 additions & 4 deletions lib/form/filemanager.js
Expand Up @@ -773,10 +773,38 @@ M.form_filemanager.init = function(Y, options) {
this.print_msg(M.util.get_string('enternewname', 'repository'), 'error');
return;
}
if ((filenamechanged || filepathchanged) && !confirmed && fileinfo.refcount) {
dialog_options.message = M.util.get_string('confirmrenamefile', 'repository', fileinfo.refcount);
this.show_confirm_dialog(dialog_options);
return;

if ((filenamechanged || filepathchanged) && !confirmed) {
var warnings = '';
var originalfilenamearr = fileinfo.fullname.split('.');
var originalextension = (originalfilenamearr.length > 1) ? originalfilenamearr.pop() : "";
var newfilenamearr = newfilename.split('.');
var newextension = (newfilenamearr.length > 1) ? newfilenamearr.pop() : "";

if (newextension !== originalextension) {
if (newextension === "") {
var string = M.util.get_string('originalextensionremove', 'repository', originalextension);
} else {
var stringvars = {
originalextension: originalextension,
newextension: newextension
}
string = M.util.get_string('originalextensionchange', 'repository', stringvars);
}
warnings = warnings.concat('<li>', string, '</li>');
}
if (fileinfo.refcount) {
var string = M.util.get_string('aliaseschange', 'repository', fileinfo.refcount);
warnings = warnings.concat('<li>', string, '</li>');
}
if (warnings.length > 0) {
var message = '';
var confirmmsg = M.util.get_string('confirmrenamefile', 'repository', fileinfo.refcount);
dialog_options.message = message.concat('<p>', confirmmsg, '</p>',
'<ul class="p-x-2">', warnings, '</ul>');
this.show_confirm_dialog(dialog_options);
return;
}
}
if (filenamechanged || filepathchanged || licensechanged || authorchanged) {
params = {filepath:fileinfo.filepath, filename:fileinfo.fullname,
Expand Down

0 comments on commit 17ddce9

Please sign in to comment.