Some more updates
authorAlexander Ebert <ebert@woltlab.com>
Fri, 11 Apr 2014 19:36:26 +0000 (21:36 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 11 Apr 2014 19:36:26 +0000 (21:36 +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/PackageValidationException.class.php
wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php

index 9173777c7ae692ef9fe47dd9a647b6d21c62b9b6..a3da2c78accdd7d553fcbf21fdaec46fe6b09c61 100755 (executable)
@@ -7,13 +7,13 @@ use wcf\form\AbstractForm;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\SystemException;
 use wcf\system\exception\UserInputException;
+use wcf\system\package\validation\PackageValidationManager;
 use wcf\system\package\PackageArchive;
 use wcf\system\package\PackageInstallationDispatcher;
 use wcf\system\WCF;
 use wcf\system\WCFACP;
 use wcf\util\FileUtil;
 use wcf\util\StringUtil;
-use wcf\system\package\validation\PackageValidationManager;
 
 /**
  * Shows the package install and update form.
@@ -137,7 +137,7 @@ class PackageStartInstallForm extends AbstractForm {
                        throw new UserInputException('uploadPackage', 'uploadFailed');
                }
                
-               if (PackageValidationManager::getInstance()->validate($this->uploadPackage['name'])) {
+               if (PackageValidationManager::getInstance()->validate($this->uploadPackage['name'], false)) {
                        die("win");
                }
                else {
index f1445711a355f99dae63fcdcd62aac5656e7d0ca..b9825fec3caf6b843fda5cc281401e287538aaa8 100644 (file)
@@ -1,9 +1,8 @@
 <?php
 namespace wcf\system\package\validation;
+use wcf\data\package\PackageCache;
 use wcf\system\package\PackageArchive;
-use wcf\system\WCF;
 use wcf\data\package\Package;
-use wcf\data\package\PackageCache;
 
 /**
  * Recursively validates the package archive and it's delivered requirements.
@@ -50,12 +49,14 @@ class PackageValidationArchive implements \RecursiveIterator {
        }
        
        /**
-        * Validates this package and it's delivered requirements.
+        * Validates this package and optionally it's delivered requirements. Unless you turn on
+        * $deepInspection, this will only check if the archive is theoretically usable to install
+        * or update. This means that neither exclusions nor dependencies will be checked. 
         * 
         * @param       boolean         $deepInspection
         * @return      boolean
         */
-       public function validate($deepInspection = false, $requiredVersion = '') {
+       public function validate($deepInspection, $requiredVersion = '') {
                try {
                        // try to read archive
                        $this->archive->openArchive();
@@ -71,18 +72,31 @@ class PackageValidationArchive implements \RecursiveIterator {
                
                if ($deepInspection) {
                        try {
+                               PackageValidationManager::getInstance()->addVirtualPackage($this->archive->getPackageInfo('name'), $this->archive->getPackageInfo('version'));
+                               
                                // check for exclusions
-                               $this->validateExclusion();
+                               if (true || WCF_VERSION != '2.1.0 Alpha 1 (Typhoon)') {
+                                       $this->validateExclusion();
+                               }
                                
                                // traverse open requirements
                                foreach ($this->archive->getOpenRequirements() as $requirement) {
+                                       if (empty($requirement['file'])) {
+                                               throw new PackageValidationException(PackageValidationException::MISSING_REQUIREMENT, array(
+                                                       'packageName' => $requirement['name'],
+                                                       'packageVersion' => $requirement['minversion']
+                                               ));
+                                       }
+                                       
                                        $archive = $this->archive->extractTar($requirement->file);
-                                               
+                                       
                                        $index = count($this->children);
                                        $this->children[$index] = new PackageValidationArchive($archive);
-                                       if (!$this->children[$index]->validate(true)) {
+                                       if (!$this->children[$index]->validate(true, $requirement['minversion'])) {
                                                return false;
                                        }
+                                       
+                                       PackageValidationManager::getInstance()->addVirtualPackage($this->archive->getPackageInfo('name'), $this->archive->getPackageInfo('version'));
                                }
                        }
                        catch (PackageValidationException $e) {
@@ -99,6 +113,15 @@ class PackageValidationArchive implements \RecursiveIterator {
        protected function validateInstructions($requiredVersion) {
                $package = PackageCache::getInstance()->getPackageByIdentifier($this->archive->getPackageInfo('name'));
                
+               // delivered package does not provide the minimum required version
+               if (Package::compareVersion($requiredVersion, $this->archive->getPackageInfo('version'), '>')) {
+                       throw new PackageValidationException(PackageValidationException::INSUFFICIENT_VERSION,array(
+                               'packageName' => $package->packageName,
+                               'packageVersion' => $package->packageVersion,
+                               'deliveredPackageVersion' => $this->archive->getPackageInfo('version')
+                       ));
+               }
+               
                // package is not installed yet
                if ($package === null) {
                        if (empty($this->archive->getInstallInstructions())) {
index e2177c9229173336868c6342beb51253145002c7..7484cc8daf85978d82b69785b3f471e247084ea2 100644 (file)
@@ -70,6 +70,12 @@ class PackageValidationException extends SystemException {
         */
        const EXCLUDED_PACKAGES = 8;
        
+       /**
+        * package version is lower than the request version, expects the details 'packageName', 'packageVersion' and 'deliveredPackageVersion'
+        * @var integer
+        */
+       const INSUFFICIENT_VERSION = 9;
+       
        /**
         * Creates a new PackageArchiveValidationException.
         * 
index d469bbf4efedb663182bee695057b553d6eb6a70..4e679eaed47323e27d62e94cea1db6bd3b573907 100644 (file)
@@ -27,12 +27,16 @@ class PackageValidationManager extends SingletonFactory {
        protected $virtualPackageList = array();
        
        /**
-        * Validates given archive for existance and ability to be installed/updated
+        * Validates given archive for existance and ability to be installed/updated. If you set the
+        * second parameter $deepInspection to "false", the system will only check if the archive
+        * looks fine, this is useful for a rough check during upload when a more detailed check will
+        * be performed afterwards.
         * 
         * @param       string          $archive
+        * @param       boolean         $deepInspection
         * @return      boolean
         */
-       public function validate($archive) {
+       public function validate($archive, $deepInspection = true) {
                $this->virtualPackageList = array();
                $this->packageValidationArchive = new PackageValidationArchive($archive);