Clean up data flow in LinkHandler::getCmsLink()
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 13 Jun 2022 12:00:56 +0000 (14:00 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 13 Jun 2022 12:01:22 +0000 (14:01 +0200)
wcfsetup/install/files/lib/system/request/LinkHandler.class.php

index 5e3899e48bddd31972763bb6b106af40bde4f446..bbb666033bdbf92bd1235cac0289f76b2b39a11b 100644 (file)
@@ -280,35 +280,29 @@ class LinkHandler extends SingletonFactory
      */
     public function getCmsLink($pageID, $languageID = -1)
     {
+        $data = null;
+
         // use current language
         if ($languageID === -1) {
             $data = ControllerMap::getInstance()->lookupCmsPage($pageID, WCF::getLanguage()->languageID);
 
-            // no result
-            if ($data === null) {
-                // attempt to use the default language instead
-                if (LanguageFactory::getInstance()->getDefaultLanguageID() != WCF::getLanguage()->languageID) {
-                    $data = ControllerMap::getInstance()
-                        ->lookupCmsPage($pageID, LanguageFactory::getInstance()->getDefaultLanguageID());
-                }
-
-                // no result, possibly this is a non-multilingual page
-                if ($data === null) {
-                    $data = ControllerMap::getInstance()->lookupCmsPage($pageID, null);
-                }
+            // no result, attempt to use the default language instead
+            $defaultLanguageID = LanguageFactory::getInstance()->getDefaultLanguageID();
+            if ($data === null && $defaultLanguageID != WCF::getLanguage()->languageID) {
+                $data = ControllerMap::getInstance()->lookupCmsPage($pageID, $defaultLanguageID);
+            }
 
-                // still no result, page does not exist at all
-                if ($data === null) {
-                    return '';
-                }
+            // no result, possibly this is a non-multilingual page
+            if ($data === null) {
+                $data = ControllerMap::getInstance()->lookupCmsPage($pageID, null);
             }
         } else {
             $data = ControllerMap::getInstance()->lookupCmsPage($pageID, $languageID);
+        }
 
-            // no result, page does not exist or at least not in the given language
-            if ($data === null) {
-                return '';
-            }
+        // no result, page does not exist or at least not in the given language
+        if ($data === null) {
+            return '';
         }
 
         return $this->getLink($data['controller'], [