Skip to content

Commit 8dfab24

Browse files
committed
fix(form): show error if failure in import of a sub item
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 812c76d commit 8dfab24

12 files changed

+30
-13
lines changed

inc/condition.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
136136
$itemId = $item->add($input);
137137
}
138138
if ($itemId === false) {
139-
throw new ImportFailureException('failed to add or update the item');
139+
$typeName = strtolower(self::getTypeName());
140+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
140141
}
141142

142143
// add the question to the linker

inc/form.class.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,22 +1866,27 @@ public function importJson($params = []) {
18661866
continue;
18671867
}
18681868

1869+
$success = true;
18691870
foreach ($forms_toimport['forms'] as $form) {
18701871
set_time_limit(30);
18711872
$linker = new PluginFormcreatorLinker();
18721873
try {
18731874
self::import($linker, $form);
18741875
} catch (ImportFailureException $e) {
18751876
// Import failed, give up
1877+
$sucess = false;
1878+
Session::addMessageAfterRedirect($e->getMessage(), false, ERROR);
18761879
continue;
18771880
}
18781881
if (!$linker->linkPostponed()) {
18791882
Session::addMessageAfterRedirect(sprintf(__("Failed to import %s", "formcreator"),
18801883
$$form['name']));
18811884
}
18821885
}
1883-
Session::addMessageAfterRedirect(sprintf(__("Forms successfully imported from %s", "formcreator"),
1886+
if ($sucess) {
1887+
Session::addMessageAfterRedirect(sprintf(__("Forms successfully imported from %s", "formcreator"),
18841888
$filename));
1889+
}
18851890
}
18861891
}
18871892

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

19751981
// add the form to the linker

inc/form_profile.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
203203
$itemId = $item->add($input);
204204
}
205205
if ($itemId === false) {
206-
throw new ImportFailureException('failed to add or update the item');
206+
$typeName = strtolower(self::getTypeName());
207+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
207208
}
208209

209210
// add the form_profile to the linker

inc/form_validator.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $for
105105
$itemId = $item->add($input);
106106
}
107107
if ($itemId === false) {
108-
throw new ImportFailureException();
108+
$typeName = strtolower(self::getTypeName());
109+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
109110
}
110111

111112
// add the item to the linker

inc/question.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
971971
$itemId = $item->add($input);
972972
}
973973
if ($itemId === false) {
974-
throw new ImportFailureException('failed to add or update the item');
974+
$typeName = strtolower(self::getTypeName());
975+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
975976
}
976977

977978
// add the question to the linker

inc/questiondependency.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
186186
$itemId = $item->add($input);
187187
}
188188
if ($itemId === false) {
189-
throw new ImportFailureException('failed to add or update the item');
189+
$typeName = strtolower(self::getTypeName());
190+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
190191
}
191192

192193
// add the parameter to the linker

inc/questionrange.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
170170
$itemId = $item->add($input);
171171
}
172172
if ($itemId === false) {
173-
throw new ImportFailureException('failed to add or update the item');
173+
$typeName = strtolower(self::getTypeName());
174+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
174175
}
175176

176177
// add the question to the linker

inc/questionregex.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
165165
$itemId = $item->add($input);
166166
}
167167
if ($itemId === false) {
168-
throw new ImportFailureException('failed to add or update the item');
168+
$typeName = strtolower(self::getTypeName());
169+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
169170
}
170171

171172
// add the question to the linker

inc/section.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
253253
$itemId = $item->add($input);
254254
}
255255
if ($itemId === false) {
256-
throw new ImportFailureException('failed to add or update the item');
256+
$typeName = strtolower(self::getTypeName());
257+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
257258
}
258259

259260
// add the section to the linker

inc/target_actor.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
156156
$itemId = $item->add($input);
157157
}
158158
if ($itemId === false) {
159-
throw new ImportFailureException('failed to add or update the item');
159+
$typeName = strtolower(self::getTypeName());
160+
throw new ImportFailureException(sprintf(__('failed to add or update the %1$s %2$s', 'formceator'), $typeName, $input['name']));
160161
}
161162

162163
// add the question to the linker

0 commit comments

Comments
 (0)