Fix style preview images when upgrading from 5.2
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 19 Nov 2020 15:09:29 +0000 (16:09 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 19 Nov 2020 15:09:29 +0000 (16:09 +0100)
com.woltlab.wcf/package.xml
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.1_faviconTemplate.php [deleted file]
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.1_style.php [new file with mode: 0644]
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3_style.php

index cf409de0b5b04d3860a03556b4e2cce5b6511e52..2c033b692b21010a6bf86fce440e36087fb0cb0c 100644 (file)
        </instructions>
        
        <!-- Run the option.xml update for 5.3.0 -> 5.3.1, due to the missing removal of external_link_rel_nofollow. -->
-       <!-- Run update_com.woltlab.wcf_5.3.1_faviconTemplate.php for 5.3.0 -> 5.3.1 -->
+       <!-- Run update_com.woltlab.wcf_5.3.1_style.php for 5.3.0 -> 5.3.1 -->
        <!-- 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.
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.1_faviconTemplate.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.1_faviconTemplate.php
deleted file mode 100644 (file)
index 79465a3..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-
-use wcf\data\style\StyleList;
-
-/**
- * @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) {
-       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
-                       );
-               }
-       }
-}
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
new file mode 100644 (file)
index 0000000..535706b
--- /dev/null
@@ -0,0 +1,53 @@
+<?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,
+               ]);
+       }
+}
index 27fe4cfe2ba46ced987d092f8b2c067183171ca1..888aea40a0d466282f53137e3d9b92116e82dd55 100644 (file)
@@ -81,23 +81,25 @@ foreach ($styleList as $style) {
        // Moving *should* be safe here, unless the admin manually edited the style, but better play safe.
        if ($style->image && file_exists(WCF_DIR . 'images/' . $style->image)) {
                $extension = pathinfo($style->image, PATHINFO_EXTENSION);
+               $newName =  'stylePreview.' . $extension;
                copy(
                        WCF_DIR . 'images/' . $style->image,
-                       $style->getAssetPath() . 'stylePreview.' . $extension
+                       $style->getAssetPath() . $newName
                );
                $styleEditor->update([
-                       'image' => 'stylePreview.' . $extension,
+                       'image' => FileUtil::getRelativePath(WCF_DIR.'images/', $style->getAssetPath()) . $newName,
                ]);
        }
 
        if ($style->image2x && file_exists(WCF_DIR . 'images/' . $style->image2x)) {
                $extension = pathinfo($style->image2x, PATHINFO_EXTENSION);
+               $newName = 'stylePreview@2x.' . $extension;
                copy(
                        WCF_DIR . 'images/' . $style->image2x,
-                       $style->getAssetPath() . 'stylePreview@2x.' . $extension
+                       $style->getAssetPath() . $newName
                );
                $styleEditor->update([
-                       'image2x' => 'stylePreview@2x.' . $extension,
+                       'image2x' => FileUtil::getRelativePath(WCF_DIR.'images/', $style->getAssetPath()) . $newName,
                ]);
        }