Skip to content

Commit

Permalink
fix(targetticket,targetchange): missing update of question ID in targets
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jun 9, 2020
1 parent c502dfd commit 5ecb828
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,25 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
}
}

// Update links to other questions
$questionLinks = [
'due_date_rule' => ['values' => self::DUE_DATE_RULE_ANSWER, 'field' => 'due_date_question'],
'urgency_rule' => ['values' => self::URGENCY_RULE_ANSWER, 'field' => 'urgency_question'],
'tag_type' => ['values' => self::TAG_TYPE_QUESTIONS, 'field' => 'tag_questions'],
'category_rule' => ['values' => self::CATEGORY_RULE_ANSWER, 'field' => 'category_question'],
];
foreach ($questionLinks as $field => $fieldSetting) {
if (!is_array($fieldSetting['values'])) {
$fieldSetting['values'] = [$fieldSetting['values']];
}
if (!in_array($input[$field], $fieldSetting['values'])) {
continue;
}
/**@var PluginFormcreatorQuestion $question */
$question = $linker->getObject($input[$fieldSetting['field']], PluginFormcreatorQuestion::class);
$input[$fieldSetting['field']] = $question->getID();
}

// Add or update
$originalId = $input[$idKey];
if ($itemId !== false) {
Expand Down
22 changes: 22 additions & 0 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,28 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
}
}

// Update links to other questions
$questionLinks = [
'type_rule' => ['values' => self::REQUESTTYPE_ANSWER, 'field' => 'type_question'],
'due_date_rule' => ['values' => self::DUE_DATE_RULE_ANSWER, 'field' => 'due_date_question'],
'urgency_rule' => ['values' => self::URGENCY_RULE_ANSWER, 'field' => 'urgency_question'],
'tag_type' => ['values' => self::TAG_TYPE_QUESTIONS, 'field' => 'tag_questions'],
'category_rule' => ['values' => self::CATEGORY_RULE_ANSWER, 'field' => 'category_question'],
'associate_rule' => ['values' => self::ASSOCIATE_RULE_ANSWER, 'field' => 'associate_question'],
'location_rule' => ['values' => self::LOCATION_RULE_ANSWER, 'field' => 'location_question'],
];
foreach ($questionLinks as $field => $fieldSetting) {
if (!is_array($fieldSetting['values'])) {
$fieldSetting['values'] = [$fieldSetting['values']];
}
if (!in_array($input[$field], $fieldSetting['values'])) {
continue;
}
/**@var PluginFormcreatorQuestion $question */
$question = $linker->getObject($input[$fieldSetting['field']], PluginFormcreatorQuestion::class);
$input[$fieldSetting['field']] = $question->getID();
}

// Add or update
$originalId = $input[$idKey];
if ($itemId !== false) {
Expand Down
2 changes: 2 additions & 0 deletions tests/suite-unit/PluginFormcreatorTargetTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ public function testImport() {
'category_question' => '0',
'associate_rule' => \PluginFormcreatorTargetTicket::ASSOCIATE_RULE_NONE,
'associate_question' => '0',
'type_rule' => 1,
'type_question' => 0,
'uuid' => $uuid,
];

Expand Down

0 comments on commit 5ecb828

Please sign in to comment.