Fixed check for update version for manual uploads
authorAlexander Ebert <ebert@woltlab.com>
Tue, 28 Jan 2014 19:56:53 +0000 (20:56 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 28 Jan 2014 19:56:53 +0000 (20:56 +0100)
wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php
wcfsetup/install/files/lib/system/package/PackageArchive.class.php

index f1420ca1e21b949af332df6a5a9aa5858aaa6050..272f24e92a32308897e65cc77276c092bfdc39a0 100755 (executable)
@@ -176,8 +176,7 @@ class PackageStartInstallForm extends AbstractForm {
                        WCF::getSession()->checkPermissions(array('admin.system.package.canUpdatePackage'));
                        $this->activeMenuItem = 'wcf.acp.menu.link.package';
                        
-                       $this->archive->setPackage($this->package);
-                       if (!$this->archive->isValidUpdate()) {
+                       if (!$this->archive->isValidUpdate($this->package)) {
                                throw new UserInputException($type, 'noValidUpdate');
                        }
                }
index 032f701d4c95e13b81e1a72c84123f51d1008ec3..6b11ed97e1e9a57d41e26ebec25940afe409dde1 100644 (file)
@@ -347,19 +347,7 @@ class PackageArchive {
                }
                
                if ($this->package != null) {
-                       $validFromVersion = null;
-                       foreach ($this->instructions['update'] as $fromVersion => $update) {
-                               if (Package::checkFromversion($this->package->packageVersion, $fromVersion)) {
-                                       $validFromVersion = $fromVersion;
-                                       break;
-                               }
-                       }
-                       if ($validFromVersion === null) {
-                               $this->instructions['update'] = array();
-                       }
-                       else {
-                               $this->instructions['update'] = $this->instructions['update'][$validFromVersion];
-                       }
+                       $this->filterUpdateInstructions();
                }
                
                // set default values
@@ -367,6 +355,26 @@ class PackageArchive {
                if (!isset($this->packageInfo['packageURL'])) $this->packageInfo['packageURL'] = '';
        }
        
+       /**
+        * Filters update instructions.
+        */
+       protected function filterUpdateInstructions() {
+               $validFromVersion = null;
+               foreach ($this->instructions['update'] as $fromVersion => $update) {
+                       if (Package::checkFromversion($this->package->packageVersion, $fromVersion)) {
+                               $validFromVersion = $fromVersion;
+                               break;
+                       }
+               }
+               
+               if ($validFromVersion === null) {
+                       $this->instructions['update'] = array();
+               }
+               else {
+                       $this->instructions['update'] = $this->instructions['update'][$validFromVersion];
+               }
+       }
+       
        /**
         * Downloads the package archive.
         * 
@@ -408,9 +416,17 @@ class PackageArchive {
         * Checks if the new package is compatible with
         * the package that is about to be updated.
         * 
-        * @return      boolean         isValidUpdate
+        * @param       \wcf\data\package\Package       $package
+        * @return      boolean                         isValidUpdate
         */
-       public function isValidUpdate() {
+       public function isValidUpdate(Package $package = null) {
+               if ($this->package === null && $package !== null) {
+                       $this->setPackage($package);
+                       
+                       // re-evaluate update data
+                       $this->filterUpdateInstructions();
+               }
+               
                // Check name of the installed package against the name of the update. Both must be identical.
                if ($this->packageInfo['name'] != $this->package->package) {
                        return false;
@@ -421,10 +437,12 @@ class PackageArchive {
                if (Package::compareVersion($this->packageInfo['version'], $this->package->packageVersion) != 1) {
                        return false;
                }
+               
                // Check if the package provides an instructions block for the update from the installed package version
                if (empty($this->instructions['update'])) {
                        return false;
                }
+               
                return true;
        }