Skip to content
Merged
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: 9 additions & 0 deletions _build/data/transport.core.system_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,15 @@
'area' => 'file',
'editedon' => null,
], '', true, true);
$settings['upload_file_exists']= $xpdo->newObject('modSystemSetting');
$settings['upload_file_exists']->fromArray([
'key' => 'upload_file_exists',
'value' => true,
'xtype' => 'combo-boolean',
'namespace' => 'core',
'area' => 'file',
'editedon' => null,
], '', true, true);
$settings['upload_images']= $xpdo->newObject(modSystemSetting::class);
$settings['upload_images']->fromArray([
'key' => 'upload_images',
Expand Down
3 changes: 3 additions & 0 deletions core/lexicon/en/setting.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@
$_lang['setting_upload_files'] = 'Uploadable File Types';
$_lang['setting_upload_files_desc'] = 'Here you can enter a list of files that can be uploaded into \'assets/files/\' using the Resource Manager. Please enter the extensions for the filetypes, seperated by commas.';

$_lang['setting_upload_file_exists'] = 'Check if uploaded file exists';
$_lang['setting_upload_file_exists_desc'] = 'When enabled an error will be shown when uploading a file that already exists with the same name. When disabled, the existing file will be quietly replaced with the new file.';

$_lang['setting_upload_images'] = 'Uploadable Image Types';
$_lang['setting_upload_images_desc'] = 'Here you can enter a list of files that can be uploaded into \'assets/images/\' using the Resource Manager. Please enter the extensions for the image types, separated by commas.';

Expand Down
20 changes: 18 additions & 2 deletions core/src/Revolution/Sources/modMediaSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,17 @@ public function createContainer($name, $parentContainer)
}


/**
* Checks `upload_file_exists` system setting to allow or disallow overwriting files with the same name
*
* @return boolean
*/
public function checkFileExists()
{
return (bool)$this->xpdo->getOption('upload_file_exists', null, true);
}


/**
* Create a file
*
Expand All @@ -655,7 +666,7 @@ public function createObject($path, $name, $content)
}

try {
if ($this->filesystem->has($path)) {
if ($this->checkFileExists() && $this->filesystem->has($path)) {
$this->addError('name', sprintf($this->xpdo->lexicon('file_err_ae'), $name));

return false;
Expand Down Expand Up @@ -945,7 +956,7 @@ public function renameObject($oldPath, $newName)
$this->addError('name', $this->xpdo->lexicon('file_err_invalid'));

return false;
} elseif ($this->filesystem->has($newPath)) {
} elseif ($this->checkFileExists() && $this->filesystem->has($newPath)) {
$this->addError('name', sprintf($this->xpdo->lexicon('file_err_ae'), $newName));

return false;
Expand Down Expand Up @@ -1076,6 +1087,11 @@ public function uploadObjectsToContainer($container, array $objects = [])

$newPath = $container . $this->sanitizePath($file['name']);
try {
if ($this->checkFileExists() && $this->filesystem->has($newPath)) {
$this->addError('path', sprintf($this->xpdo->lexicon('file_err_ae'), $file['name']));

return false;
}
if (!$this->filesystem->put($newPath, file_get_contents($file['tmp_name']))) {
$this->addError('path', $this->xpdo->lexicon('file_err_upload'));
continue;
Expand Down
2 changes: 1 addition & 1 deletion manager/assets/modext/modx.jsgrps-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manager/assets/modext/util/multiuploaddialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
var errors = '';
for (var i in this.errors) {
if (this.errors.hasOwnProperty(i)) {
errors += '- <b>' + i + '</b>: ' + this.errors[i] + '<br>';
errors += this.errors[i] + '<br>';
}
}
if (errors != '') {
Expand Down