[TASK] EM: Update extension to latest possible 99/37099/5
authorAlexander Opitz <opitz.alexander@googlemail.com>
Mon, 23 Feb 2015 10:17:23 +0000 (11:17 +0100)
committerXavier Perseguers <xavier@typo3.org>
Mon, 13 Apr 2015 13:56:43 +0000 (15:56 +0200)
The EM tries to update to latest available extension, but the latest one
may have unresolvable dependencies to core version. Now we show the user
also other available updates which will resolve dependencies. So it is
now possible to easily update to such versions.

Resolves: #65117
Releases: master, 6.2
Change-Id: I57423c17b3f7ab13c49b2662294b822adf5e0247
Reviewed-on: http://review.typo3.org/37099
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/sysext/extensionmanager/Classes/Controller/DownloadController.php
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
typo3/sysext/extensionmanager/Classes/Utility/ListUtility.php
typo3/sysext/extensionmanager/Resources/Private/Templates/Download/UpdateCommentForUpdatableVersions.json
typo3/sysext/extensionmanager/Resources/Private/Templates/List/Index.html

index 11cad48..e4076d3 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extensionmanager\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
 
 /**
@@ -201,7 +202,7 @@ class DownloadController extends AbstractController {
                                $this->translate('extensionList.updateFlashMessage.title')
                        );
                } catch (\Exception $e) {
-                       $this->addFlashMessage(htmlspecialchars($e->getMessage()), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                       $this->addFlashMessage(htmlspecialchars($e->getMessage()), '', FlashMessage::ERROR);
                }
 
                return '';
@@ -216,14 +217,26 @@ class DownloadController extends AbstractController {
         */
        protected function updateCommentForUpdatableVersionsAction() {
                $extensionKey = $this->request->getArgument('extension');
-               $version = $this->request->getArgument('integerVersion');
+               $versionStart = $this->request->getArgument('integerVersionStart');
+               $versionStop = $this->request->getArgument('integerVersionStop');
                $updateComments = array();
                /** @var Extension[] $updatableVersions */
-               $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion($extensionKey, $version, 0, FALSE);
+               $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
+                       $extensionKey,
+                       $versionStart,
+                       $versionStop
+               );
+               $highestPossibleVersion = FALSE;
+
                foreach ($updatableVersions as $updatableVersion) {
+                       if ($highestPossibleVersion === FALSE) {
+                               $highestPossibleVersion = $updatableVersion->getVersion();
+                       }
                        $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
                }
-               $this->view->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);
+               $this->view->assign('updateComments', $updateComments)
+                       ->assign('extensionKey', $extensionKey)
+                       ->assign('version', $highestPossibleVersion);
        }
 
        /**
index fe21dac..04d5045 100644 (file)
@@ -418,29 +418,44 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
                return $sqlData;
        }
 
+
        /**
-        * Checks if an update for an extension is available
+        * Checks if an update for an extension is available which also resolves dependencies.
         *
         * @internal
         * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData
         * @return bool
         */
        public function isUpdateAvailable(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData) {
-               $isUpdateAvailable = FALSE;
+               return (bool)$this->getUpdateableVersion($extensionData);
+       }
+
+       /**
+        * Returns the updateable version for an extension which also resolves dependencies.
+        *
+        * @internal
+        * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData
+        * @return bool|\TYPO3\CMS\Extensionmanager\Domain\Model\Extension FALSE if no update available otherwise latest
+        *                                                                 possible update
+        */
+       public function getUpdateableVersion(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData) {
                // Only check for update for TER extensions
                $version = $extensionData->getIntegerVersion();
-               /** @var $highestTerVersionExtension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
-               $highestTerVersionExtension = $this->extensionRepository->findHighestAvailableVersion($extensionData->getExtensionKey());
-               if ($highestTerVersionExtension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
-                       $highestVersion = $highestTerVersionExtension->getIntegerVersion();
-                       if ($highestVersion > $version) {
-                               $this->dependencyUtility->checkDependencies($highestTerVersionExtension);
+
+               /** @var $extensionUpdates[] \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
+               $extensionUpdates = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
+                       $extensionData->getExtensionKey(),
+                       $version + 1
+               );
+               if ($extensionUpdates->count() > 0) {
+                       foreach ($extensionUpdates as $extensionUpdate) {
+                               $this->dependencyUtility->checkDependencies($extensionUpdate);
                                if (!$this->dependencyUtility->hasDependencyErrors()) {
-                                       $isUpdateAvailable = TRUE;
+                                       return $extensionUpdate;
                                }
                        }
                }
-               return $isUpdateAvailable;
+               return FALSE;
        }
 
        /**
index e92ecef..9be2787 100644 (file)
@@ -139,8 +139,13 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
                                $terObject = $this->getExtensionTerData($extensionKey, $extensions[$extensionKey]['version']);
                                if ($terObject !== NULL) {
                                        $extensions[$extensionKey]['terObject'] = $terObject;
-                                       $extensions[$extensionKey]['updateAvailable'] = $this->installUtility->isUpdateAvailable($terObject);
-                                       $extensions[$extensionKey]['updateToVersion'] = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
+                                       $extensions[$extensionKey]['updateAvailable'] = FALSE;
+                                       $extensions[$extensionKey]['updateToVersion'] = NULL;
+                                       $extensionToUpdate = $this->installUtility->getUpdateableVersion($terObject);
+                                       if ($extensionToUpdate !== FALSE) {
+                                               $extensions[$extensionKey]['updateAvailable'] = TRUE;
+                                               $extensions[$extensionKey]['updateToVersion'] = $extensionToUpdate;
+                                       }
                                }
                        } else {
                                unset($extensions[$extensionKey]);
index 1d93df4..7c7248e 100644 (file)
@@ -1,4 +1,4 @@
 {namespace em=TYPO3\CMS\Extensionmanager\ViewHelpers}
 <em:format.jsonEncode additionalAttributes="{updateComments:updateComments,
-url:'{f:uri.action(action:\"updateExtension\", controller:\"Download\", arguments:\"{extension:extensionKey, format:\'json\'}\")}'
+url:'{f:uri.action(action:\"updateExtension\", controller:\"Download\", arguments:\"{extension:extensionKey, version:version, format:\'json\'}\")}'
 }" />
index e6c5103..e76fa96 100644 (file)
@@ -59,7 +59,7 @@
                                                                <f:else>
                                                                        <span class="btn btn-default">
                                                                                <f:be.buttons.icon
-                                                                                       uri="{f:uri.action(action:'updateCommentForUpdatableVersions',controller:'Download',arguments:{extension:extension.key, integerVersion: extension.terObject.integerVersion},format:'json')}"
+                                                                                       uri="{f:uri.action(action:'updateCommentForUpdatableVersions',controller:'Download',arguments:{extension:extension.key, integerVersionStart: extension.terObject.integerVersion, integerVersionStop: extension.updateToVersion.integerVersion},format:'json')}"
                                                                                        icon="actions-system-extension-update"
                                                                                        title="{f:translate(key:'extensionList.updateToVersion', arguments:{0:extension.updateToVersion.version})}"
                                                                                        additionalAttributes="{data-action:'update-extension'}"