Regenerate Favicon images only when the template changes
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 12 Jul 2021 12:55:31 +0000 (14:55 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 12 Jul 2021 12:56:12 +0000 (14:56 +0200)
wcfsetup/install/files/lib/data/style/StyleAction.class.php

index b93e81578c88ee767e2c7fbc4f8574f964321ff7..acf6c7b4ca0d2334ddf875943ec727bad13530c8 100644 (file)
@@ -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);