Duplicate cms content when new language is added
authorMarcel Werk <burntime@woltlab.com>
Fri, 23 Sep 2016 13:47:56 +0000 (15:47 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 23 Sep 2016 13:48:02 +0000 (15:48 +0200)
wcfsetup/install/files/lib/acp/form/LanguageAddForm.class.php
wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php
wcfsetup/install/files/lib/data/language/LanguageEditor.class.php

index 4551d97775d26ba7cad7c7101437b3dbe2a01d8e..d22b4c014037c43e8eb8a71a1f9618b791f354da 100644 (file)
@@ -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();
                
index 67a7a30659a0ccf02dbfb0c694889905c2340033..95e1cbe04a46e7ecd8735e6f9fed5aeeb0977986 100644 (file)
@@ -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
         */
index 1f8398872fa8025c6548b75fd2932d4ca8e13001..d1568c3f9466cce5f060a0db455658acf6b7d16f 100644 (file)
@@ -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]);
+       }
 }