From 8c9570311cb8eecc6a8a7570c680f652bfc124c6 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 4 Jun 2021 16:17:45 +0200 Subject: [PATCH] Ensure that either old or new language XML structure is used --- .../data/language/LanguageEditor.class.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php index b781500eee..5bba2348af 100644 --- a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php +++ b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php @@ -302,6 +302,27 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje $statement->execute($conditions->getParameters()); } + /** + * Checks the structure of the XML file to ensure that either the old, deprecated structure + * with direct `category` children is used or the new structure with `import` and `delete` + * children. + * + * @throws \InvalidArgumentException if old and new structure is mixed + * @since 5.5 + */ + protected function validateXMLStructure(XML $xml): void + { + $xpath = $xml->xpath(); + + $hasImport = $xpath->query('/ns:language/ns:import')->length !== 0; + $hasDelete = $xpath->query('/ns:language/ns:delete')->length !== 0; + $hasDirectCategories = $xpath->query('/ns:language/ns:category')->length !== 0; + + if (($hasImport || $hasDelete) && $hasDirectCategories) { + throw new \InvalidArgumentException("'category' elements cannot be used next to 'import' and 'delete' elements."); + } + } + /** * Imports language items from an XML file into this language. * Updates the relevant language files automatically. @@ -314,6 +335,8 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje */ public function updateFromXML(XML $xml, $packageID, $updateFiles = true, $updateExistingItems = true) { + $this->validateXMLStructure($xml); + $this->deleteFromXML($xml, $packageID); $xpath = $xml->xpath(); -- 2.20.1