Merge branch '5.5'
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 31 Mar 2023 10:35:27 +0000 (12:35 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 31 Mar 2023 10:35:27 +0000 (12:35 +0200)
1  2 
wcfsetup/install/files/lib/data/style/StyleEditor.class.php

index e6892b302caee9a55878eb873416d914fd74096a,c1b3011a0bdf3b57669de05ee4a3299c168110ea..f9f219238954023183f9d5aa3e3d4b40f7d98edf
@@@ -1204,40 -1186,52 +1204,40 @@@ final class StyleEditor extends Databas
       * Sets the variables of a style.
       *
       * @param string[] $variables
 +     * @param string[] $variablesDarkMode
       */
 -    public function setVariables(array $variables = [])
 +    public function setVariables(array $variables, array $variablesDarkMode): void
      {
 -        // delete old variables
 -        $sql = "DELETE FROM wcf" . WCF_N . "_style_variable_value
 -                WHERE       styleID = ?";
 -        $statement = WCF::getDB()->prepareStatement($sql);
 -        $statement->execute([$this->styleID]);
 -
 -        // insert new variables
 -        if (!empty($variables)) {
 -            $sql = "SELECT  *
 -                    FROM    wcf" . WCF_N . "_style_variable";
 -            $statement = WCF::getDB()->prepareStatement($sql);
 -            $statement->execute();
 -            $styleVariables = [];
 -            while ($row = $statement->fetchArray()) {
 -                $variableName = $row['variableName'];
 -
 -                if (isset($variables[$variableName])) {
 -                    // compare value, save only if differs from default
 -                    if ($variables[$variableName] != $row['defaultValue']) {
 -                        $styleVariables[$row['variableID']] = $variables[$variableName];
 -                    }
 -                }
 -            }
 -
 -            if (!empty($styleVariables)) {
 -                $sql = "INSERT INTO wcf" . WCF_N . "_style_variable_value
 -                                    (styleID, variableID, variableValue)
 -                        VALUES      (?, ?, ?)";
 -                $statement = WCF::getDB()->prepareStatement($sql);
 -
 -                WCF::getDB()->beginTransaction();
 -                foreach ($styleVariables as $variableID => $variableValue) {
 -                    $statement->execute([
 -                        $this->styleID,
 -                        $variableID,
 -                        $variableValue,
 -                    ]);
 -                }
 -                WCF::getDB()->commitTransaction();
 -            }
 +        $sql = "SELECT  variableID, variableName
 +                FROM    wcf1_style_variable";
 +        $statement = WCF::getDB()->prepare($sql);
 +        $statement->execute();
 +        $styleVariables = $statement->fetchMap('variableID', 'variableName');
 +
 +        $variables = \array_filter($variables, static function (string $key) use ($styleVariables) {
 +            return \in_array($key, $styleVariables, true);
 +        }, \ARRAY_FILTER_USE_KEY);
 +
 +        $variablesDarkMode = \array_filter($variablesDarkMode, static function (string $key) use ($styleVariables) {
 +            return \in_array($key, $styleVariables, true);
 +        }, \ARRAY_FILTER_USE_KEY);
 +
 +        $sql = "INSERT INTO             wcf1_style_variable_value
 +                                        (styleID, variableID, variableValue, variableValueDarkMode)
 +                VALUES                  (?, ?, ?, ?)
 +                ON DUPLICATE KEY UPDATE variableValue = VALUES(variableValue),
 +                                        variableValueDarkMode = VALUES(variableValueDarkMode)";
 +        $statement = WCF::getDB()->prepare($sql);
 +        foreach ($styleVariables as $variableID => $variableName) {
 +            $statement->execute([
 +                $this->styleID,
 +                $variableID,
 +                $variables[$variableName] ?? null,
 +                $variablesDarkMode[$variableName] ?? null,
 +            ]);
          }
  
-         $this->writeStyleFile();
+         StyleHandler::getInstance()->resetStylesheet($this->getDecoratedObject());
      }
  
      /**