Prevent languages being overwritten during update
authorAlexander Ebert <ebert@woltlab.com>
Tue, 24 Sep 2013 22:06:04 +0000 (00:06 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 24 Sep 2013 22:06:04 +0000 (00:06 +0200)
wcfsetup/install/files/lib/data/language/LanguageEditor.class.php
wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php

index fec8776bc489d564f335bb86f3a44770a96bab6e..a4e2436ab1847b5a4a93ac4d6e4cbb0b5de44b05 100644 (file)
@@ -164,8 +164,9 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje
         * @param       wcf\util\XML    $xml
         * @param       integer         $packageID
         * @param       boolean         $updateFiles
+        * @param       boolean         $updateExistingItems
         */
-       public function updateFromXML(XML $xml, $packageID, $updateFiles = true) {
+       public function updateFromXML(XML $xml, $packageID, $updateFiles = true, $updateExistingItems = true) {
                $xpath = $xml->xpath();
                $usedCategories = array();
                
@@ -223,20 +224,26 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje
                if (!empty($itemData)) {
                        // insert/update a maximum of 50 items per run (prevents issues with max_allowed_packet)
                        $step = ($packageID) ? 5 : 4;
+                       WCF::getDB()->beginTransaction();
                        for ($i = 0, $length = count($itemData); $i < $length; $i += 50 * $step) {
                                $parameters = array_slice($itemData, $i, 50 * $step);
                                $repeat = count($parameters) / $step;
                                
-                               $sql = "INSERT INTO             wcf".WCF_N."_language_item
+                               $sql = "INSERT".(!$updateExistingItems ? " IGNORE" : "")." INTO         wcf".WCF_N."_language_item
                                                                (languageID, languageItem, languageItemValue, languageCategoryID". ($packageID ? ", packageID" : "") . ")
-                                       VALUES                  ".substr(str_repeat('(?, ?, ?, ?'. ($packageID ? ', ?' : '') .'), ', $repeat), 0, -2)."
-                                       ON DUPLICATE KEY
+                                       VALUES                  ".substr(str_repeat('(?, ?, ?, ?'. ($packageID ? ', ?' : '') .'), ', $repeat), 0, -2);
+                               
+                               if ($updateExistingItems) {
+                                       " ON DUPLICATE KEY
                                        UPDATE                  languageItemValue = IF(languageItemOriginIsSystem = 0, languageItemValue, VALUES(languageItemValue)),
                                                                languageCategoryID = VALUES(languageCategoryID),
                                                                languageUseCustomValue = 0";
+                               }
+                               
                                $statement = WCF::getDB()->prepareStatement($sql);
                                $statement->execute($parameters);
                        }
+                       WCF::getDB()->commitTransaction();
                }
                
                // update the relevant language files
index d0bd7575f1f05961a7b2a04779b0f6d66a9f95ed..c41d70c4ce6c961f379eb7f862924aacf554a68e 100644 (file)
@@ -81,10 +81,14 @@ class LanguagePackageInstallationPlugin extends AbstractXMLPackageInstallationPl
                // install language
                foreach ($installedLanguages as $installedLanguage) {
                        $languageFile = null;
+                       $updateExistingItems = true;
                        if (isset($languageFiles[$installedLanguage['languageCode']])) {
                                $languageFile = $languageFiles[$installedLanguage['languageCode']];
                        }
                        else if ($multipleFiles) {
+                               // do not update existing items, only add new ones
+                               $updateExistingItems = false;
+                               
                                // use default language
                                if (isset($languageFiles[$installedLanguages[0]['languageCode']])) {
                                        $languageFile = $languageFiles[$installedLanguages[0]['languageCode']];
@@ -125,7 +129,7 @@ class LanguagePackageInstallationPlugin extends AbstractXMLPackageInstallationPl
                                        
                                        // import xml
                                        // don't update language files if package is an application
-                                       $languageEditor->updateFromXML($xml, $this->installation->getPackageID(), !$this->installation->getPackage()->isApplication);
+                                       $languageEditor->updateFromXML($xml, $this->installation->getPackageID(), !$this->installation->getPackage()->isApplication, $updateExistingItems);
                                }
                        }
                }