Fixed style export, import and update
authorAlexander Ebert <ebert@woltlab.com>
Tue, 17 Jan 2017 13:39:34 +0000 (14:39 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 17 Jan 2017 13:39:40 +0000 (14:39 +0100)
com.woltlab.wcf/defaultStyle.tar
wcfsetup/install/files/lib/acp/form/StyleExportForm.class.php
wcfsetup/install/files/lib/data/style/StyleEditor.class.php

index 3e3e92329a3c629263e7f2ea43729f4d1aa4c584..c30b05767a69a283cbd527f33a3eb3dcaa314069 100644 (file)
Binary files a/com.woltlab.wcf/defaultStyle.tar and b/com.woltlab.wcf/defaultStyle.tar differ
index 12b9eebbe76b0d43a7c99466c7f76f5cea73bb95..914265b962da01b25e1ca0b17c0d085d72938c8a 100644 (file)
@@ -118,7 +118,7 @@ class StyleExportForm extends AbstractForm {
                
                // export style
                $styleEditor = new StyleEditor($this->style);
-               $styleEditor->export($this->exportTemplates, $this->exportImages, $this->style->packageName);
+               $styleEditor->export($this->exportTemplates, $this->exportImages, ($this->exportAsPackage ? $this->style->packageName : ''));
                
                // call saved event
                $this->saved();
index aa6d36d637bd077bf15c6a41791b3e6302a82aae..6cc3ffffbf589cbf2089d6881e0873aff265227e 100644 (file)
@@ -19,6 +19,7 @@ use wcf\system\language\LanguageFactory;
 use wcf\system\package\PackageArchive;
 use wcf\system\style\StyleCompiler;
 use wcf\system\Regex;
+use wcf\system\style\StyleHandler;
 use wcf\system\WCF;
 use wcf\util\DateUtil;
 use wcf\util\FileUtil;
@@ -144,7 +145,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                $data = [
                        'name' => '', 'description' => [], 'version' => '', 'image' => '', 'copyright' => '', 'default' => false,
                        'license' => '', 'authorName' => '', 'authorURL' => '', 'templates' => '', 'images' => '',
-                       'variables' => '', 'date' => '0000-00-00', 'imagesPath' => ''
+                       'variables' => '', 'date' => '0000-00-00', 'imagesPath' => '', 'packageName' => ''
                ];
                
                $categories = $xpath->query('/ns:style/*');
@@ -201,6 +202,10 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                                                                $data['name'] = $element->nodeValue;
                                                        break;
                                                        
+                                                       case 'packageName':
+                                                               $data['packageName'] = $element->nodeValue;
+                                                       break;
+                                                       
                                                        case 'version':
                                                                if (!Package::isValidVersion($element->nodeValue)) {
                                                                        throw new SystemException("style version '".$element->nodeValue."' is invalid");
@@ -313,9 +318,15 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                        'copyright' => $data['copyright'],
                        'license' => $data['license'],
                        'authorName' => $data['authorName'],
-                       'authorURL' => $data['authorURL']
+                       'authorURL' => $data['authorURL'],
+                       'packageName' => $data['packageName']
                ];
                
+               // check if there is an untainted style with the same package name
+               if ($style === null && !empty($styleData['packageName'])) {
+                       $style = StyleHandler::getInstance()->getStyleByName($styleData['packageName'], true);
+               }
+               
                // import images
                if (!empty($data['images']) && $data['imagesPath'] != 'images/') {
                        // create images folder if necessary
@@ -519,6 +530,8 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                        unset($styleData['styleName']);
                        
                        $variables = $style->getVariables();
+                       if (!isset($styleData['variables']['individualScss'])) $styleData['variables']['individualScss'] = '';
+                       if (!isset($styleData['variables']['overrideScss'])) $styleData['variables']['overrideScss'] = '';
                        
                        $individualScss = Style::splitLessVariables($variables['individualScss']);
                        $variables['individualScss'] = Style::joinLessVariables($styleData['variables']['individualScss'], $individualScss['custom']);
@@ -606,6 +619,9 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                        $index = ($index === null ? 2 : ($index + 1));
                }
                while (true);
+               
+               // this should never happen
+               throw new \LogicException();
        }
        
        /**
@@ -642,6 +658,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                // general block
                $xml->startElement('general');
                $xml->writeElement('stylename', $this->styleName);
+               $xml->writeElement('packageName', $this->packageName);
                
                // style description
                foreach ($styleDescriptions as $languageCode => $value) {