[TASK] Cleanup EM list utility 39/27239/5
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 1 Feb 2014 17:45:37 +0000 (18:45 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 2 Feb 2014 20:31:33 +0000 (21:31 +0100)
The EM has a lot of code related prior to
the inclusion of package management.

This change does a small cleanup in
ListUtility and calling code to make
better use of the new API.

Resolves: #55562
Releases: 6.2
Change-Id: I7aa5f5204ed3552fec617f2cd9e65dac2009486f
Reviewed-on: https://review.typo3.org/27239
Reviewed-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/core/ext_localconf.php
typo3/sysext/extensionmanager/Classes/Command/ExtensionCommandController.php
typo3/sysext/extensionmanager/Classes/Controller/ListController.php
typo3/sysext/extensionmanager/Classes/Utility/DependencyUtility.php
typo3/sysext/extensionmanager/Classes/Utility/ListUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/ListUtilityTest.php
typo3/sysext/lang/Classes/Command/UpdateCommandController.php
typo3/sysext/lang/Classes/Domain/Repository/ExtensionRepository.php

index 1484a69..5d8fc76 100644 (file)
@@ -3,13 +3,21 @@ if (!defined('TYPO3_MODE')) {
        die('Access denied.');
 }
 
-if (TYPO3_MODE === 'BE' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
+if (TYPO3_MODE === 'BE') {
        \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect(
-               'TYPO3\\CMS\\Core\\Resource\\ResourceFactory',
-               \TYPO3\CMS\Core\Resource\ResourceFactory::SIGNAL_PostProcessStorage,
-               'TYPO3\\CMS\\Core\\Resource\\Security\\StoragePermissionsAspect',
-               'addUserPermissionsToStorage'
+               'PackageManagement',
+               'packagesMayHaveChanged',
+               'TYPO3\\CMS\\Core\\Package\\PackageManager',
+               'scanAvailablePackages'
        );
+       if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect(
+                       'TYPO3\\CMS\\Core\\Resource\\ResourceFactory',
+                       \TYPO3\CMS\Core\Resource\ResourceFactory::SIGNAL_PostProcessStorage,
+                       'TYPO3\\CMS\\Core\\Resource\\Security\\StoragePermissionsAspect',
+                       'addUserPermissionsToStorage'
+               );
+       }
 }
 
 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect(
index 03082db..a0296d4 100644 (file)
@@ -37,6 +37,12 @@ use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
 class ExtensionCommandController extends CommandController {
 
        /**
+        * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        * @inject
+        */
+       protected $signalSlotDispatcher;
+
+       /**
         * Installs an extension by key
         *
         * The extension files must be present in one of the
@@ -46,9 +52,7 @@ class ExtensionCommandController extends CommandController {
         * @return void
         */
        public function installCommand($extensionKey) {
-               /** @var $packageManager \TYPO3\CMS\Core\Package\PackageManager */
-               $packageManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Package\\PackageManager');
-               $packageManager->scanAvailablePackages();
+               $this->emitPackagesMayHaveChanged();
 
                /** @var $service \TYPO3\CMS\Extensionmanager\Utility\InstallUtility */
                $service = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
@@ -70,4 +74,10 @@ class ExtensionCommandController extends CommandController {
                $service->uninstall($extensionKey);
        }
 
+       /**
+        * Emits packages may have changed signal
+        */
+       protected function emitPackagesMayHaveChanged() {
+               $this->signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
+       }
 }
index b8b75cc..0160f9f 100644 (file)
@@ -65,9 +65,7 @@ class ListController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractCont
         * @return void
         */
        public function indexAction() {
-               $availableExtensions = $this->listUtility->getAvailableExtensions();
-               $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($availableExtensions);
-               $availableAndInstalledExtensions = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
+               $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
                $this->view->assign('extensions', $availableAndInstalledExtensions);
                $this->handleTriggerArguments();
        }
index 7a01491..b7e2f07 100644 (file)
@@ -389,9 +389,7 @@ class DependencyUtility implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        public function findInstalledExtensionsThatDependOnMe($extensionKey) {
-               $availableExtensions = $this->listUtility->getAvailableExtensions();
-               $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($availableExtensions);
-               $availableAndInstalledExtensions = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
+               $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
                $dependentExtensions = array();
                foreach ($availableAndInstalledExtensions as $availableAndInstalledExtensionKey => $availableAndInstalledExtension) {
                        if (isset($availableAndInstalledExtension['installed']) && $availableAndInstalledExtension['installed'] === TRUE) {
index 5f59d2f..197bc5b 100644 (file)
@@ -26,6 +26,9 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Package\PackageInterface;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Utility for dealing with extension list related functions
  *
@@ -39,22 +42,16 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
 class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
 
        /**
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManager
-        * @inject
-        */
-       public $objectManager;
-
-       /**
         * @var \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility
         * @inject
         */
-       public $emConfUtility;
+       protected $emConfUtility;
 
        /**
         * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
         * @inject
         */
-       public $extensionRepository;
+       protected $extensionRepository;
 
        /**
         * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
@@ -63,45 +60,69 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
        protected $installUtility;
 
        /**
+        * @var \TYPO3\CMS\Core\Package\PackageManager
+        * @inject
+        */
+       protected $packageManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        * @inject
+        */
+       protected $signalSlotDispatcher;
+
+       /**
         * Returns the list of available, but not necessarily loaded extensions
         *
         * @return array Array with two sub-arrays, list array (all extensions with info) and category index
         * @see getInstExtList()
         */
        public function getAvailableExtensions() {
+               $this->emitPackagesMayHaveChanged();
                $extensions = array();
-               $paths = \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnInstallPaths();
-               foreach ($paths as $installationType => $path) {
-                       try {
-                               if (is_dir($path)) {
-                                       $extList = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs($path);
-                                       if (is_array($extList)) {
-                                               foreach ($extList as $extKey) {
-                                                       $extensions[$extKey] = array(
-                                                               'siteRelPath' => str_replace(PATH_site, '', $path . $extKey),
-                                                               'type' => $installationType,
-                                                               'key' => $extKey,
-                                                               'ext_icon' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionIcon($path . $extKey . '/')
-                                                       );
-                                               }
-                                       }
-                               }
-                       } catch (\Exception $e) {
-                               \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getMessage(), 'extensionmanager');
-                       }
+               foreach ($this->packageManager->getAvailablePackages() as $package) {
+                       $installationType = $this->getInstallTypeForPackage($package);
+                       $extensions[$package->getPackageKey()] = array(
+                               'siteRelPath' => str_replace(PATH_site, '', $package->getPackagePath()),
+                               'type' => $installationType,
+                               'key' => $package->getPackageKey(),
+                               'ext_icon' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionIcon($package->getPackagePath()),
+                       );
                }
                return $extensions;
        }
 
        /**
+        * Emits packages may have changed signal
+        */
+       protected function emitPackagesMayHaveChanged() {
+               $this->signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
+       }
+
+       /**
+        * Returns "System", "Global" or "Local" based on extension position in filesystem.
+        *
+        * @param PackageInterface $package
+        * @return string
+        */
+       protected function getInstallTypeForPackage(PackageInterface $package) {
+               foreach (\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnInstallPaths() as $installType => $installPath) {
+                       if (GeneralUtility::isFirstPartOfStr($package->getPackagePath(), $installPath)) {
+                               return $installType;
+                       }
+               }
+               return '';
+       }
+
+       /**
         * Enrich the output of getAvailableExtensions() with an array key installed = 1 if an extension is loaded.
         *
         * @param array $availableExtensions
         * @return array
         */
        public function getAvailableAndInstalledExtensions(array $availableExtensions) {
-               foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $properties) {
-                       if (array_key_exists($extKey, $availableExtensions)) {
+               foreach (array_keys($this->packageManager->getActivePackages()) as $extKey) {
+                       if (isset($availableExtensions[$extKey])) {
                                $availableExtensions[$extKey]['installed'] = TRUE;
                        }
                }
@@ -143,5 +164,4 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $availableAndInstalledExtensions = $this->getAvailableAndInstalledExtensions($availableExtensions);
                return $this->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
        }
-
 }
index afefba3..c50f868 100644 (file)
@@ -23,6 +23,7 @@ namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
  *
  * This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Cms\Package;
 
 /**
  * List utility test
@@ -33,37 +34,32 @@ class ListUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
         */
-       private $fixture;
-
-       private $loadedExtensions = array();
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
-        */
-       protected $mockObjectManager;
+       private $subject;
 
        /**
         * @return void
         */
        public function setUp() {
-               $this->fixture = new \TYPO3\CMS\Extensionmanager\Utility\ListUtility();
-               $this->loadedExtensions = $GLOBALS['TYPO3_LOADED_EXT'];
-               $GLOBALS['TYPO3_LOADED_EXT'] = array(
-                       'cms' => 'cms',
-                       'lang' => 'lang',
-                       'news' => 'news',
-                       'saltedpasswords' => 'saltedpasswords',
-                       'rsaauth' => 'rsaauth'
-               );
-               $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
+               $this->subject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility', array('emitPackagesMayHaveChanged'));
+               $packageManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager');
+               $packageManagerMock
+                               ->expects($this->any())
+                               ->method('getActivePackages')
+                               ->will($this->returnValue(array(
+                                       'cms' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
+                                       'lang' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
+                                       'news' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
+                                       'saltedpasswords' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
+                                       'rsaauth' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
+                               )));
+               $this->inject($this->subject, 'packageManager', $packageManagerMock);
        }
 
        /**
         * @return void
         */
        public function tearDown() {
-               unset($this->fixture);
-               $GLOBALS['TYPO3_LOADED_EXT'] = $this->loadedExtensions;
+               unset($this->subject);
        }
 
        /**
@@ -152,7 +148,7 @@ class ListUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @return void
         */
        public function getAvailableAndInstalledExtensionsTest($availableExtensions, $expectedResult) {
-               $this->assertEquals($expectedResult, $this->fixture->getAvailableAndInstalledExtensions($availableExtensions));
+               $this->assertEquals($expectedResult, $this->subject->getAvailableAndInstalledExtensions($availableExtensions));
        }
 
        /**
@@ -191,10 +187,10 @@ class ListUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @return void
         */
        public function enrichExtensionsWithEmConfInformation($extensions, $emConf, $expectedResult) {
-               $this->fixture->extensionRepository = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('findOneByExtensionKeyAndVersion'), array(), '', FALSE);
-               $this->fixture->emConfUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\EmConfUtility');
-               $this->fixture->emConfUtility->expects($this->any())->method('includeEmConf')->will($this->returnValue($emConf));
-               $this->assertEquals($expectedResult, $this->fixture->enrichExtensionsWithEmConfAndTerInformation($extensions));
+               $this->inject($this->subject, 'extensionRepository', $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('findOneByExtensionKeyAndVersion'), 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);
+               $this->assertEquals($expectedResult, $this->subject->enrichExtensionsWithEmConfAndTerInformation($extensions));
        }
-
 }
index 47c4e56..4326bce 100644 (file)
@@ -30,17 +30,24 @@ namespace TYPO3\CMS\Lang\Command;
 class UpdateCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
 
        /**
+        * @var \TYPO3\CMS\Core\Package\PackageManager
+        * @inject
+        */
+       protected $packageManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        * @inject
+        */
+       protected $signalSlotDispatcher;
+
+       /**
         * Update language file for each extension
         *
         * @param string $localesToUpdate Comma separated list of locales that needs to be updated
         * @return void
         */
        public function updateCommand($localesToUpdate = '') {
-               /** @var $listUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility */
-               $listUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
-               $availableExtensions = $listUtility->getAvailableExtensions();
-               $extensions = $listUtility->getAvailableAndInstalledExtensions($availableExtensions);
-
                /** @var $updateTranslationService \TYPO3\CMS\Lang\Service\UpdateTranslationService */
                $updateTranslationService = $this->objectManager->get('TYPO3\\CMS\\Lang\Service\\UpdateTranslationService');
                /** @var $languageRepository \TYPO3\CMS\Lang\Domain\Repository\LanguageRepository */
@@ -55,10 +62,17 @@ class UpdateCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandC
                                $locales[] = $language->getLocale();
                        }
                }
-
-               foreach ($extensions as $extension) {
-                       $updateTranslationService->updateTranslation($extension['key'], $locales);
+               $this->packageManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Package\\PackageManager');
+               $this->emitPackagesMayHaveChanged();
+               foreach ($this->packageManager->getAvailablePackages() as $package) {
+                       $updateTranslationService->updateTranslation($package->getPackageKey(), $locales);
                }
        }
 
+       /**
+        * Emits packages may have changed signal
+        */
+       protected function emitPackagesMayHaveChanged() {
+               $this->signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
+       }
 }
index c16d7cb..43ed13b 100644 (file)
@@ -71,11 +71,7 @@ class ExtensionRepository {
         */
        public function findAll() {
                if (!count($this->extensions)) {
-                       $availableExtensions = $this->listUtility->getAvailableExtensions();
-                       $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($availableExtensions);
-                       $availableAndInstalledExtensions = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
-                               $availableAndInstalledExtensions
-                       );
+                       $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
 
                        foreach ($availableAndInstalledExtensions as $entry) {
                                /** @var $extension \TYPO3\CMS\Lang\Domain\Model\Extension */