Remove old pageLogo(|Mobile) file when logo is deleted or updated
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 3 Aug 2020 10:33:58 +0000 (12:33 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 3 Aug 2020 10:33:58 +0000 (12:33 +0200)
wcfsetup/install/files/lib/data/style/StyleAction.class.php

index a8568c4f5ecfc4e7d40e3046e391e8b09e251c20..a78e4e2cee78372761e722d3f0c2171c2951a75d 100644 (file)
@@ -172,11 +172,18 @@ class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction
                        return;
                }
                
+               $style->loadVariables();
                foreach (['pageLogo', 'pageLogoMobile'] as $type) {
                        if (array_key_exists($type, $this->parameters['uploads'])) {
                                /** @var \wcf\system\file\upload\UploadFile $file */
                                $file = $this->parameters['uploads'][$type];
                                
+                               if ($style->getVariable($type) && file_exists($style->getAssetPath().basename($style->getVariable($type)))) {
+                                       if (!$file || $style->getAssetPath().basename($style->getVariable($type)) !== $file->getLocation()) {
+                                               unlink($style->getAssetPath().basename($style->getVariable($type)));
+                                       }
+                               }
+                               
                                if ($file !== null) {
                                        $fileLocation = $file->getLocation();
                                        $extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);