From: Marcel Werk Date: Fri, 23 Sep 2016 13:47:56 +0000 (+0200) Subject: Duplicate cms content when new language is added X-Git-Tag: 3.0.0_Beta_1~18 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cf2d32a0c6e3dc6706008bec8a8ca1d966b8e5c7;p=GitHub%2FWoltLab%2FWCF.git Duplicate cms content when new language is added --- diff --git a/wcfsetup/install/files/lib/acp/form/LanguageAddForm.class.php b/wcfsetup/install/files/lib/acp/form/LanguageAddForm.class.php index 4551d97775..d22b4c0140 100644 --- a/wcfsetup/install/files/lib/acp/form/LanguageAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LanguageAddForm.class.php @@ -145,6 +145,10 @@ class LanguageAddForm extends AbstractForm { $languageEditor = new LanguageEditor($this->sourceLanguage); $languageEditor->copy($this->language); + // copy content + LanguageEditor::copyLanguageContent($this->sourceLanguage->languageID, $this->language->languageID); + + // reset caches LanguageFactory::getInstance()->clearCache(); LanguageFactory::getInstance()->deleteLanguageCache(); diff --git a/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php b/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php index 67a7a30659..95e1cbe04a 100644 --- a/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php @@ -59,6 +59,15 @@ class LanguageImportForm extends AbstractForm { */ public $sourceLanguageID = 0; + /** + * @inheritDoc + */ + public function readParameters() { + parent::readParameters(); + + $this->languages = LanguageFactory::getInstance()->getLanguages(); + } + /** * @inheritDoc */ @@ -100,6 +109,11 @@ class LanguageImportForm extends AbstractForm { // import xml document $this->language = LanguageEditor::importFromXML($xml, -1, $this->sourceLanguage); + + // copy content + if (!isset($this->languages[$this->language->languageID])) { + LanguageEditor::copyLanguageContent($this->sourceLanguage->languageID, $this->language->languageID); + } } catch (SystemException $e) { throw new UserInputException('languageUpload', $e->getMessage()); @@ -120,15 +134,6 @@ class LanguageImportForm extends AbstractForm { WCF::getTPL()->assign('success', true); } - /** - * @inheritDoc - */ - public function readData() { - parent::readData(); - - $this->languages = LanguageFactory::getInstance()->getLanguages(); - } - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php index 1f8398872f..d1568c3f94 100644 --- a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php +++ b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php @@ -543,4 +543,48 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje public static function resetCache() { LanguageFactory::getInstance()->clearCache(); } + + /** + * Copies all cms contents (article, box, media, page) from given source language to language specified as $destinationLanguageID. + * + * @param integer $sourceLanguageID + * @param integer $destinationLanguageID + */ + public static function copyLanguageContent($sourceLanguageID, $destinationLanguageID) { + // article content + $sql = "INSERT INTO wcf".WCF_N."_article_content + (articleID, languageID, title, teaser, content, imageID, hasEmbeddedObjects) + SELECT articleID, ?, title, teaser, content, imageID, hasEmbeddedObjects + FROM wcf".WCF_N."_article_content + WHERE languageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$destinationLanguageID, $sourceLanguageID]); + + // box content + $sql = "INSERT INTO wcf".WCF_N."_box_content + (boxID, languageID, title, content, imageID, hasEmbeddedObjects) + SELECT boxID, ?, title, content, imageID, hasEmbeddedObjects + FROM wcf".WCF_N."_box_content + WHERE languageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$destinationLanguageID, $sourceLanguageID]); + + // media content + $sql = "INSERT INTO wcf".WCF_N."_media_content + (mediaID, languageID, title, caption, altText) + SELECT mediaID, ?, title, caption, altText + FROM wcf".WCF_N."_media_content + WHERE languageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$destinationLanguageID, $sourceLanguageID]); + + // page content + $sql = "INSERT INTO wcf".WCF_N."_page_content + (pageID, languageID, title, content, metaDescription, metaKeywords, customURL, hasEmbeddedObjects) + SELECT pageID, ?, title, content, metaDescription, metaKeywords, CASE WHEN customURL <> '' THEN CONCAT(customURL, '_', ?) ELSE '' END, hasEmbeddedObjects + FROM wcf".WCF_N."_page_content + WHERE languageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$destinationLanguageID, $destinationLanguageID, $sourceLanguageID]); + } }