Skip to content

Added check for package exist when uploading it #15267

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

Merged
merged 4 commits into from
Feb 24, 2021
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
6 changes: 6 additions & 0 deletions _build/templates/default/sass/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ textarea.x-form-field {
}
}

#modx-panel-packages.drag-n-drop:before{
background: transparent url($imgPath + 'restyle/dragndrop.svg') no-repeat top;
background-size: 50% 30%;
z-index: 0;
}

.x-panel-header {
background: none;
border: none;
Expand Down
3 changes: 3 additions & 0 deletions core/lexicon/en/file.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
$_lang['file_name'] = 'File Name';
$_lang['file_quick_create'] = 'Quick Create File';
$_lang['file_quick_update'] = 'Quick Edit File';
$_lang['file_package_err_invalid_directory'] = 'The packages directory does not exist!';
$_lang['file_package_err_invalid_name'] = 'This file [[+name]] has an invalid name for the transport package';
$_lang['file_package_err_invalid_type'] = 'This file does not appear to be a transport package';
$_lang['file_remove'] = 'Delete File';
$_lang['file_remove_confirm'] = 'Are you sure you want to delete this file entirely?';
$_lang['file_saved'] = 'File updated successfully!';
Expand Down
17 changes: 13 additions & 4 deletions core/src/Revolution/Processors/Workspace/Packages/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function process()
// Prepare the upload path and check it exists
$destination = $this->modx->getOption('core_path') . 'packages/';
if (!is_dir($destination)) {
return $this->failure('Packages directory doesnt appear to exist!'); //@TODO Make translatable
return $this->failure($this->modx->lexicon('file_package_err_invalid_directory'));
}

// Grab the file
Expand All @@ -95,16 +95,25 @@ public function process()
'application/x-zip',
'application/octet-stream',
])) {
return $this->failure('1 This file does not appear to be a transport package'); //@TODO Make translatable
return $this->failure($this->modx->lexicon('file_package_err_invalid_type'));
}

// Check valid name of file
if (!preg_match("/.+\\.transport\\.zip$/i", $file['name'])) {
return $this->failure("2 This file [{$file['name']}] does not appear to be a transport package"); //@TODO Make translatable
return $this->failure($this->modx->lexicon('file_package_err_invalid_name', [
'name' => $file['name']
]));
}

$newPath = $destination . $file['name'];

// Check if a file exists
if (file_exists($newPath)) {
Comment on lines +110 to +111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary comment

return $this->failure(sprintf($this->modx->lexicon('file_err_ae'), $file['name']));
}

// Return response
if (move_uploaded_file($file['tmp_name'], $destination . $file['name'])) {
if (move_uploaded_file($file['tmp_name'], $newPath)) {
return $this->success();
}

Expand Down
2 changes: 1 addition & 1 deletion manager/assets/modext/modx.jsgrps-min.js

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion manager/templates/default/css/index-min.css

Large diffs are not rendered by default.

Loading