From 765eeec89075b81617d4cab57f3ce2b425b872ab Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Tue, 6 Sep 2022 10:59:01 +0100
Subject: [PATCH] :ambulance: Fix(ForeignKey) - Arrays are processed properly

Arrays are now processed properly by foreign key modification.
---
 include/simpleplugin/class_simplePlugin.inc | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc
index d515d1835..e5f3a64d4 100644
--- a/include/simpleplugin/class_simplePlugin.inc
+++ b/include/simpleplugin/class_simplePlugin.inc
@@ -2048,6 +2048,17 @@ class simplePlugin implements SimpleTab
     if (!isset($source['MODE'])) {
       $source['MODE'] = 'move';
     }
+
+    // In case of SetAttribute, value is an array needing to be changed to string.
+    if (is_array($oldvalue) && isset($oldvalue[0])) {
+
+      $oldvalue = $oldvalue[0];
+    }
+    if (is_array($newvalue) && isset($newvalue[0])) {
+
+      $newvalue = $newvalue[0];
+    }
+
     $this->attributesAccess[$field]->foreignKeyUpdate($oldvalue, $newvalue, $source);
   }
 
@@ -2064,7 +2075,7 @@ class simplePlugin implements SimpleTab
   function foreignKeyCheck (string $field, $value, array $source)
   {
     // In case of SetAttribute, value is an array needing to be changed to string.
-    if (is_array($value)) {
+    if (is_array($value) && isset($value[0])) {
 
       $value = $value[0];
     }
-- 
GitLab