Skip to content

Commit

Permalink
fix(target_actor): actors ID not converted when duplicating a form
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Oct 31, 2023
1 parent 4da93e3 commit c5167c1
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions inc/target_actor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit c5167c1

Please sign in to comment.