From c063caad1a65326d64cfa2aa4a101d6da71f3e3b Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+github@gmail.com>
Date: Tue, 11 Jan 2022 12:45:30 +0100
Subject: [PATCH] throw exceptions when i18nstring is used with a composite
 primary key, fixes #535

---
 lib/classes/I18NString.php       | 7 ++++++-
 lib/models/SimpleORMap.class.php | 4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/classes/I18NString.php b/lib/classes/I18NString.php
index 4dc61560454..da2b5007070 100644
--- a/lib/classes/I18NString.php
+++ b/lib/classes/I18NString.php
@@ -52,7 +52,8 @@ class I18NString
     {
         $this->base = $base;
         $this->lang = $lang;
-        $this->metadata = $metadata;
+
+        $this->setMetadata($metadata);
     }
 
     /**
@@ -151,6 +152,10 @@ class I18NString
      */
     public function setMetadata($metadata)
     {
+        if (isset($metadata['object_id']) && (is_array($metadata['object_id']) || is_object($metadata['object_id']))) {
+            throw new Exception('Can not use array or object as object id');
+        }
+
         $this->metadata = $metadata;
     }
 
diff --git a/lib/models/SimpleORMap.class.php b/lib/models/SimpleORMap.class.php
index de444aa7c54..f1708272294 100644
--- a/lib/models/SimpleORMap.class.php
+++ b/lib/models/SimpleORMap.class.php
@@ -296,6 +296,10 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
 
         if (I18N::isEnabled()) {
             if (isset($config['i18n_fields']) && count($config['i18n_fields']) > 0) {
+                if (count($config['pk']) > 1) {
+                    throw new Exception('Can not define i18n fields on a composite primary key');
+                }
+
                 $config['registered_callbacks']['before_store'][] = 'cbI18N';
                 $config['registered_callbacks']['after_delete'][] = 'cbI18N';
             }
-- 
GitLab