[BUGFIX] Reload ext_emconf.php after extension update 35/40935/5
authorNicole Cordes <typo3@cordes.co>
Mon, 6 Jul 2015 19:55:42 +0000 (21:55 +0200)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Tue, 6 Oct 2015 06:39:58 +0000 (08:39 +0200)
If you overwrite an extension or download a new version with the
extension manager, the dependency check uses old ext_emconf dependencies
which are stored in the PackageManager. This patch extends the
PackageManager api to be able to create a new Package instance with
fresh ext_emconf information and replace the current instance. This new
function is called after an extension was extracted from a file or
was downloaded from the extension manager.

Resolves: #67367
Releases: master
Change-Id: I4d4dbb94aaafcbe1d99f496039d17d4856bce3bd
Reviewed-on: http://review.typo3.org/40935
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/core/Classes/Package/PackageManager.php
typo3/sysext/extensionmanager/Classes/Controller/UploadExtensionFileController.php
typo3/sysext/extensionmanager/Classes/Service/ExtensionManagementService.php
typo3/sysext/extensionmanager/Classes/Utility/FileHandlingUtility.php
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/FileHandlingUtilityTest.php

index 4d0c0a6..c2fa67c 100644 (file)
@@ -845,6 +845,28 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * Reloads a package and its information
+        *
+        * @param string $packageKey
+        * @throws Exception\InvalidPackageStateException if the package isn't available
+        * @throws Exception\InvalidPackageKeyException if an invalid package key was passed
+        * @throws Exception\InvalidPackagePathException if an invalid package path was passed
+        * @throws Exception\InvalidPackageManifestException if no extension configuration file could be found
+        */
+       public function reloadPackageInformation($packageKey) {
+               if (!$this->isPackageAvailable($packageKey)) {
+                       throw new Exception\InvalidPackageStateException('Package "' . $packageKey . '" is not registered.', 1436201329);
+               }
+
+               /** @var PackageInterface $package */
+               $package = $this->packages[$packageKey];
+               $packagePath = $package->getPackagePath();
+               $newPackage = new Package($this, $packageKey, $packagePath);
+               $this->packages[$packageKey] = $newPackage;
+               unset($package);
+       }
+
+       /**
         * Scans all sub directories of the specified directory and collects the package keys of packages it finds.
         *
         * The return of the array is to make this method usable in array_merge.
index c85eb6d..25ac082 100644 (file)
@@ -204,6 +204,7 @@ class UploadExtensionFileController extends AbstractController {
         * @return bool
         */
        public function activateExtension($extensionKey) {
+               $this->managementService->reloadPackageInformation($extensionKey);
                $extension = $this->managementService->getExtension($extensionKey);
                return is_array($this->managementService->installExtension($extension));
        }
index fb313fc..e04098e 100644 (file)
@@ -229,6 +229,17 @@ class ExtensionManagementService implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * @param string $extensionKey
+        * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageStateException if the package isn't available
+        * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageKeyException if an invalid package key was passed
+        * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackagePathException if an invalid package path was passed
+        * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageManifestException if no extension configuration file could be found
+        */
+       public function reloadPackageInformation($extensionKey) {
+               $this->installUtility->reloadPackageInformation($extensionKey);
+       }
+
+       /**
         * Download an extension
         *
         * @param Extension $extension
index 7ba6ab3..61dfb0c 100644 (file)
@@ -84,6 +84,7 @@ class FileHandlingUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $this->createDirectoriesForExtensionFiles($directories, $extensionDir);
                $this->writeExtensionFiles($files, $extensionDir);
                $this->writeEmConfToFile($extensionData, $extensionDir, $extension);
+               $this->reloadPackageInformation($extensionData['extKey']);
        }
 
        /**
@@ -518,4 +519,11 @@ class FileHandlingUtility implements \TYPO3\CMS\Core\SingletonInterface {
                die;
        }
 
+       /**
+        * @param string $extensionKey
+        */
+       protected function reloadPackageInformation($extensionKey) {
+               $this->installUtility->reloadPackageInformation($extensionKey);
+       }
+
 }
index c8f7335..0b05fb1 100644 (file)
@@ -268,6 +268,22 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * Reloads the package information, if the package is already registered
+        *
+        * @param string $extensionKey
+        * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageStateException if the package isn't available
+        * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageKeyException if an invalid package key was passed
+        * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackagePathException if an invalid package path was passed
+        * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageManifestException if no extension configuration file could be found
+        */
+       public function reloadPackageInformation($extensionKey) {
+               if ($this->packageManager->isPackageAvailable($extensionKey)) {
+                       $this->reloadOpcache();
+                       $this->packageManager->reloadPackageInformation($extensionKey);
+               }
+       }
+
+       /**
         * Fetch additional information for an extension key
         *
         * @param string $extensionKey
@@ -368,12 +384,19 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
         * @return void
         */
        public function reloadCaches() {
-               GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
+               $this->reloadOpcache();
                \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtLocalconf(FALSE);
                \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(FALSE);
        }
 
        /**
+        * Reloads PHP opcache
+        */
+       protected function reloadOpcache() {
+               GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
+       }
+
+       /**
         * Save default configuration of an extension
         *
         * @param string $extensionKey
index 5cd6970..fb1b895 100644 (file)
@@ -211,7 +211,8 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'extractFilesArrayFromExtensionData',
                        'extractDirectoriesFromExtensionData',
                        'createDirectoriesForExtensionFiles',
-                       'writeExtensionFiles'
+                       'writeExtensionFiles',
+                       'reloadPackageInformation',
                ));
                $fileHandlerMock->expects($this->once())->method('extractFilesArrayFromExtensionData')->will($this->returnValue(array()));
                $fileHandlerMock->expects($this->once())->method('extractDirectoriesFromExtensionData')->will($this->returnValue(array()));
@@ -277,12 +278,14 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'extractFilesArrayFromExtensionData',
                        'extractDirectoriesFromExtensionData',
                        'createDirectoriesForExtensionFiles',
-                       'writeExtensionFiles'
+                       'writeExtensionFiles',
+                       'reloadPackageInformation',
                ));
                $fileHandlerMock->expects($this->once())->method('extractFilesArrayFromExtensionData')->will($this->returnValue($files));
                $fileHandlerMock->expects($this->once())->method('extractDirectoriesFromExtensionData')->will($this->returnValue($directories));
                $fileHandlerMock->expects($this->once())->method('createDirectoriesForExtensionFiles')->with($directories);
                $fileHandlerMock->expects($this->once())->method('writeExtensionFiles')->with($cleanedFiles);
+               $fileHandlerMock->expects($this->once())->method('reloadPackageInformation')->with('test');
                $fileHandlerMock->_call('unpackExtensionFromExtensionDataArray', $extensionData);
        }