Skip to content

Commit

Permalink
fix(form): show error if failure in import of a sub item
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jan 9, 2020
1 parent 812c76d commit 8dfab24
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion inc/condition.class.php
Expand Up @@ -136,7 +136,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the question to the linker
Expand Down
10 changes: 8 additions & 2 deletions inc/form.class.php
Expand Up @@ -1866,22 +1866,27 @@ public function importJson($params = []) {
continue;
}

$success = true;
foreach ($forms_toimport['forms'] as $form) {
set_time_limit(30);
$linker = new PluginFormcreatorLinker();
try {
self::import($linker, $form);
} catch (ImportFailureException $e) {
// Import failed, give up
$sucess = false;
Session::addMessageAfterRedirect($e->getMessage(), false, ERROR);
continue;
}
if (!$linker->linkPostponed()) {
Session::addMessageAfterRedirect(sprintf(__("Failed to import %s", "formcreator"),
$$form['name']));
}
}
Session::addMessageAfterRedirect(sprintf(__("Forms successfully imported from %s", "formcreator"),
if ($sucess) {
Session::addMessageAfterRedirect(sprintf(__("Forms successfully imported from %s", "formcreator"),
$filename));
}
}
}

Expand Down Expand Up @@ -1969,7 +1974,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the form to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/form_profile.class.php
Expand Up @@ -203,7 +203,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the form_profile to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/form_validator.class.php
Expand Up @@ -105,7 +105,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $for
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException();
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the item to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/question.class.php
Expand Up @@ -971,7 +971,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the question to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/questiondependency.class.php
Expand Up @@ -186,7 +186,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the parameter to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/questionrange.class.php
Expand Up @@ -170,7 +170,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the question to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/questionregex.class.php
Expand Up @@ -165,7 +165,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the question to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/section.class.php
Expand Up @@ -253,7 +253,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the section to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/target_actor.class.php
Expand Up @@ -156,7 +156,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the question to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/targetchange.class.php
Expand Up @@ -208,7 +208,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the target to the linker
Expand Down
3 changes: 2 additions & 1 deletion inc/targetticket.class.php
Expand Up @@ -931,7 +931,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
$itemId = $item->add($input);
}
if ($itemId === false) {
throw new ImportFailureException('failed to add or update the item');
$typeName = strtolower(self::getTypeName());
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
}

// add the target to the linker
Expand Down

0 comments on commit 8dfab24

Please sign in to comment.