Added error handling when hitting PHP upload limits
authorAlexander Ebert <ebert@woltlab.com>
Fri, 21 Jul 2017 19:12:21 +0000 (21:12 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 21 Jul 2017 19:12:21 +0000 (21:12 +0200)
Closes #2346

com.woltlab.wcf/templates/messageFormAttachments.tpl
wcfsetup/install/files/js/WCF.Attachment.js
wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php
wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php
wcfsetup/install/files/lib/system/upload/DefaultUploadFileValidationStrategy.class.php
wcfsetup/install/files/lib/system/upload/UploadFile.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 3bea7e37c17d255a9a28ba16f4ca74ea5b31afd7..4d12b12e3960b626917497f4cbb770477f03b5bc 100644 (file)
@@ -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}',
index 6bbefc793493802c2d4c4d42e539a9f7294bbaac..c22b7e3e1e2e8e7f536db74efbe15fc1fad934f2 100644 (file)
@@ -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
index 97d993ac04b5f45a460a039fcb09eb5064282ae3..7d29d61973363f3dba81aeff839c15113789e7ed 100755 (executable)
@@ -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');
                        }
                        
index 8f5e767f4c5f054d1ca80853a30c42be171f58b8..8cc95e58398bd2bd5101cb1f9050bf3c17cf954f 100644 (file)
@@ -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()
                                ];
                        }
                }
index ab6c20430933b420c2fd5aaa4b87857dc94abb59..6874351d2dc8c57215f20e38b4a4fab629c8991f 100644 (file)
@@ -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;
                }
                
index 5b344227d50e56515de127ff7cf27d6210f98bdf..5d460c76e8d360de22310e72d8559e64d68d996f 100644 (file)
@@ -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.
         * 
index 34f3ae034398f0b3e07b0e5c903395cf3747c40d..e2bfc3ef2058ab8447c68a3870f8303a90e4e231 100644 (file)
@@ -1419,6 +1419,7 @@ Bitte {if LANGUAGE_USE_INFORMAL_VARIANT}befolge{else}befolgen Sie{/if} die Anlei
                <item name="wcf.acp.package.dependencies.title"><![CDATA[Abhängigkeiten]]></item>
                <item name="wcf.acp.package.description"><![CDATA[Beschreibung]]></item>
                <item name="wcf.acp.package.error.cli.installIsApplication"><![CDATA[Apps können per CLI nicht installiert werden.]]></item>
+               <item name="wcf.acp.package.error.exceedsPhpLimit"><![CDATA[Die Datei ist größer als das PHP-Limit „max_upload_filesize“ und/oder „post_max_size“.]]></item>
                <item name="wcf.acp.package.error.noUniqueAbbrevation"><![CDATA[Es ist bereits eine App installiert, die die gleiche Abkürzung besitzt.]]></item>
                <item name="wcf.acp.package.error.noValidPackage"><![CDATA[Das angegebene Archiv ist kein gültiges Paket.]]></item>
                <item name="wcf.acp.package.error.sql.createTable"><![CDATA[Existierende Tabellen überschreiben]]></item>
@@ -2235,6 +2236,7 @@ Benutzerkontos nun in vollem Umfang nutzen.]]></item>
                <item name="wcf.attachment.upload.error.reachedLimit"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} die maximale Anzahl an Dateianhängen erreicht.]]></item>
                <item name="wcf.attachment.upload.error.reachedRemainingLimit"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} zu viele Dateianhänge ausgewählt, maximal verbleibend: #remaining#.]]></item>
                <item name="wcf.attachment.upload.error.uploadFailed"><![CDATA[Beim Hochladen der Datei ist ein unbekannter Fehler aufgetreten.]]></item>
+               <item name="wcf.attachment.upload.error.uploadPhpLimit"><![CDATA[Die Datei ist größer als das PHP-Limit „max_upload_filesize“ und/oder „post_max_size“.]]></item>
                <item name="wcf.attachment.upload.limits"><![CDATA[Maximale Anzahl an Dateianhängen: {#$attachmentHandler->getMaxCount()}<br>
 Maximale Dateigröße: {@$attachmentHandler->getMaxSize()|filesize}<br>
 Erlaubte Dateiendungen: {', '|implode:$attachmentHandler->getFormattedAllowedExtensions()}]]></item>
index 112942833f34f2a8ccf28dd2da82489375cc0432..605d69e8af75bc60b137fbfc3885e8eb46026481 100644 (file)
@@ -1413,6 +1413,7 @@ Please follow the instructions described in <a href="{@$__wcf->getPath()}acp/der
                <item name="wcf.acp.package.dependencies.title"><![CDATA[Dependencies]]></item>
                <item name="wcf.acp.package.description"><![CDATA[Description]]></item>
                <item name="wcf.acp.package.error.cli.installIsApplication"><![CDATA[Apps cannot be installed via CLI.]]></item>
+               <item name="wcf.acp.package.error.exceedsPhpLimit"><![CDATA[The file exceeds the PHP limit “max_upload_filesize” and/or “post_max_size”.]]></item>
                <item name="wcf.acp.package.error.noUniqueAbbrevation"><![CDATA[There is already an app installed which has the same abbreviation.]]></item>
                <item name="wcf.acp.package.error.noValidPackage"><![CDATA[The uploaded archive is invalid.]]></item>
                <item name="wcf.acp.package.error.sql.createTable"><![CDATA[Overwrite Existing Tables]]></item>
@@ -2174,6 +2175,7 @@ full extend.]]></item>
                
                <item name="wcf.attachment.upload.error.reachedRemainingLimit"><![CDATA[You have selected too many attachments, remaining: #remaining#.]]></item>
                <item name="wcf.attachment.upload.error.uploadFailed"><![CDATA[An unknown error occurred during the upload.]]></item>
+               <item name="wcf.attachment.upload.error.uploadPhpLimit"><![CDATA[The file exceeds the PHP limit “max_upload_filesize” and/or “post_max_size”.]]></item>
                <item name="wcf.attachment.upload.limits"><![CDATA[The maximum number of attachments: {#$attachmentHandler->getMaxCount()}<br>
 Allowed extensions: {', '|implode:$attachmentHandler->getFormattedAllowedExtensions()}]]></item>
                <item name="wcf.attachment.insert"><![CDATA[Insert into message]]></item>