Fixed some package update errors (update is still not working)
authorMarcel Werk <burntime@woltlab.com>
Fri, 5 Aug 2011 17:48:14 +0000 (19:48 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 5 Aug 2011 17:48:14 +0000 (19:48 +0200)
wcfsetup/install/files/lib/data/package/Package.class.php
wcfsetup/install/files/lib/system/package/PackageArchive.class.php

index bb31310639ecd88b0e064b3669874eb118d3be3c..8cbf165b9c3788d5abba2daf2f495ffe1b18f2de 100644 (file)
@@ -6,6 +6,7 @@ use wcf\system\exception\SystemException;
 use wcf\system\io\File;
 use wcf\system\WCF;
 use wcf\util\FileUtil;
+use wcf\util\StringUtil;
 
 /**
  * Represents a package.
@@ -195,10 +196,43 @@ class Package extends DatabaseObject {
                return preg_match('%^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$%', $packageName);
        }
        
+       /**
+        * Check version number of the installed package against the "fromversion" number of the update.
+        * The "fromversion" number may contain wildcards (asterisks) which means that the update covers 
+        * the whole range of release numbers where the asterisk wildcards digits from 0 to 9. For example,
+        * if "fromversion" is "1.1.*" and this package updates to version 1.2.0, all releases from 1.1.0 to 
+        * 1.1.9 may be updated using this package.
+        * 
+        * @param       string          $currentVersion
+        * @param       string          $fromVersion
+        * @return      boolean
+        */
+       public static function checkFromversion($currentVersion, $fromversion) {
+               if (StringUtil::indexOf($fromversion, '*') !== false) {
+                       // from version with wildcard
+                       // use regular expression
+                       $fromversion = StringUtil::replace('\*', '.*', preg_quote($fromversion, '!'));
+                       if (preg_match('!^'.$fromversion.'$!i', $currentVersion)) {
+                               return true;
+                       }
+               }
+               else {
+                       if (self::compareVersion($currentVersion, $fromversion, '=')) {
+                               return true;
+                       }
+               }
+               
+               return false;
+       }
+       
        /**
         * Compares two version number strings.
         *
-        * @see version_compare()
+        * @param       string          $version1
+        * @param       string          $version2
+        * @param       string          $operator
+        * @return      boolean         result
+        * @see http://www.php.net/manual/en/function.version-compare.php
         */
        public static function compareVersion($version1, $version2, $operator = null) {
                $version1 = self::formatVersionForCompare($version1);
index 307026f821c157173afc5cc0f9c01c7f55936a5d..8ed0d7ff0a366e6f73de57e2540c29885af7afa1 100644 (file)
@@ -361,7 +361,7 @@ class PackageArchive {
                
                if ($this->package != null) {
                        $validFromVersion = null;
-                       foreach ($this->update as $fromVersion => $update) {
+                       foreach ($this->instructions['update'] as $fromVersion => $update) {
                                if (Package::checkFromversion($this->package->packageVersion, $fromVersion)) {
                                        $validFromVersion = $fromVersion;
                                        break;