Improved handling of changed phrases
authorAlexander Ebert <ebert@woltlab.com>
Thu, 16 Mar 2017 12:05:18 +0000 (13:05 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 16 Mar 2017 12:05:18 +0000 (13:05 +0100)
See #2221

wcfsetup/install/files/lib/data/language/LanguageEditor.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 95cae4da483eaa28665ac67e997811f72a835055..ff77322876bd3e22ff7ab1cf773bde49902171e2 100644 (file)
@@ -280,6 +280,7 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje
                
                // loop through categories to import items
                $itemData = $pageContents = $boxContents = [];
+               $languageItemValues = [];
                
                /** @var \DOMElement $category */
                foreach ($categories as $category) {
@@ -317,12 +318,56 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje
                                        $itemData[] = $itemValue;
                                        $itemData[] = $categoryID;
                                        if ($packageID) $itemData[] = ($packageID == -1) ? PACKAGE_ID : $packageID;
+                                       
+                                       if ($updateExistingItems) {
+                                               $languageItemValues[$itemName] = $itemValue;
+                                       }
                                }
                        }
                }
                
                // save items
                if (!empty($itemData)) {
+                       // select phrases that have custom versions that might get disabled during the update
+                       if ($updateExistingItems) {
+                               $conditions = new PreparedStatementConditionBuilder();
+                               $conditions->add("languageItem IN (?)", [array_keys($languageItemValues)]);
+                               if ($packageID > 0) $conditions->add("packageID = ?", [$packageID]);
+                               $conditions->add("languageUseCustomValue = ?", [1]);
+                               $conditions->add("languageItemOriginIsSystem = ?", [1]);
+                               
+                               $sql = "SELECT  languageItemID, languageItem, languageItemValue
+                                       FROM    wcf".WCF_N."_language_item
+                                       ".$conditions;
+                               $statement = WCF::getDB()->prepareStatement($sql);
+                               $statement->execute($conditions->getParameters());
+                               $updateValues = [];
+                               while ($row = $statement->fetchArray()) {
+                                       if ($row['languageItemValue'] != $languageItemValues[$row['languageItem']]) {
+                                               $updateValues[] = $row['languageItemID'];
+                                       }
+                               }
+                               
+                               if (!empty($updateValues)) {
+                                       $sql = "UPDATE  wcf".WCF_N."_language_item
+                                               SET     languageItemOldValue = languageItemValue,
+                                                       languageCustomItemDisableTime = ?,
+                                                       languageUseCustomValue = ?
+                                               WHERE   languageItemID = ?";
+                                       $statement = WCF::getDB()->prepareStatement($sql);
+                                       
+                                       WCF::getDB()->beginTransaction();
+                                       foreach ($updateValues as $languageItemID) {
+                                               $statement->execute([
+                                                       TIME_NOW,
+                                                       0,
+                                                       $languageItemID
+                                               ]);
+                                       }
+                                       WCF::getDB()->commitTransaction();
+                               }
+                       }
+                       
                        // insert/update a maximum of 50 items per run (prevents issues with max_allowed_packet)
                        $step = $packageID ? 5 : 4;
                        WCF::getDB()->beginTransaction();
@@ -338,15 +383,13 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje
                                        if ($packageID > 0) {
                                                // do not update anything if language item is owned by a different package
                                                $sql .= "       ON DUPLICATE KEY
-                                                               UPDATE                  languageUseCustomValue = IF(packageID = ".$packageID.", IF(languageItemValue = VALUES(languageItemValue), languageUseCustomValue, 0), languageUseCustomValue),
-                                                                                       languageItemValue = IF(packageID = ".$packageID.", IF(languageItemOriginIsSystem = 0, languageItemValue, VALUES(languageItemValue)), languageItemValue),
+                                                               UPDATE                  languageItemValue = IF(packageID = ".$packageID.", IF(languageItemOriginIsSystem = 0, languageItemValue, VALUES(languageItemValue)), languageItemValue),
                                                                                        languageCategoryID = IF(packageID = ".$packageID.", VALUES(languageCategoryID), languageCategoryID)";
                                        }
                                        else {
                                                // skip package id check during WCFSetup (packageID = 0) or if using the ACP form (packageID = -1)
                                                $sql .= "       ON DUPLICATE KEY
-                                                               UPDATE                  languageUseCustomValue = IF(languageItemValue = VALUES(languageItemValue), languageUseCustomValue, 0),
-                                                                                       languageItemValue = IF(languageItemOriginIsSystem = 0, languageItemValue, VALUES(languageItemValue)),
+                                                               UPDATE                  languageItemValue = IF(languageItemOriginIsSystem = 0, languageItemValue, VALUES(languageItemValue)),
                                                                                        languageCategoryID = VALUES(languageCategoryID)";
                                        }
                                }
index 59ff52b55be707c8135a6190ec09919e007ef264..2b5ed056470ac8e8d71a5b3b87db1020048de9a5 100644 (file)
                <item name="wcf.acp.language.item.disabledCustomValues"><![CDATA[Deaktivierte veränderte Inhalte finden]]></item>
                <item name="wcf.acp.language.name.description"><![CDATA[Name der Sprache]]></item>
                <item name="wcf.acp.language.add.source.description"><![CDATA[Die ausgewählte Sprache wird als Vorlage benutzt. Alle Sprachvariablen werden in die neue Sprache kopiert.]]></item>
+               <item name="wcf.acp.language.item.oldValue"><![CDATA[Ursprünglicher Inhalt]]></item>
+               <item name="wcf.acp.language.item.oldValue.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} veränderte Fassung basierte auf dem unten stehenden Stand vom {$item->languageCustomItemDisableTime|date}.]]></item>
        </category>
        
        <category name="wcf.acp.masterPassword">
index 0e81efa5f2e1981604f80692ee7be6a4c11689ae..4cce6256bb7f6ae6e89a82d4d04ed2fa1302ee68 100644 (file)
@@ -656,6 +656,8 @@ Examples for medium ID detection:
                <item name="wcf.acp.language.item.disabledCustomValues"><![CDATA[Disabled customized values]]></item>
                <item name="wcf.acp.language.name.description"><![CDATA[Language Name]]></item>
                <item name="wcf.acp.language.add.source.description"><![CDATA[The selected language will be used as origin, all phrases will be copied into the new language.]]></item>
+               <item name="wcf.acp.language.item.oldValue"><![CDATA[Original Content]]></item>
+               <item name="wcf.acp.language.item.oldValue.description"><![CDATA[Your custom value was based on the original content that has changed on {$item->languageCustomItemDisableTime|date}.]]></item>
        </category>
        
        <category name="wcf.acp.masterPassword">