From 1775195462de2c755936fba3c609a73f16e7acf2 Mon Sep 17 00:00:00 2001
From: Thomas Maroschik <tmaroschik@dfau.de>
Date: Tue, 11 Feb 2014 15:26:27 +0100
Subject: [PATCH] [BUGFIX] Fix fatal errors upon package installation

During the installation of packages via the extension
manager a fatal error can occur when the ext_localconf
and ext_tables are loaded and use classes from their own
package. This happens because the package is activated
but the class loader is not aware yet of the new package.

This patch adds the extension temporarily to the runtime
activated packages in the class loader.

Fixes: #53795
Releases: 6.2
Change-Id: I195b86284b9a288f4d7c102168ec18ed8683cb07
Reviewed-on: https://review.typo3.org/27544
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
---
 typo3/sysext/core/Classes/Core/ClassLoader.php      | 13 ++++++++-----
 .../sysext/core/Classes/Package/PackageManager.php  |  3 ++-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/typo3/sysext/core/Classes/Core/ClassLoader.php b/typo3/sysext/core/Classes/Core/ClassLoader.php
index 88d15f73f8ae..fb03dc23e01c 100644
--- a/typo3/sysext/core/Classes/Core/ClassLoader.php
+++ b/typo3/sysext/core/Classes/Core/ClassLoader.php
@@ -399,11 +399,14 @@ class ClassLoader {
 	 * @param \TYPO3\Flow\Package\PackageInterface $package
 	 * @return ClassLoader
 	 */
-	public function addRuntimeActivatedPackage(\TYPO3\Flow\Package\PackageInterface $package) {
-		$this->packages[] = $package;
-		$this->buildPackageNamespaceAndClassesPath($package);
-		$this->sortPackageNamespaces();
-		$this->loadClassFilesFromAutoloadRegistryIntoRuntimeClassInformationCache(array($package));
+	public function addActivePackage(\TYPO3\Flow\Package\PackageInterface $package) {
+		$packageKey = $package->getPackageKey();
+		if (!isset($this->packages[$packageKey])) {
+			$this->packages[$packageKey] = $package;
+			$this->buildPackageNamespaceAndClassesPath($package);
+			$this->sortPackageNamespaces();
+			$this->loadClassFilesFromAutoloadRegistryIntoRuntimeClassInformationCache(array($package));
+		}
 		return $this;
 	}
 
diff --git a/typo3/sysext/core/Classes/Package/PackageManager.php b/typo3/sysext/core/Classes/Package/PackageManager.php
index 00ca8bd5be9b..b46867ca1796 100644
--- a/typo3/sysext/core/Classes/Package/PackageManager.php
+++ b/typo3/sysext/core/Classes/Package/PackageManager.php
@@ -531,6 +531,7 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 	public function activatePackage($packageKey) {
 		$package = $this->getPackage($packageKey);
 		parent::activatePackage($package->getPackageKey());
+		$this->classLoader->addActivePackage($package);
 	}
 
 	/**
@@ -542,7 +543,7 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 	public function activatePackageDuringRuntime($packageKey) {
 		$package = $this->getPackage($packageKey);
 		$this->runtimeActivatedPackages[$package->getPackageKey()] = $package;
-		$this->classLoader->addRuntimeActivatedPackage($package);
+		$this->classLoader->addActivePackage($package);
 	}
 
 
-- 
GitLab