From: Tim Düsterhus Date: Mon, 11 Jan 2021 08:44:05 +0000 (+0100) Subject: Fix the style preview images X-Git-Tag: 5.3.3~27^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b702fb2e82f814bf06d0cdba4a3d3b8269cff72c;p=GitHub%2FWoltLab%2FWCF.git Fix the style preview images The update 5.3.1 -> 5.3.2 detached all the style preview images in the database, while leaving the actual image files in the file system. This new update script *should* fix this situation again, by scanning the asset folder and reattaching the newest image. --- diff --git a/com.woltlab.wcf/package.xml b/com.woltlab.wcf/package.xml index c01670c335..5a71c03d0a 100644 --- a/com.woltlab.wcf/package.xml +++ b/com.woltlab.wcf/package.xml @@ -106,21 +106,5 @@ acp/update_com.woltlab.wcf_5.3_packageServer.php - - - - - acptemplates_update.tar - files_update.tar - templates_update.tar - - - - - - acp/update_com.woltlab.wcf_5.3.2_style.php - + 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 deleted file mode 100644 index 7fa8fa9224..0000000000 --- a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.2_style.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @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' => '', - ]); - } -} diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.3_style.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.3_style.php new file mode 100644 index 0000000000..83213d63ce --- /dev/null +++ b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3.3_style.php @@ -0,0 +1,88 @@ + + * @package WoltLabSuite\Core + */ + +$styleList = new StyleList(); +$styleList->readObjects(); + +foreach ($styleList as $style) { + $styleEditor = new StyleEditor($style); + + // Fix the style preview. + if (!$style->image) { + $basename = 'stylePreview'; + + // Check all possible extensions for preview images on the file system. + $files = []; + foreach ([ + 'png', + 'gif', + 'jpg', + 'jpeg', + 'svg', + ] as $extension) { + $fileName = $style->getAssetPath().$basename.'.'.$extension; + if (is_readable($fileName)) { + $files[$extension] = filemtime($fileName); + } + } + + // Sort by modification time in descending order. + arsort($files); + + if (!empty($files)) { + // This loop will pick the newest file first. + foreach ($files as $extension => $unused) { + $newName = $basename.'.'.$extension; + + $styleEditor->update([ + 'image' => FileUtil::getRelativePath(WCF_DIR.'images/', $style->getAssetPath()).$newName, + ]); + + // break after handling the newest file, simulating + // array_key_first(). + break; + } + } + } + + if (!$style->image2x) { + $basename = 'stylePreview@2x'; + + $files = []; + foreach ([ + 'png', + 'gif', + 'jpg', + 'jpeg', + 'svg', + ] as $extension) { + $fileName = $style->getAssetPath().$basename.'.'.$extension; + if (is_readable($fileName)) { + $files[$extension] = filemtime($fileName); + } + } + arsort($files); + + if (!empty($files)) { + foreach ($files as $extension => $unused) { + $newName = $basename.'.'.$extension; + + $styleEditor->update([ + 'image2x' => FileUtil::getRelativePath(WCF_DIR.'images/', $style->getAssetPath()).$newName, + ]); + + break; + } + } + } +}