From: Matthias Schmidt Date: Tue, 7 May 2013 16:34:28 +0000 (+0200) Subject: Fixes issues during style import X-Git-Tag: 2.0.0_Beta_1~233 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f4ca14c376ff3e36c693da60e60537209ecb250f;p=GitHub%2FWoltLab%2FWCF.git Fixes issues during style import Closes #1168 Closes #1171 --- diff --git a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php index 4caa4b9796..cd97bfd235 100644 --- a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php @@ -302,7 +302,6 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject ); // create template group - $templateGroupID = 0; if (!empty($data['templates'])) { $templateGroupName = $originalTemplateGroupName = $data['name']; $templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName); @@ -329,7 +328,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $sql = "SELECT COUNT(*) AS count FROM wcf".WCF_N."_template_group WHERE templateGroupFolderName = ? - AND parentTemplatePackID = ?"; + AND parentTemplateGroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( FileUtil::addTrailingSlash($templateGroupFolderName), @@ -348,21 +347,6 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $styleData['templateGroupID'] = $templateGroup->templateGroupID; } - // import preview image - if (!empty($data['image'])) { - $fileExtension = StringUtil::substring($data['image'], StringUtil::lastIndexOf($data['image'], '.')); - $index = $tar->getIndexByFilename($data['image']); - if ($index !== false) { - $filename = WCF_DIR.'images/stylePreview-'.$style->styleID.'.'.$fileExtension; - $tar->extract($index, $filename); - @chmod($filename, 0777); - - if (file_exists($filename)) { - $styleData['image'] = $filename; - } - } - } - // import images if (!empty($data['images']) && $data['imagesPath'] != 'images/') { // create images folder if necessary @@ -443,7 +427,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject TemplateEditor::create(array( 'packageID' => $row['packageID'], 'templateName' => StringUtil::replace('.tpl', '', $template['filename']), - 'templateGroupID' => $templateGroupID + 'templateGroupID' => $styleData['templateGroupID'] )); } } @@ -455,8 +439,6 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject } } - $tar->close(); - // save style if ($style !== null) { $style->update($styleData); @@ -466,9 +448,27 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $style = new StyleEditor(self::create($styleData)); } + // import preview image + if (!empty($data['image'])) { + $fileExtension = StringUtil::substring($data['image'], StringUtil::lastIndexOf($data['image'], '.')); + $index = $tar->getIndexByFilename($data['image']); + if ($index !== false) { + $filename = WCF_DIR.'images/stylePreview-'.$style->styleID.$fileExtension; + $tar->extract($index, $filename); + @chmod($filename, 0777); + + if (file_exists($filename)) { + $style->update(array('image' => 'stylePreview-'.$style->styleID.$fileExtension)); + } + } + } + + $tar->close(); + // handle descriptions if (!empty($data['description'])) { self::saveLocalizedDescriptions($style, $data['description']); + LanguageFactory::getInstance()->deleteLanguageCache(); } if ($data['default']) { @@ -861,7 +861,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject */ public static function scalePreviewImage($filename) { $adapter = ImageHandler::getInstance()->getAdapter(); - $adapter->loadFile($filename); + $adapter->loadFile(WCF_DIR.'images/'.$filename); $thumbnail = $adapter->createThumbnail(Style::PREVIEW_IMAGE_MAX_WIDTH, Style::PREVIEW_IMAGE_MAX_HEIGHT); $adapter->writeImage($thumbnail, $filename); }