Fixed copying style not copying image path
authorAlexander Ebert <ebert@woltlab.com>
Sun, 26 Apr 2015 18:27:19 +0000 (20:27 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 26 Apr 2015 18:27:19 +0000 (20:27 +0200)
wcfsetup/install/files/lib/data/style/StyleAction.class.php

index 8e120a3307b2dd853d958dee4958da412a4fc32a..f16eb2b68c29eb6fd13ab820135b6c78fa4c29d7 100644 (file)
@@ -511,6 +511,47 @@ class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction
                        }
                }
                
+               // copy images
+               if ($this->styleEditor->imagePath && is_dir(WCF_DIR . $this->styleEditor->imagePath)) {
+                       $path = FileUtil::removeTrailingSlash($this->styleEditor->imagePath);
+                       $newPath = '';
+                       $i = 2;
+                       while (true) {
+                               $newPath = "{$path}-{$i}/";
+                               if (!file_exists(WCF_DIR . $newPath)) {
+                                       break;
+                               }
+                               
+                               $i++;
+                       }
+                       
+                       if (!FileUtil::makePath(WCF_DIR . $newPath)) {
+                               $newPath = '';
+                       }
+                       
+                       if ($newPath) {
+                               $src = FileUtil::addTrailingSlash(WCF_DIR . $this->styleEditor->imagePath);
+                               $dst = WCF_DIR . $newPath;
+                               
+                               $dir = opendir($src);
+                               while (($file = readdir($dir)) !== false) {
+                                       if ($file != '.' && $file != '..' && !is_dir($file)) {
+                                               @copy($src . $file, $dst . $file);
+                                       }
+                               }
+                               closedir($dir);
+                       }
+                       
+                       $sql = "UPDATE  wcf".WCF_N."_style
+                               SET     imagePath = ?
+                               WHERE   styleID = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array(
+                               $newPath,
+                               $newStyle->styleID
+                       ));
+               }
+               
                StyleCacheBuilder::getInstance()->reset();
                
                return array(