Incorrect handling of overridden application ownerships of pages
authorAlexander Ebert <ebert@woltlab.com>
Thu, 25 Apr 2019 16:24:29 +0000 (18:24 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 25 Apr 2019 16:24:29 +0000 (18:24 +0200)
Fixes #2905

wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php
wcfsetup/install/files/lib/system/request/ControllerMap.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php

index c16ead28610dc9e318d3a8f39c569e9bcfd85833..b68e7fa052b297124b44267d9d2dd0bb64c96bb6 100644 (file)
@@ -42,6 +42,8 @@ class RoutingCacheBuilder extends AbstractCacheBuilder {
                $data['customUrls'] = $this->getCustomUrls($data['landingPages']);
                $data['applicationOverrides'] = $this->getApplicationOverrides($data['customUrls']);
                
+               $this->handleLandingPageWithOverriddenApplication($data);
+               
                return $data;
        }
        
@@ -345,4 +347,27 @@ class RoutingCacheBuilder extends AbstractCacheBuilder {
                
                return $data;
        }
+       
+       protected function handleLandingPageWithOverriddenApplication(array &$data) {
+               $landingPageController = $data['landingPages']['wcf'][0];
+               $controllers = [$landingPageController];
+               
+               // The controller may be the custom url of a CMS page.
+               if (strpos($landingPageController, '__WCF_CMS__') === 0) {
+                       $controllers = array_filter($data['customUrls']['reverse']['wcf'], function($controller) use ($landingPageController) {
+                               return strpos($controller, "{$landingPageController}-") === 0;
+                       }, ARRAY_FILTER_USE_KEY);
+               }
+               
+               foreach ($controllers as $controller) {
+                       if (isset($data['applicationOverrides']['reverse']['wcf'][$controller])) {
+                               $overriddenApplication = $data['applicationOverrides']['reverse']['wcf'][$controller];
+                               
+                               // The original landing page of the target app has been implicitly overridden, thus we need to
+                               // replace the data of the affected app. This is necessary in order to avoid the original landing
+                               // page to be conflicting with the global landing page, eventually overshadowing it.
+                               $data['landingPages'][$overriddenApplication] = array_slice($data['landingPages']['wcf'], 0);
+                       }
+               }
+       }
 }
index d1c38bd526acc57010744b22cf27b0c12a146fb0..e26d1b31298a0f2e6b843fd1fcc78c645463699c 100644 (file)
@@ -254,7 +254,7 @@ class ControllerMap extends SingletonFactory {
                        }
                        
                        // different application, redirect instead
-                       if ($cmsPageData['application'] !== $application) {
+                       if ($cmsPageData['application'] !== $application && $this->getApplicationOverride($application, $cmsPageData['controller']) !== $application) {
                                return ['redirect' => LinkHandler::getInstance()->getCmsLink($matches['pageID'])];
                        }
                        else {
index e27cd1f700a2fff8ef916516183511dc8681d4c8..7255c372047e187b164074b5534cd6c9460cb0ff 100644 (file)
@@ -269,13 +269,16 @@ class RequestHandler extends SingletonFactory {
                        exit;
                }
                else if (!empty($data['application']) && $data['application'] !== $application) {
-                       HeaderUtil::redirect(
-                               LinkHandler::getInstance()->getLink(
-                                       ControllerMap::getInstance()->resolve($data['application'], $data['controller'], false)['controller'],
-                                       ['application' => $data['application']]
-                               ), true, true
-                       );
-                       exit;
+                       $override = ControllerMap::getInstance()->getApplicationOverride($application, $data['controller']);
+                       if ($application !== $override) {
+                               HeaderUtil::redirect(
+                                       LinkHandler::getInstance()->getLink(
+                                               ControllerMap::getInstance()->resolve($data['application'], $data['controller'], false)['controller'],
+                                               ['application' => $data['application']]
+                                       ), true, true
+                               );
+                               exit;
+                       }
                }
                
                // copy route data