From 2487e36c7b880d5f80558206927cd589b24b7a0a Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 16 Jun 2020 11:40:20 +0200 Subject: [PATCH 1/2] fix(form): duplication exception Signed-off-by: Thierry Bugier --- inc/form.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/inc/form.class.php b/inc/form.class.php index a1243b49f..b02907bbd 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1538,7 +1538,15 @@ public function duplicate() { $linker = new PluginFormcreatorLinker(); $export = $this->export(true); - $new_form_id = static::import($linker, $export); + try { + $new_form_id = static::import($linker, $export); + } catch (ImportFailureException $e) { + foreach ($linker->getObjectsByType(PluginFormcreatorForm::class) as $form) { + $form->delete(['id' => $form->getID()]); + } + Session::addMessageAfterRedirect($e->getMessage(), false, ERROR); + return false; + } if ($new_form_id === false) { return false; From 4a1ccc1d333581beef91d0e554dc10916c2ccae4 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Tue, 16 Jun 2020 14:30:52 +0200 Subject: [PATCH 2/2] fix(form): keep failed duplicate Signed-off-by: Thierry Bugier --- inc/form.class.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index b02907bbd..4db3700b9 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1541,10 +1541,13 @@ public function duplicate() { try { $new_form_id = static::import($linker, $export); } catch (ImportFailureException $e) { - foreach ($linker->getObjectsByType(PluginFormcreatorForm::class) as $form) { - $form->delete(['id' => $form->getID()]); - } - Session::addMessageAfterRedirect($e->getMessage(), false, ERROR); + $forms = $linker->getObjectsByType(PluginFormcreatorForm::class); + $form = reset($forms); + $form->update([ + 'id' => $form->getID(), + 'name' => $form->fields['name'] . ' [' . __('Errored duplicate', 'formcreator') . ']', + ]); + Session::addMessageAfterRedirect($e->getMessage(), false, WARNING); return false; }