From: Alexander Ebert Date: Tue, 23 Jul 2019 15:36:34 +0000 (+0200) Subject: Override the active application on runtime X-Git-Tag: 5.2.0_Alpha_3~14 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b26a42b276d4a5570c75211a155387d2f50f9fa2;p=GitHub%2FWoltLab%2FWCF.git Override the active application on runtime Fixes #2934 --- diff --git a/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php b/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php index 8bc8e144f9..37ba6dee08 100644 --- a/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php +++ b/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php @@ -69,10 +69,7 @@ abstract class AbstractApplication extends SingletonFactory implements IApplicat $this->packageID = $application->packageID; - // check if current application is active (directly invoked, not dependent) - if ($application->packageID == ApplicationHandler::getInstance()->getActiveApplication()->packageID) { - $this->isActiveApplication = true; - } + $this->rebuildActiveApplication(); } /** @@ -119,6 +116,13 @@ abstract class AbstractApplication extends SingletonFactory implements IApplicat return $this->primaryController; } + /** + * @since 5.2 + */ + public function rebuildActiveApplication() { + $this->isActiveApplication = ($this->packageID == ApplicationHandler::getInstance()->getActiveApplication()->packageID); + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/application/ApplicationHandler.class.php b/wcfsetup/install/files/lib/system/application/ApplicationHandler.class.php index 6441b66dc6..675a807fd2 100644 --- a/wcfsetup/install/files/lib/system/application/ApplicationHandler.class.php +++ b/wcfsetup/install/files/lib/system/application/ApplicationHandler.class.php @@ -6,9 +6,11 @@ use wcf\data\application\ApplicationList; use wcf\data\package\Package; use wcf\data\package\PackageList; use wcf\system\cache\builder\ApplicationCacheBuilder; +use wcf\system\request\RequestHandler; use wcf\system\request\RouteHandler; use wcf\system\Regex; use wcf\system\SingletonFactory; +use wcf\system\WCF; use wcf\util\FileUtil; /** @@ -118,10 +120,18 @@ class ApplicationHandler extends SingletonFactory { return new Application(null, [ 'domainName' => $host, 'domainPath' => $path, - 'cookieDomain' => $host + 'cookieDomain' => $host, ]); } - else if (isset($this->cache['application'][PACKAGE_ID])) { + + $request = RequestHandler::getInstance()->getActiveRequest(); + if ($request !== null) { + $abbreviation = substr($request->getClassName(), 0, mb_strpos($request->getClassName(), '\\')); + + return $this->getApplication($abbreviation); + } + + if (isset($this->cache['application'][PACKAGE_ID])) { return $this->cache['application'][PACKAGE_ID]; } @@ -230,6 +240,23 @@ class ApplicationHandler extends SingletonFactory { return $this->isMultiDomain; } + /** + * @since 5.2 + */ + public function rebuildActiveApplication() { + /** @var AbstractApplication $application */ + foreach ($this->cache['application'] as $application) { + if ($application->getPackage()->package === 'com.woltlab.wcf') { + continue; + } + + $appObject = WCF::getApplicationObject($application); + if ($appObject instanceof AbstractApplication) { + $appObject->rebuildActiveApplication(); + } + } + } + /** * Rebuilds cookie domain/path for all applications. */ diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index bace28189e..5fbac25b77 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -224,6 +224,8 @@ class RequestHandler extends SingletonFactory { $this->activeRequest->setIsLandingPage(); } } + + ApplicationHandler::getInstance()->rebuildActiveApplication(); } catch (SystemException $e) { if (defined('ENABLE_DEBUG_MODE') && ENABLE_DEBUG_MODE && defined('ENABLE_DEVELOPER_TOOLS') && ENABLE_DEVELOPER_TOOLS) {