Skip to content

Commit

Permalink
fix(form,question): duplicate fail on form without section
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 31, 2020
1 parent 3a6968f commit 4db8455
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1986,11 +1986,15 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
}
$importedItems[] = $importedItem;
}
// Delete all other restrictions
// Delete all other sections
$deleteCriteria = [];
if (count($importedItems) > 0) {
$deleteCriteria = ['NOT' => ['id' => $importedItems]];
}
$FormProfile = new PluginFormcreatorSection();
$FormProfile->deleteByCriteria([
$formFk => $itemId,
['NOT' => ['id' => $importedItems]]
$deleteCriteria,
]);
}

Expand Down
20 changes: 18 additions & 2 deletions inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
// add the section to the linker
$linker->addObject($originalId, $item);

// Import the questions
// Import each question
$importedItems = [];
if (isset($input['_questions'])) {
// sort questions by order
usort($input['_questions'], function ($a, $b) {
Expand All @@ -273,9 +274,24 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
});

foreach ($input['_questions'] as $question) {
PluginFormcreatorQuestion::import($linker, $question, $itemId);
$importedItem = PluginFormcreatorQuestion::import($linker, $question, $itemId);
if ($importedItem === false) {
// Falied to import a question
return false;
}
$importedItems[] = $importedItem;
}
}
// Delete all other questions
$deleteCriteria = [];
if (count($importedItems) > 0) {
$deleteCriteria = ['NOT' => ['id' => $importedItems]];
}
$FormProfile = new PluginFormcreatorSection();
$FormProfile->deleteByCriteria([
$formFk => $itemId,
$deleteCriteria,
]);

// Import conditions
if (isset($input['_conditions'])) {
Expand Down

0 comments on commit 4db8455

Please sign in to comment.