From 68cbcd00df73c27ad70623013b09dfc786b57c2c Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 31 Oct 2023 08:45:57 +0100 Subject: [PATCH] fix(target_actor): actors ID not converted when duplicating a form --- inc/target_actor.class.php | 85 +++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/inc/target_actor.class.php b/inc/target_actor.class.php index 7f3866712..69ad45170 100644 --- a/inc/target_actor.class.php +++ b/inc/target_actor.class.php @@ -172,51 +172,52 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con 'uuid', $input['uuid'] ); - // Convert UUIDs or names into IDs - switch ($input['actor_type']) { - case self::ACTOR_TYPE_QUESTION_PERSON : - case self::ACTOR_TYPE_QUESTION_GROUP : - case self::ACTOR_TYPE_QUESTION_SUPPLIER : - case self::ACTOR_TYPE_QUESTION_ACTORS : - case self::ACTOR_TYPE_GROUP_FROM_OBJECT : - case self::ACTOR_TYPE_TECH_GROUP_FROM_OBJECT : - /** @var PluginFormcreatorQuestion $question */ - $question = $linker->getObject($input['actor_value'], PluginFormcreatorQuestion::class); - if ($question === false) { - $linker->postpone($input[$idKey], $item->getType(), $input, $containerId); - return false; - } - $input['actor_value'] = $question->getID(); - break; + } - case self::ACTOR_TYPE_PERSON: - case self::ACTOR_TYPE_AUTHORS_SUPERVISOR: - $user = new User; - $users_id = plugin_formcreator_getFromDBByField($user, 'name', $input['actor_value']); - if ($users_id === false) { - throw new ImportFailureException(sprintf(__('Failed to find a user: %1$s'), $input['actor_value'])); - } - $input['actor_value'] = $users_id; - break; + // Convert UUIDs or names into IDs + switch ($input['actor_type']) { + case self::ACTOR_TYPE_QUESTION_PERSON : + case self::ACTOR_TYPE_QUESTION_GROUP : + case self::ACTOR_TYPE_QUESTION_SUPPLIER : + case self::ACTOR_TYPE_QUESTION_ACTORS : + case self::ACTOR_TYPE_GROUP_FROM_OBJECT : + case self::ACTOR_TYPE_TECH_GROUP_FROM_OBJECT : + /** @var PluginFormcreatorQuestion $question */ + $question = $linker->getObject($input['actor_value'], PluginFormcreatorQuestion::class); + if ($question === false) { + $linker->postpone($input[$idKey], $item->getType(), $input, $containerId); + return false; + } + $input['actor_value'] = $question->getID(); + break; - case self::ACTOR_TYPE_GROUP: - $group = new Group; - $groups_id = plugin_formcreator_getFromDBByField($group, 'completename', $input['actor_value']); - if ($groups_id === false) { - throw new ImportFailureException(sprintf(__('Failed to find a group: %1$s'), $input['actor_value'])); - } - $input['actor_value'] = $groups_id; - break; + case self::ACTOR_TYPE_PERSON: + case self::ACTOR_TYPE_AUTHORS_SUPERVISOR: + $user = new User; + $users_id = plugin_formcreator_getFromDBByField($user, 'name', $input['actor_value']); + if ($users_id === false) { + throw new ImportFailureException(sprintf(__('Failed to find a user: %1$s'), $input['actor_value'])); + } + $input['actor_value'] = $users_id; + break; - case self::ACTOR_TYPE_SUPPLIER: - $supplier = new Supplier; - $suppliers_id = plugin_formcreator_getFromDBByField($supplier, 'name', $input['actor_value']); - if ($suppliers_id === false) { - throw new ImportFailureException(sprintf(__('Failed to find a supplier: %1$s'), $input['actor_value'])); - } - $input['actor_value'] = $suppliers_id; - break; - } + case self::ACTOR_TYPE_GROUP: + $group = new Group; + $groups_id = plugin_formcreator_getFromDBByField($group, 'completename', $input['actor_value']); + if ($groups_id === false) { + throw new ImportFailureException(sprintf(__('Failed to find a group: %1$s'), $input['actor_value'])); + } + $input['actor_value'] = $groups_id; + break; + + case self::ACTOR_TYPE_SUPPLIER: + $supplier = new Supplier; + $suppliers_id = plugin_formcreator_getFromDBByField($supplier, 'name', $input['actor_value']); + if ($suppliers_id === false) { + throw new ImportFailureException(sprintf(__('Failed to find a supplier: %1$s'), $input['actor_value'])); + } + $input['actor_value'] = $suppliers_id; + break; } $originalId = $input[$idKey];