From da89969e9b4a8bae1da1a2e8bf5a9135588129e0 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 5 Aug 2011 19:48:14 +0200 Subject: [PATCH] Fixed some package update errors (update is still not working) --- .../files/lib/data/package/Package.class.php | 36 ++++++++++++++++++- .../system/package/PackageArchive.class.php | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index bb31310639..8cbf165b9c 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -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); diff --git a/wcfsetup/install/files/lib/system/package/PackageArchive.class.php b/wcfsetup/install/files/lib/system/package/PackageArchive.class.php index 307026f821..8ed0d7ff0a 100644 --- a/wcfsetup/install/files/lib/system/package/PackageArchive.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageArchive.class.php @@ -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; -- 2.20.1