Prevent `individualScssDarkMode` being set for the dark mode
authorAlexander Ebert <ebert@woltlab.com>
Thu, 16 Nov 2023 15:05:13 +0000 (16:05 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 16 Nov 2023 15:05:13 +0000 (16:05 +0100)
See https://www.woltlab.com/community/thread/302775-fatal-error-invalid-value-source/

wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0.1.php [deleted file]
wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0.3.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/style/StyleEditor.class.php

diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0.1.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0.1.php
deleted file mode 100644 (file)
index a8c42e0..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-
-/**
- * Fixes the style variable value of `individualScssDarkMode`.
- *
- * @author Alexander Ebert
- * @copyright 2001-2023 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- */
-
-use wcf\system\WCF;
-
-// Fix the default value for style variables.
-$sql = "UPDATE  wcf1_style_variable
-        SET     defaultValueDarkMode = ?
-        WHERE   variableName = ?";
-$statement = WCF::getDB()->prepare($sql);
-$statement->execute([null, 'individualScssDarkMode']);
-
-// Fixes any bad values stored for existing styles.
-$sql = "UPDATE  wcf1_style_variable_value
-        SET     variableValueDarkMode = ?
-        WHERE   variableID = (
-                    SELECT  variableID
-                    FROM    wcf1_style_variable
-                    WHERE   variableName = ?
-                )";
-$statement = WCF::getDB()->prepare($sql);
-$statement->execute([null, 'individualScssDarkMode']);
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0.3.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_6.0.3.php
new file mode 100644 (file)
index 0000000..a8c42e0
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * Fixes the style variable value of `individualScssDarkMode`.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+
+use wcf\system\WCF;
+
+// Fix the default value for style variables.
+$sql = "UPDATE  wcf1_style_variable
+        SET     defaultValueDarkMode = ?
+        WHERE   variableName = ?";
+$statement = WCF::getDB()->prepare($sql);
+$statement->execute([null, 'individualScssDarkMode']);
+
+// Fixes any bad values stored for existing styles.
+$sql = "UPDATE  wcf1_style_variable_value
+        SET     variableValueDarkMode = ?
+        WHERE   variableID = (
+                    SELECT  variableID
+                    FROM    wcf1_style_variable
+                    WHERE   variableName = ?
+                )";
+$statement = WCF::getDB()->prepare($sql);
+$statement->execute([null, 'individualScssDarkMode']);
index 1ba83ab8b459cacc64f46a6e187959beb0e1266d..5a980c568045299740c1acf45aaa09dd097ef1e0 100644 (file)
@@ -76,7 +76,12 @@ final class StyleEditor extends DatabaseObjectEditor implements IEditableCachedO
             $prefixLength = \strlen(Style::DARK_MODE_PREFIX);
             foreach ($inputVariables as $variableName => $variableValue) {
                 if (\str_starts_with($variableName, Style::DARK_MODE_PREFIX)) {
-                    $variablesDarkMode[\substr($variableName, $prefixLength)] = $variableValue;
+                    $variableName = \substr($variableName, $prefixLength);
+                    if ($variableName === 'individualScssDarkMode') {
+                        continue;
+                    }
+
+                    $variablesDarkMode[$variableName] = $variableValue;
                 } else {
                     $variables[$variableName] = $variableValue;
                 }
@@ -1045,6 +1050,10 @@ final class StyleEditor extends DatabaseObjectEditor implements IEditableCachedO
             $statement = WCF::getDB()->prepare($sql);
             $statement->execute([$this->styleID]);
             while ($row = $statement->fetchArray()) {
+                if ($row['variableName'] === 'individualScssDarkMode') {
+                    continue;
+                }
+
                 $xml->writeElement('variable', $row['variableValueDarkMode'], ['name' => $row['variableName']]);
             }