From: Alexander Ebert Date: Thu, 16 Mar 2017 12:05:18 +0000 (+0100) Subject: Improved handling of changed phrases X-Git-Tag: 3.1.0_Alpha_1~568 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=605e8e9a719ecde968f7cd5f32397db436f790fa;p=GitHub%2FWoltLab%2FWCF.git Improved handling of changed phrases See #2221 --- diff --git a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php index 95cae4da48..ff77322876 100644 --- a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php +++ b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php @@ -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)"; } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 59ff52b55b..2b5ed05647 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -660,6 +660,8 @@ + + languageCustomItemDisableTime|date}.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 0e81efa5f2..4cce6256bb 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -656,6 +656,8 @@ Examples for medium ID detection: + + languageCustomItemDisableTime|date}.]]>