Fix style previews pointing to the style's asset folder
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 18 Dec 2020 12:44:57 +0000 (13:44 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 18 Dec 2020 12:44:57 +0000 (13:44 +0100)
update_com.woltlab.wcf_5.3.1_style.php created this situation when the style
did not have a preview image, due to a missing check for a non-empty `image` /
`image2x` property.

com.woltlab.wcf/package.xml
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.1_style.php [deleted file]
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.2_style.php [new file with mode: 0644]

index 4832279135ec9b2cdefcc81fafdf8be7775f47bb..235d02156dafae8c17b1137cb835fb1896c11614 100644 (file)
                <instruction type="sql">update_5.3.sql</instruction>
        </instructions>
        
-       <!-- Run update_com.woltlab.wcf_5.3.1_style.php for 5.3.0 -> 5.3.1 -->
-       <!-- Include `update_com.woltlab.wcf_5.3_orphanedComments.php` in the next update! -->
+       <!-- Run update_com.woltlab.wcf_5.3.2_style.php for 5.3.1 -> 5.3.2 -->
        <!-- Add a note about the updated CSS in email_html.tpl to the release notes:
                https://github.com/WoltLab/WCF/commit/1ac55ad408d5bfab4f69714c6259cc5d09ceb344
                Administrators are highly encouraged to apply the CSS adjustments to their custom template version.
        -->
-       <instructions type="update" fromversion="5.3.0">
-               <instruction type="acpTemplate">acptemplates_update.tar</instruction>
-               <instruction type="file">files_update.tar</instruction>
-               <instruction type="template">templates_update.tar</instruction>
-               
-               <instruction type="language" />
-               
-               <instruction type="option" />
-               
-               <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.3.1_style.php</instruction>
-               <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.3_orphanedComments.php</instruction>
-       </instructions>
 </package>
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.1_style.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.1_style.php
deleted file mode 100644 (file)
index 535706b..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-
-use wcf\data\style\StyleEditor;
-use wcf\data\style\StyleList;
-use wcf\util\FileUtil;
-
-/**
- * @author     Tim Duesterhus
- * @copyright  2001-2020 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    WoltLabSuite\Core
- */
-
-$styleList = new StyleList();
-$styleList->readObjects();
-
-foreach ($styleList as $style) {
-       $styleEditor = new StyleEditor($style);
-       
-       // Fix the name of the favicon template.
-       foreach ([
-               'gif',
-               'jpeg',
-               'jpg',
-               'png',
-       ] as $extension) {
-               if (file_exists($style->getAssetPath() . 'favicon.template.' . $extension)) {
-                       rename(
-                               $style->getAssetPath() . 'favicon.template.' . $extension,
-                               $style->getAssetPath() . 'favicon-template.' . $extension
-                       );
-               }
-       }
-       
-       // Fix the style preview.
-       if (
-               $style->image === basename($style->image) &&
-               file_exists($style->getAssetPath() . $style->image)
-       ) {
-               $styleEditor->update([
-                       'image' => FileUtil::getRelativePath(WCF_DIR.'images/', $style->getAssetPath()) . $style->image,
-               ]);
-       }
-       
-       if (
-               $style->image2x === basename($style->image2x) &&
-               file_exists($style->getAssetPath() . $style->image2x)
-       ) {
-               $styleEditor->update([
-                       'image2x' => FileUtil::getRelativePath(WCF_DIR.'images/', $style->getAssetPath()) . $style->image2x,
-               ]);
-       }
-}
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.2_style.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.2_style.php
new file mode 100644 (file)
index 0000000..7fa8fa9
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+use wcf\data\style\StyleEditor;
+use wcf\data\style\StyleList;
+use wcf\util\FileUtil;
+
+/**
+ * @author     Tim Duesterhus
+ * @copyright  2001-2020 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core
+ */
+
+$styleList = new StyleList();
+$styleList->readObjects();
+
+foreach ($styleList as $style) {
+       $styleEditor = new StyleEditor($style);
+       
+       // Fix the style preview.
+       if (
+               $style->image === FileUtil::getRelativePath(WCF_DIR.'images/', $style->getAssetPath()) ||
+               !is_file($style->image)
+       ) {
+               $styleEditor->update([
+                       'image' => '',
+               ]);
+       }
+       
+       if (
+               $style->image2x === FileUtil::getRelativePath(WCF_DIR.'images/', $style->getAssetPath()) ||
+               !is_file($style->image2x)
+       ) {
+               $styleEditor->update([
+                       'image2x' => '',
+               ]);
+       }
+}