diff --git a/inc/targetchange.class.php b/inc/targetchange.class.php index 1f8facab4..0934616ec 100644 --- a/inc/targetchange.class.php +++ b/inc/targetchange.class.php @@ -288,6 +288,18 @@ public static function import(PluginFormcreatorLinker $linker, array $input = [] $input[$fieldSetting['field']] = $question->getID(); } + // Find template by name + $targetTemplateType = (new self())->getTemplateItemtypeName(); + $targetTemplate = new $targetTemplateType(); + $targetTemplate->getFromDBByCrit([ + 'name' => $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; diff --git a/inc/targetproblem.class.php b/inc/targetproblem.class.php index 3e911a9e3..3e5fd2dc7 100644 --- a/inc/targetproblem.class.php +++ b/inc/targetproblem.class.php @@ -525,6 +525,18 @@ public static function import(PluginFormcreatorLinker $linker, array $input = [] $input[$fieldSetting['field']] = $question->getID(); } + // Find template by name + $targetTemplateType = (new self())->getTemplateItemtypeName(); + $targetTemplate = new $targetTemplateType(); + $targetTemplate->getFromDBByCrit([ + 'name' => $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; diff --git a/inc/targetticket.class.php b/inc/targetticket.class.php index 2d0f43e91..8e3dd7ed7 100644 --- a/inc/targetticket.class.php +++ b/inc/targetticket.class.php @@ -1404,6 +1404,18 @@ public static function import(PluginFormcreatorLinker $linker, array $input = [] $input[$fieldSetting['field']] = $question->getID(); } + // Find template by name + $targetTemplateType = (new self())->getTemplateItemtypeName(); + $targetTemplate = new $targetTemplateType(); + $targetTemplate->getFromDBByCrit([ + 'name' => $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;