Fixed handling of broken archives
authorAlexander Ebert <ebert@woltlab.com>
Wed, 11 Jun 2014 11:46:41 +0000 (13:46 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 11 Jun 2014 11:46:41 +0000 (13:46 +0200)
wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php
wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php
wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php

index 5529fd025d9e494f674f48c58871b1ea489ae435..801704fd998ca8cf6256cced15f6cc71732237e1 100755 (executable)
@@ -14,6 +14,7 @@ use wcf\system\WCF;
 use wcf\system\WCFACP;
 use wcf\util\FileUtil;
 use wcf\util\StringUtil;
+use wcf\system\package\validation\PackageValidationException;
 
 /**
  * Shows the package install and update form.
@@ -137,7 +138,18 @@ class PackageStartInstallForm extends AbstractForm {
                        throw new UserInputException('uploadPackage', 'uploadFailed');
                }
                
-               PackageValidationManager::getInstance()->validate($this->uploadPackage['name'], false);
+               if (!PackageValidationManager::getInstance()->validate($this->uploadPackage['name'], false)) {
+                       $exception = PackageValidationManager::getInstance()->getException();
+                       if ($exception instanceof PackageValidationException) {
+                               switch ($exception->getCode()) {
+                                       case PackageValidationException::INVALID_PACKAGE_NAME:
+                                       case PackageValidationException::MISSING_PACKAGE_XML:
+                                               throw new UserInputException('uploadPackage', 'noValidPackage');
+                                       break;
+                               }
+                       }
+               }
+               
                $this->package = PackageValidationManager::getInstance()->getPackageValidationArchive()->getPackage();
        }
        
index db3e71f4a77e2e249f062f1b338dc716eff7801f..2928a76d559dbcdc4b2c887b33ae385ddb9326e1 100644 (file)
@@ -222,6 +222,15 @@ class PackageValidationArchive implements \RecursiveIterator {
                }
        }
        
+       /**
+        * Returns the occured exception.
+        * 
+        * @return      \Exception
+        */
+       public function getException() {
+               return $this->exception;
+       }
+       
        /**
         * Returns the exception message.
         * 
index 1e68507e9a1f06d385078a10069fcfe4067f85d7..28fb3e56a44d1f30b099e1a86a469bc1e7aa3409 100644 (file)
@@ -132,6 +132,21 @@ class PackageValidationManager extends SingletonFactory {
                return '';
        }
        
+       /**
+        * Recursively traverses the package validation archives and returns the first exception.
+        * 
+        * @return      \Exception
+        */
+       public function getException() {
+               foreach ($this->getPackageValidationArchiveList() as $packageArchive) {
+                       if ($packageArchive->getException() !== null) {
+                               return $packageArchive->getException();
+                       }
+               }
+               
+               return null;
+       }
+       
        /**
         * Validates an instruction against the corresponding package installation plugin.
         *