Skip to content

Commit

Permalink
fix(targetticket,targetchange,targetproblem): not imported template
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Feb 5, 2024
1 parent 08d3871 commit 905d6e6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,14 @@ public function prepareInputForClone($input) {
unset($input['uuid']);
return $input;
}

protected static function getTemplateByName(string $name) {
$targetTemplateType = (new static())->getTemplateItemtypeName();
$targetTemplate = new $targetTemplateType();
$targetTemplate->getFromDBByCrit([
'name' => $name,
]);

return $targetTemplate;
}
}
12 changes: 12 additions & 0 deletions inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,18 @@ public static function import(PluginFormcreatorLinker $linker, array $input = []
$input[$fieldSetting['field']] = $question->getID();
}

// Find template by name
$input['changetemplates_id'] = 0;
if ($input['_changetemplate'] !== '') {

$targetTemplate = self::getTemplateByName($input['_changetemplate']);
if ($targetTemplate->isNewItem()) {
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('Failed to add or update the %1$s %2$s: It uses a non existent template ', 'formceator'), $typeName, $input['name']));
}
$input['changetemplates_id'] = $targetTemplate->getID();
}

// Add or update
$originalId = $input[$idKey];
$item->skipChecks = true;
Expand Down
12 changes: 12 additions & 0 deletions inc/targetproblem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,18 @@ public static function import(PluginFormcreatorLinker $linker, array $input = []
$input[$fieldSetting['field']] = $question->getID();
}

// Find template by name
$input['problemtemplates_id'] = 0;
if ($input['_problemtemplate'] !== '') {

$targetTemplate = self::getTemplateByName($input['_problemtemplate']);
if ($targetTemplate->isNewItem()) {
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('Failed to add or update the %1$s %2$s: It uses a non existent template ', 'formceator'), $typeName, $input['name']));
}
}
$input['problemtemplates_id'] = $targetTemplate->getID();

// Add or update
$originalId = $input[$idKey];
$item->skipChecks = true;
Expand Down
11 changes: 11 additions & 0 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,17 @@ public static function import(PluginFormcreatorLinker $linker, array $input = []
$input[$fieldSetting['field']] = $question->getID();
}

// Find template by name
$input['tickettemplates_id'] = 0;
if ($input['_tickettemplate'] !== '') {
$targetTemplate = self::getTemplateByName($input['_tickettemplate']);
if ($targetTemplate->isNewItem()) {
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('Failed to add or update the %1$s %2$s: It uses a non existent template ', 'formceator'), $typeName, $input['name']));
}
$input['tickettemplates_id'] = $targetTemplate->getID();
}

// Add or update
$originalId = $input[$idKey];
$item->skipChecks = true;
Expand Down

0 comments on commit 905d6e6

Please sign in to comment.