From: Alexander Ebert Date: Fri, 21 Jul 2017 19:12:21 +0000 (+0200) Subject: Added error handling when hitting PHP upload limits X-Git-Tag: 3.1.0_Alpha_1~227 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8a23f870a4e370a57cad5332ee392f382e7dcc33;p=GitHub%2FWoltLab%2FWCF.git Added error handling when hitting PHP upload limits Closes #2346 --- diff --git a/com.woltlab.wcf/templates/messageFormAttachments.tpl b/com.woltlab.wcf/templates/messageFormAttachments.tpl index 3bea7e37c1..4d12b12e39 100644 --- a/com.woltlab.wcf/templates/messageFormAttachments.tpl +++ b/com.woltlab.wcf/templates/messageFormAttachments.tpl @@ -47,6 +47,7 @@ 'wcf.attachment.upload.error.reachedLimit': '{lang}wcf.attachment.upload.error.reachedLimit{/lang}', 'wcf.attachment.upload.error.reachedRemainingLimit': '{lang}wcf.attachment.upload.error.reachedRemainingLimit{/lang}', 'wcf.attachment.upload.error.uploadFailed': '{lang}wcf.attachment.upload.error.uploadFailed{/lang}', + 'wcf.attachment.upload.error.uploadPhpLimit': '{lang}wcf.attachment.upload.error.uploadPhpLimit{/lang}', 'wcf.attachment.insert': '{lang}wcf.attachment.insert{/lang}', 'wcf.attachment.insertAll': '{lang}wcf.attachment.insertAll{/lang}', 'wcf.attachment.insertFull': '{lang}wcf.attachment.insertFull{/lang}', diff --git a/wcfsetup/install/files/js/WCF.Attachment.js b/wcfsetup/install/files/js/WCF.Attachment.js index 6bbefc7934..c22b7e3e1e 100644 --- a/wcfsetup/install/files/js/WCF.Attachment.js +++ b/wcfsetup/install/files/js/WCF.Attachment.js @@ -425,7 +425,12 @@ if (COMPILER_TARGET_DEFAULT) { // error handling if (data.returnValues && data.returnValues.errors[$internalFileID]) { - $errorMessage = data.returnValues.errors[$internalFileID]['errorType']; + var errorData = data.returnValues.errors[$internalFileID]; + $errorMessage = errorData.errorType; + + if ($errorMessage === 'uploadFailed' && errorData.additionalData.phpLimitExceeded) { + $errorMessage = 'uploadPhpLimit'; + } } else { // unknown error diff --git a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php index 97d993ac04..7d29d61973 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php @@ -2,9 +2,11 @@ namespace wcf\acp\form; use wcf\data\package\installation\queue\PackageInstallationQueue; use wcf\data\package\installation\queue\PackageInstallationQueueEditor; +use wcf\data\package\Package; use wcf\form\AbstractForm; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; +use wcf\system\package\PackageArchive; use wcf\system\package\validation\PackageValidationException; use wcf\system\package\validation\PackageValidationManager; use wcf\system\package\PackageInstallationDispatcher; @@ -28,9 +30,9 @@ class PackageStartInstallForm extends AbstractForm { /** * updated package object - * @var \wcf\data\package\Package + * @var Package */ - public $package = null; + public $package; /** * data of the uploaded package @@ -40,15 +42,15 @@ class PackageStartInstallForm extends AbstractForm { /** * archive of the installation/update package - * @var \wcf\system\package\PackageArchive + * @var PackageArchive */ - public $archive = null; + public $archive; /** * package installation/update queue * @var PackageInstallationQueue */ - public $queue = null; + public $queue; /** * location of the package uploaded via style import @@ -114,6 +116,10 @@ class PackageStartInstallForm extends AbstractForm { if (empty($filename)) { if (empty($this->uploadPackage['tmp_name'])) { + if (isset($_FILES['uploadPackage']) && $_FILES['uploadPackage']['error'] === UPLOAD_ERR_INI_SIZE) { + throw new UserInputException('uploadPackage', 'exceedsPhpLimit'); + } + throw new UserInputException('uploadPackage', 'uploadFailed'); } diff --git a/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php b/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php index 8f5e767f4c..8cc95e5839 100644 --- a/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php +++ b/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php @@ -190,7 +190,8 @@ class AttachmentAction extends AbstractDatabaseObjectAction implements ISortable $result['errors'][$file->getInternalFileID()] = [ 'filename' => $file->getFilename(), 'filesize' => $file->getFilesize(), - 'errorType' => $file->getValidationErrorType() + 'errorType' => $file->getValidationErrorType(), + 'additionalData' => $file->getValidationErrorAdditionalData() ]; } } diff --git a/wcfsetup/install/files/lib/system/upload/DefaultUploadFileValidationStrategy.class.php b/wcfsetup/install/files/lib/system/upload/DefaultUploadFileValidationStrategy.class.php index ab6c204309..6874351d2d 100644 --- a/wcfsetup/install/files/lib/system/upload/DefaultUploadFileValidationStrategy.class.php +++ b/wcfsetup/install/files/lib/system/upload/DefaultUploadFileValidationStrategy.class.php @@ -45,7 +45,10 @@ class DefaultUploadFileValidationStrategy implements IUploadFileValidationStrate */ public function validate(UploadFile $uploadFile) { if ($uploadFile->getErrorCode() != 0) { - $uploadFile->setValidationErrorType('uploadFailed'); + $additionalData = []; + if ($uploadFile->getErrorCode() === UPLOAD_ERR_INI_SIZE) $additionalData['phpLimitExceeded'] = true; + + $uploadFile->setValidationErrorType('uploadFailed', $additionalData); return false; } diff --git a/wcfsetup/install/files/lib/system/upload/UploadFile.class.php b/wcfsetup/install/files/lib/system/upload/UploadFile.class.php index 5b344227d5..5d460c76e8 100644 --- a/wcfsetup/install/files/lib/system/upload/UploadFile.class.php +++ b/wcfsetup/install/files/lib/system/upload/UploadFile.class.php @@ -52,6 +52,12 @@ class UploadFile { */ protected $validationErrorType = ''; + /** + * additional data for validation errors + * @var array + */ + protected $validationErrorAdditionalData = []; + /** * Creates a new UploadFile object. * @@ -145,9 +151,11 @@ class UploadFile { * Sets the validation error type. * * @param string $validationErrorType + * @param array $additionalData */ - public function setValidationErrorType($validationErrorType) { + public function setValidationErrorType($validationErrorType, array $additionalData = []) { $this->validationErrorType = $validationErrorType; + $this->validationErrorAdditionalData = $additionalData; } /** @@ -159,6 +167,15 @@ class UploadFile { return $this->validationErrorType; } + /** + * Returns the validation error additional data array. + * + * @return array + */ + public function getValidationErrorAdditionalData() { + return $this->validationErrorAdditionalData; + } + /** * Returns the image data of the file or `null` if the file is no image. * diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 34f3ae0343..e2bfc3ef20 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1419,6 +1419,7 @@ Bitte {if LANGUAGE_USE_INFORMAL_VARIANT}befolge{else}befolgen Sie{/if} die Anlei + @@ -2235,6 +2236,7 @@ Benutzerkontos nun in vollem Umfang nutzen.]]> + getMaxCount()}
Maximale Dateigröße: {@$attachmentHandler->getMaxSize()|filesize}
Erlaubte Dateiendungen: {', '|implode:$attachmentHandler->getFormattedAllowedExtensions()}]]>
diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 112942833f..605d69e8af 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1413,6 +1413,7 @@ Please follow the instructions described in + @@ -2174,6 +2175,7 @@ full extend.]]> + getMaxCount()}
Allowed extensions: {', '|implode:$attachmentHandler->getFormattedAllowedExtensions()}]]>