[BUGFIX] EM: Update extension versions not in TER 84/38284/2
authorAlexander Opitz <opitz.alexander@googlemail.com>
Thu, 26 Feb 2015 10:51:07 +0000 (11:51 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Sun, 29 Mar 2015 20:39:28 +0000 (22:39 +0200)
The EM finds now extension updates for extension versions which aren't
in TER data.

Resolves: #65341
Releases: master, 6.2
Change-Id: Ia8c280f85b9c9f903334437bc059fad841c760da
Reviewed-on: http://review.typo3.org/38284
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/extensionmanager/Classes/Utility/ListUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/ListUtilityTest.php

index 1d0a551..dc122c1 100644 (file)
@@ -14,7 +14,10 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 use TYPO3\CMS\Core\Package\PackageInterface;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\VersionNumberUtility;
+use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
 
 /**
  * Utility for dealing with extension list related functions
@@ -69,7 +72,7 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $extensions = array();
                foreach ($this->packageManager->getAvailablePackages() as $package) {
                        // Only TYPO3 related packages could be handled by the extension manager
-                       // Composer packages from "Packages" folder will be instanciated as \TYPO3\Flow\Package\Package
+                       // Composer packages from "Packages" folder will be instantiated as \TYPO3\Flow\Package\Package
                        if (!($package instanceof \TYPO3\CMS\Core\Package\PackageInterface)) {
                                continue;
                        }
@@ -78,7 +81,7 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
                                'siteRelPath' => str_replace(PATH_site, '', $package->getPackagePath()),
                                'type' => $installationType,
                                'key' => $package->getPackageKey(),
-                               'ext_icon' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionIcon($package->getPackagePath()),
+                               'ext_icon' => ExtensionManagementUtility::getExtensionIcon($package->getPackagePath()),
                        );
                }
                return $extensions;
@@ -98,7 +101,7 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
         * @return string
         */
        protected function getInstallTypeForPackage(PackageInterface $package) {
-               foreach (\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnInstallPaths() as $installType => $installPath) {
+               foreach (Extension::returnInstallPaths() as $installType => $installPath) {
                        if (GeneralUtility::isFirstPartOfStr($package->getPackagePath(), $installPath)) {
                                return $installType;
                        }
@@ -132,8 +135,8 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
                        $emconf = $this->emConfUtility->includeEmConf($properties);
                        if ($emconf) {
                                $extensions[$extensionKey] = array_merge($emconf, $properties);
-                               $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $extensions[$extensionKey]['version']);
-                               if ($terObject instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
+                               $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);
@@ -146,6 +149,57 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * Tries to find given extension with given version in TER data.
+        * If extension is found but not the given version, we return TER data from highest version with version data set to
+        * given one.
+        *
+        * @param string $extensionKey Key of the extension
+        * @param string $version String representation of version number
+        * @return Extension|NULL Extension TER object or NULL if nothing found
+        */
+       protected function getExtensionTerData($extensionKey, $version) {
+               $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
+               if (!$terObject instanceof Extension) {
+                       // Version unknown in TER data, try to find extension
+                       $terObject = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
+                       if ($terObject instanceof Extension) {
+                               // Found in TER now, set version information to the known ones, so we can look if there is a newer one
+                               // Use a cloned object, otherwise wrong information is stored in persistenceManager
+                               $terObject = clone $terObject;
+                               $terObject->setVersion($version);
+                               $terObject->setIntegerVersion(
+                                       VersionNumberUtility::convertVersionNumberToInteger($terObject->getVersion())
+                               );
+                       } else {
+                               $terObject = NULL;
+                       }
+               }
+
+               return $terObject;
+       }
+
+       /**
+        * Adds information about icon size to the extension information
+        *
+        * @param array $extensions
+        * @return array
+        */
+       public function enrichExtensionsWithIconInformation(array $extensions) {
+               foreach ($extensions as &$properties) {
+                       $iInfo = @getimagesize(PATH_site . $properties['siteRelPath'] . $properties['ext_icon']);
+                       if ($iInfo !== FALSE) {
+                               $properties['ext_icon_width'] = $iInfo[0];
+                               $properties['ext_icon_height'] = $iInfo[1];
+                       } else {
+                               $properties['ext_icon_width'] = 0;
+                               $properties['ext_icon_height'] = 0;
+                       }
+               }
+               unset($properties);
+               return $extensions;
+       }
+
+       /**
         * Gets all available and installed extension with additional information
         * from em_conf and TER (if available)
         *
index 2b60d10..7552a8d 100644 (file)
@@ -170,7 +170,7 @@ class ListUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @return void
         */
        public function enrichExtensionsWithEmConfInformation($extensions, $emConf, $expectedResult) {
-               $this->inject($this->subject, 'extensionRepository', $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('findOneByExtensionKeyAndVersion'), array(), '', FALSE));
+               $this->inject($this->subject, 'extensionRepository', $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('findOneByExtensionKeyAndVersion', 'findHighestAvailableVersion'), array(), '', FALSE));
                $emConfUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\EmConfUtility');
                $emConfUtilityMock->expects($this->any())->method('includeEmConf')->will($this->returnValue($emConf));
                $this->inject($this->subject, 'emConfUtility', $emConfUtilityMock);