Remove styleID from SessionHandler
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 30 May 2022 13:49:37 +0000 (15:49 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 30 May 2022 13:50:45 +0000 (15:50 +0200)
See 094ee7c31ce505b293fc228d6831ecb4a42130cc for the majority of performed
changes.

Resolves #4835

wcfsetup/install/files/lib/data/style/StyleAction.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/session/SessionHandler.class.php

index b0a53c826ddfdadb5f0b156640796b9656ef1b04..78bc94e4711a2e42bb19cb42a900e9b913d99069 100644 (file)
@@ -685,8 +685,6 @@ BROWSERCONFIG;
     {
         StyleHandler::getInstance()->changeStyle($this->style->styleID);
         if (StyleHandler::getInstance()->getStyle()->styleID == $this->style->styleID) {
-            WCF::getSession()->setStyleID($this->style->styleID);
-
             if (WCF::getUser()->userID) {
                 // set this as the permanent style
                 $userAction = new UserAction([WCF::getUser()], 'update', [
@@ -695,6 +693,12 @@ BROWSERCONFIG;
                     ],
                 ]);
                 $userAction->executeAction();
+            } else {
+                if ($this->style->isDefault) {
+                    WCF::getSession()->unregister('styleID');
+                } else {
+                    WCF::getSession()->register('styleID', $this->style->styleID);
+                }
             }
         }
     }
index 93d9d5fcac5a612259cba8e149abb9aef9cc2a84..0c0c611d7d3d09364da9846778a1712252df1a71 100644 (file)
@@ -541,8 +541,14 @@ class WCF
      */
     protected function initStyle()
     {
+        if (self::getSession()->getUser()->userID) {
+            $styleID = self::getSession()->getUser()->styleID ?: 0;
+        } else {
+            $styleID = self::getSession()->getVar('styleID') ?: 0;
+        }
+
         $styleHandler = StyleHandler::getInstance();
-        $styleHandler->changeStyle(self::getSession()->getStyleID());
+        $styleHandler->changeStyle($styleID);
     }
 
     /**
index 313607629770168f4ea9a178c335052209331f93..3b9005ec3ed2110a33476e5a40bbcba4c6e75c3d 100644 (file)
@@ -88,12 +88,6 @@ final class SessionHandler extends SingletonFactory
      */
     protected $legacySession;
 
-    /**
-     * style id
-     * @var int
-     */
-    protected $styleID;
-
     /**
      * user object
      * @var User
@@ -414,9 +408,8 @@ final class SessionHandler extends SingletonFactory
     {
         $this->defineConstants();
 
-        // assign language and style id
+        // assign language
         $this->languageID = $this->getVar('languageID') ?: $this->user->languageID;
-        $this->styleID = $this->getVar('styleID') ?: $this->user->styleID;
 
         // https://github.com/WoltLab/WCF/issues/2568
         if ($this->getVar('__wcfIsFirstVisit') === true) {
@@ -1015,7 +1008,6 @@ final class SessionHandler extends SingletonFactory
         $this->groupData = null;
         $this->languageIDs = null;
         $this->languageID = $this->user->languageID;
-        $this->styleID = $this->user->styleID;
 
         // change language
         WCF::setLanguage($this->languageID ?: 0);
@@ -1360,23 +1352,6 @@ final class SessionHandler extends SingletonFactory
         $this->register('languageID', $this->languageID);
     }
 
-    /**
-     * @deprecated 5.5 - Use `StyleHandler::getInstance()->getStyle()->styleID` instead.
-     */
-    public function getStyleID()
-    {
-        return $this->styleID;
-    }
-
-    /**
-     * @deprecated 5.5 - Set the style directly with the `StyleAction::changeStyle()`.
-     */
-    public function setStyleID($styleID)
-    {
-        $this->styleID = $styleID;
-        $this->register('styleID', $this->styleID);
-    }
-
     /**
      * Resets session-specific storage data.
      *