From c732e5d5b863efbddf845eacd74a6e1d70108ac5 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <v.pupillo@gmail.com>
Date: Wed, 13 Mar 2024 15:35:12 +0100
Subject: [PATCH] check if Participant has a property before save it into the
 CPDB.

---
 application/controllers/admin/ParticipantsAction.php | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/application/controllers/admin/ParticipantsAction.php b/application/controllers/admin/ParticipantsAction.php
index 76801e7c1c..254430eb7d 100644
--- a/application/controllers/admin/ParticipantsAction.php
+++ b/application/controllers/admin/ParticipantsAction.php
@@ -947,6 +947,10 @@ class ParticipantsAction extends SurveyCommonAction
                 array_push($allowedfieldnames, strtolower((string) $value));
             }
         }
+
+        // initialize loop variable
+        $firstline = array();
+        $ignoredcolumns = array();
         foreach ($tokenlistarray as $buffer) {
             //Iterate through the CSV file line by line
             $buffer = @mb_convert_encoding((string) $buffer, "UTF-8", $uploadcharset);
@@ -1034,7 +1038,10 @@ class ParticipantsAction extends SurveyCommonAction
                             if (in_array($attribute, ['firstname', 'lastname', 'email'])) {
                                 continue;
                             }
-                            $oParticipant->$attribute = $value;
+                            // check if a property exist before update it
+                            if (property_exists($oParticipant, $attribute)) {
+                                $oParticipant->$attribute = $value;
+                            }
                         }
                         $oParticipant->save();
                         //Although this person already exists, we want to update the mapped attribute values
-- 
2.44.0

