Skip to content

Commit

Permalink
fix(target_actor): duplication exception
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Dec 19, 2019
1 parent 0c93dbd commit 1b0523e
Showing 1 changed file with 40 additions and 41 deletions.
81 changes: 40 additions & 41 deletions inc/target_actor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,47 +102,46 @@ 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 :
$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:
$user = new User;
$users_id = plugin_formcreator_getFromDBByField($user, 'name', $input['actor_value']);
if ($users_id === false) {
throw new ImportFailureException('failed to find a user');
}
$input['actor_value'] = $users_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('failed to find a group');
}
$input['actor_value'] = $groups_id;
break;

// set ID for linked objects
switch ($input['actor_type']) {
case self::ACTOR_TYPE_QUESTION_PERSON :
case self::ACTOR_TYPE_QUESTION_GROUP :
case self::ACTOR_TYPE_QUESTION_SUPPLIER :
$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:
$user = new User;
$users_id = plugin_formcreator_getFromDBByField($user, 'name', $input['_user']);
if ($users_id === false) {
throw new ImportFailureException('failed to find a user');
}
$input['actor_value'] = $users_id;
break;

case self::ACTOR_TYPE_GROUP:
$group = new Group;
$groups_id = plugin_formcreator_getFromDBByField($group, 'completename', $input['_group']);
if ($groups_id === false) {
throw new ImportFailureException('failed to find a group');
}
$input['actor_value'] = $groups_id;
break;

case self::ACTOR_TYPE_SUPPLIER:
$supplier = new Supplier;
$suppliers_id = plugin_formcreator_getFromDBByField($supplier, 'name', $input['_supplier']);
if ($suppliers_id === false) {
throw new ImportFailureException('failed to find a supplier');
}
$input['actor_value'] = $suppliers_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('failed to find a supplier');
}
$input['actor_value'] = $suppliers_id;
break;
}
}

$originalId = $input[$idKey];
Expand Down Expand Up @@ -184,7 +183,7 @@ public function export($remove_uuid = false) {
if ($remove_uuid) {
$idToRemove = 'uuid';
} else {
// Convert IDs into UUIDs
// Convert IDs into UUIDs or names
switch ($target_actor['actor_type']) {
case self::ACTOR_TYPE_QUESTION_PERSON:
case self::ACTOR_TYPE_QUESTION_GROUP:
Expand Down

0 comments on commit 1b0523e

Please sign in to comment.