From 3d61bd01b1e738d903cf7007b8d585a221e1a42d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 12 Jul 2021 14:55:31 +0200 Subject: [PATCH] Regenerate Favicon images only when the template changes --- .../lib/data/style/StyleAction.class.php | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/wcfsetup/install/files/lib/data/style/StyleAction.class.php b/wcfsetup/install/files/lib/data/style/StyleAction.class.php index b93e81578c..acf6c7b4ca 100644 --- a/wcfsetup/install/files/lib/data/style/StyleAction.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleAction.class.php @@ -331,38 +331,41 @@ class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction $file = $this->parameters['uploads']['favicon']; if ($file !== null) { - $fileLocation = $file->getLocation(); - if (($imageData = \getimagesize($fileLocation)) === false) { - throw new \InvalidArgumentException('The given favicon is not an image'); - } - $extension = ImageUtil::getExtensionByMimeType($imageData['mime']); - $newName = "favicon-template." . $extension; - $newLocation = $style->getAssetPath() . $newName; - \rename($fileLocation, $newLocation); + if (!$file->isProcessed()) { + $fileLocation = $file->getLocation(); + if (($imageData = \getimagesize($fileLocation)) === false) { + throw new \InvalidArgumentException('The given favicon is not an image'); + } + $extension = ImageUtil::getExtensionByMimeType($imageData['mime']); + $newName = "favicon-template." . $extension; + $newLocation = $style->getAssetPath() . $newName; + \rename($fileLocation, $newLocation); - // Create browser specific files. - $adapter = ImageHandler::getInstance()->getAdapter(); - $adapter->loadFile($newLocation); - foreach ($images as $filename => $length) { - $thumbnail = $adapter->createThumbnail($length, $length); - $adapter->writeImage($thumbnail, $style->getAssetPath() . $filename); - // Clear thumbnail as soon as possible to free up the memory. - $thumbnail = null; - } + $file->setProcessed($newLocation); - // Create ICO file. - require(WCF_DIR . 'lib/system/api/chrisjean/php-ico/class-php-ico.php'); - (new \PHP_ICO($newLocation, [ - [16, 16], - [32, 32], - ]))->save_ico($style->getAssetPath() . "favicon.ico"); + // Create browser specific files. + $adapter = ImageHandler::getInstance()->getAdapter(); + $adapter->loadFile($file->getLocation()); + foreach ($images as $filename => $length) { + $thumbnail = $adapter->createThumbnail($length, $length); + $adapter->writeImage($thumbnail, $style->getAssetPath() . $filename); + // Clear thumbnail as soon as possible to free up the memory. + $thumbnail = null; + } - (new StyleEditor($style))->update([ - 'hasFavicon' => 1, - ]); + // Create ICO file. + require(WCF_DIR . 'lib/system/api/chrisjean/php-ico/class-php-ico.php'); + (new \PHP_ICO($file->getLocation(), [ + [16, 16], + [32, 32], + ]))->save_ico($style->getAssetPath() . "favicon.ico"); - $file->setProcessed($newLocation); - $hasFavicon = true; + (new StyleEditor($style))->update([ + 'hasFavicon' => 1, + ]); + + $hasFavicon = true; + } } else { foreach ($images as $filename => $length) { \unlink($style->getAssetPath() . $filename); -- 2.20.1