Fixed selection of minor versions for updating
authorAlexander Ebert <ebert@woltlab.com>
Mon, 5 Aug 2013 13:29:57 +0000 (15:29 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 5 Aug 2013 13:29:57 +0000 (15:29 +0200)
It is no longer possible to select a lower minor version, if a higher version of the same major release is available. That means you cannot select 4.0.0 Beta 5, if 4.0.0 Beta 6 is available.

wcfsetup/install/files/lib/acp/page/PackageUpdatePage.class.php
wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php

index 23cd7c79dd809e2f83696171454c598e92de7fdb..a8e553b475f7dfb441b33fd754fe251ddd2d0201 100644 (file)
@@ -41,7 +41,7 @@ class PackageUpdatePage extends AbstractPage {
        public function readData() {
                parent::readData();
                
-               $this->availableUpdates = PackageUpdateDispatcher::getInstance()->getAvailableUpdates();
+               $this->availableUpdates = PackageUpdateDispatcher::getInstance()->getAvailableUpdates(true, true);
        }
        
        /**
index 1af7d9cd053728fb6be8a64972959ed101b84b59..82edd37cbd01db621cd6729b42d1ab215526523e 100644 (file)
@@ -521,9 +521,10 @@ class PackageUpdateDispatcher extends SingletonFactory {
         * Returns a list of available updates for installed packages.
         * 
         * @param       boolean         $removeRequirements
+        * @param       boolean         $removeOlderMinorReleases
         * @return      array
         */
-       public function getAvailableUpdates($removeRequirements = true) {
+       public function getAvailableUpdates($removeRequirements = true, $removeOlderMinorReleases = false) {
                $updates = array();
                
                // get update server data
@@ -605,6 +606,33 @@ class PackageUpdateDispatcher extends SingletonFactory {
                        }
                }
                
+               // remove older minor releases from list, e.g. only display 1.0.2, even if 1.0.1 is available
+               if ($removeOlderMinorReleases) {
+                       foreach ($updates as &$updateData) {
+                               $highestVersions = array();
+                               foreach ($updateData['versions'] as $versionNumber => $dummy) {
+                                       if (preg_match('~^(\d+\.\d+)\.~', $versionNumber, $matches)) {
+                                               $major = $matches[1];
+                                               if (isset($highestVersions[$major])) {
+                                                       if (version_compare($highestVersions[$major], $versionNumber, '<')) {
+                                                               // version is newer, discard current version
+                                                               unset($updateData['versions'][$highestVersions[$major]]);
+                                                               $highestVersions[$major] = $versionNumber;
+                                                       }
+                                                       else {
+                                                               // version is lower, discard
+                                                               unset($updateData['versions'][$versionNumber]);
+                                                       }
+                                               }
+                                               else {
+                                                       $highestVersions[$major] = $versionNumber;
+                                               }
+                                       }
+                               }
+                       }
+                       unset($updateData);
+               }
+               
                return $updates;
        }