Skip to content

Commit

Permalink
fix(item_targetticket): uuid to ID conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Aug 29, 2022
1 parent 87a7405 commit e9f326c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
8 changes: 0 additions & 8 deletions inc/form_validator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
30 changes: 17 additions & 13 deletions inc/item_targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion inc/linker.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down

0 comments on commit e9f326c

Please sign in to comment.