Skip to content

Commit

Permalink
fix(question): make import resilient against missing parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Apr 12, 2021
1 parent 9ea1460 commit 1594e6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions inc/abstractfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public function getEmptyParameters() : array {
return [];
}

/**
* Undocumented function
*
* @return PluginFormcreatorAbstractQuestionParameter[]
*/
public final function getParameters() : array {
$parameters = $this->getEmptyParameters();
foreach ($parameters as $fieldname => $parameter) {
Expand Down
12 changes: 11 additions & 1 deletion inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,17 @@ public static function import(PluginFormcreatorLinker $linker, array $input = []
if (isset($input['_parameters'])) {
$parameters = $field->getParameters();
foreach ($parameters as $fieldName => $parameter) {
$parameter::import($linker, $input['_parameters'][$input['fieldtype']][$fieldName], $itemId);
if (is_array($input['_parameters'][$input['fieldtype']][$fieldName])) {
/** @var PluginFormcreatorExportableInterface $parameter */
$parameter::import($linker, $input['_parameters'][$input['fieldtype']][$fieldName], $itemId);
} else {
// Import data incomplete, parameter not defined
// Adding an empty parameter (assuming the question is actually added or updated in DB)
$parameterInput = $parameter->fields;
$parameterInput['plugin_formcreator_questions_id'] = $itemId;
unset($parameterInput['id']);
$parameter->add($parameterInput);
}
}
}

Expand Down

0 comments on commit 1594e6f

Please sign in to comment.