Delete also old langauge items in save function
authorOlaf Braun <info@braun-development.de>
Fri, 10 Nov 2023 08:24:07 +0000 (09:24 +0100)
committerOlaf Braun <info@braun-development.de>
Fri, 10 Nov 2023 08:24:07 +0000 (09:24 +0100)
wcfsetup/install/files/lib/data/TI18nDatabaseObjectAction.class.php

index 5e8ddbddcd4b15ec544d9a1ebdc13e3ef2fb098c..15e295f9e21202cb7c0215edcc1aed9db26f22cd 100644 (file)
@@ -32,6 +32,14 @@ trait TI18nDatabaseObjectAction
                 }
             }
         }
+        $this->deleteI18Items($langaugeItems);
+    }
+
+    /**
+     * Deletes language items and clears the language cache.
+     */
+    private function deleteI18Items(array $langaugeItems): void
+    {
         if ($langaugeItems !== []) {
             //find language category id
             $sql = "SELECT  languageCategoryID
@@ -87,12 +95,11 @@ trait TI18nDatabaseObjectAction
      */
     protected function saveI18nValue(DatabaseObject $object): void
     {
-        $updateData = [];
+        $updateData = $deleteData = [];
 
         foreach ($this->getI18nSaveTypes() as $name => $regex) {
+            $languageName = \str_replace('\d+', $object->getObjectID(), $regex);
             if (isset($this->parameters[$name . '_i18n'])) {
-                $languageName = \str_replace('\d+', $object->getObjectID(), $regex);
-
                 I18nHandler::getInstance()->save(
                     $this->parameters[$name . '_i18n'],
                     $languageName,
@@ -101,8 +108,12 @@ trait TI18nDatabaseObjectAction
                 );
 
                 $updateData[$name] = $languageName;
+            } else {
+                $deleteData[] = $languageName;
             }
         }
+        $this->deleteI18Items($deleteData);
+
         if (!empty($updateData)) {
             $editor = new $this->className($object);
             $editor->update($updateData);