From d77cde058e8321a69480c30b822c2c898417d4fd Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 5 Jan 2024 11:07:17 +0100 Subject: [PATCH] fix(target_actor): duplicate failure with gours, supliers or users --- inc/target_actor.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/inc/target_actor.class.php b/inc/target_actor.class.php index 69ad45170..f76501a86 100644 --- a/inc/target_actor.class.php +++ b/inc/target_actor.class.php @@ -194,7 +194,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con case self::ACTOR_TYPE_PERSON: case self::ACTOR_TYPE_AUTHORS_SUPERVISOR: $user = new User; - $users_id = plugin_formcreator_getFromDBByField($user, 'name', $input['actor_value']); + $field = $idKey == 'id' ? 'id' : 'name'; + $users_id = plugin_formcreator_getFromDBByField($user, $field, $input['actor_value']); if ($users_id === false) { throw new ImportFailureException(sprintf(__('Failed to find a user: %1$s'), $input['actor_value'])); } @@ -203,7 +204,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con case self::ACTOR_TYPE_GROUP: $group = new Group; - $groups_id = plugin_formcreator_getFromDBByField($group, 'completename', $input['actor_value']); + $field = $idKey == 'id' ? 'id' : 'completename'; + $groups_id = plugin_formcreator_getFromDBByField($group, $field, $input['actor_value']); if ($groups_id === false) { throw new ImportFailureException(sprintf(__('Failed to find a group: %1$s'), $input['actor_value'])); } @@ -212,7 +214,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con case self::ACTOR_TYPE_SUPPLIER: $supplier = new Supplier; - $suppliers_id = plugin_formcreator_getFromDBByField($supplier, 'name', $input['actor_value']); + $field = $idKey == 'id' ? 'id' : 'name'; + $suppliers_id = plugin_formcreator_getFromDBByField($supplier, $field, $input['actor_value']); if ($suppliers_id === false) { throw new ImportFailureException(sprintf(__('Failed to find a supplier: %1$s'), $input['actor_value'])); }