From e9f326c080887e9add1667f2714c3aa82d9ce8ad Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Mon, 29 Aug 2022 11:00:36 +0200 Subject: [PATCH] fix(item_targetticket): uuid to ID conversion --- inc/form_validator.class.php | 8 -------- inc/item_targetticket.class.php | 30 +++++++++++++++++------------- inc/linker.class.php | 4 +++- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/inc/form_validator.class.php b/inc/form_validator.class.php index 23e6a2123..b4d3bc582 100644 --- a/inc/form_validator.class.php +++ b/inc/form_validator.class.php @@ -104,14 +104,6 @@ public function prepareInputForAdd($input) { return $input; } - public function prepareInputForUpdate($input) { - $level = $input['level'] ?? $this->fields['level']; - - if ($level < 1) { - return false; - } - } - public function showForForm(PluginFormcreatorForm $item, $options = []) { global $DB, $CFG_GLPI; diff --git a/inc/item_targetticket.class.php b/inc/item_targetticket.class.php index 8998bb5cb..fa29f4ac6 100644 --- a/inc/item_targetticket.class.php +++ b/inc/item_targetticket.class.php @@ -96,7 +96,7 @@ public function export(bool $remove_uuid = false) : array { return $item_targetTicket; } - public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0, $dryRun = false) { + public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0) { if (!isset($input['uuid']) && !isset($input['id'])) { throw new ImportFailureException(sprintf('UUID or ID is mandatory for %1$s', static::getTypeName(1))); } @@ -119,19 +119,23 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con } // set ID for linked objects - if (!$dryRun) { - $linkedItemtype = $input['itemtype']; - $linkedItemId = $input['items_id']; - $linkedItem = $linker->findObject($linkedItemtype, $linkedItemId, $idKey); - if ($linkedItem->isNewItem()) { - if (strpos($linkedItemtype, 'PluginFormcreator') === 0) { - // the linnked object belongs to the plugin, maybe the item will be imported later - $linker->postpone($input[$idKey], $item->getType(), $input, $containerId); - return false; - } - // linked item is not an object of Formcreator, it will not be imported - throw new ImportFailureException('Failed to find a linked object to a target ticket'); + $linkedItemtype = $input['itemtype']; + $linkedItemId = $input['items_id']; + $linkedItem = $linker->findObject($linkedItemtype, $linkedItemId, $idKey); + if ($linkedItem->isNewItem()) { + if (strpos($linkedItemtype, 'PluginFormcreator') === 0) { + // the linked object belongs to the plugin, maybe the item will be imported later + $linker->postpone($input[$idKey], $item->getType(), $input, $containerId); + return false; } + // linked item is not an object of Formcreator, it will not be imported + throw new ImportFailureException('Failed to find a linked object to a target ticket'); + } + + // Linked object found + if (strpos($linkedItemtype, 'PluginFormcreator') === 0) { + // replace UUID with ID of the found object + $input['items_id'] = $linkedItem->getID(); } // Add or update diff --git a/inc/linker.class.php b/inc/linker.class.php index 331e34818..3e5b02e77 100644 --- a/inc/linker.class.php +++ b/inc/linker.class.php @@ -95,7 +95,9 @@ public function addObject($originalId, PluginFormcreatorExportableInterface $obj $this->imported[$object->getType()] = []; } if (isset($this->imported[$object->getType()][$originalId])) { - throw new ImportFailureException(sprintf('Attempt to create twice the item "%1$s" with original ID "%2$s"', $object->getType(), $originalId)); + // throw new ImportFailureException(sprintf('Attempt to create twice the item "%1$s" with original ID "%2$s"', $object->getType(), $originalId)); + // Object already added + return; } $this->imported[$object->getType()][$originalId] = $object; $this->progress++;