Skip to content

Commit

Permalink
fix(targettichet,targetchange): question tags not updated on duplication
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 10, 2020
1 parent 47cf0c9 commit 22f765d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
15 changes: 5 additions & 10 deletions inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function getCategoryFilter() {

protected function getTaggableFields() {
return [
'name',
'target_name',
'content',
'impactcontent',
'controlistcontent',
Expand Down Expand Up @@ -166,18 +166,13 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
// convert question uuid into id
$questions = $linker->getObjectsByType(PluginFormcreatorQuestion::class);
if ($questions !== false) {
$questionIdentifier = 'id';
if (isset($input['uuid'])) {
$questionIdentifier = 'uuid';
}
$taggableFields = $item->getTaggableFields();
foreach ($questions as $question) {
$id = $question['id'];
$originalId = $question[$questionIdentifier];
foreach ($questions as $originalId => $question) {
$newId = $question->getID();
foreach ($taggableFields as $field) {
$content = $input[$field];
$content = str_replace("##question_$originalId##", "##question_$id##", $content);
$content = str_replace("##answer_$originalId##", "##answer_$id##", $content);
$content = str_replace("##question_$originalId##", "##question_$newId##", $content);
$content = str_replace("##answer_$originalId##", "##answer_$newId##", $content);
$input[$field] = $content;
}
}
Expand Down
15 changes: 5 additions & 10 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,18 +1061,13 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
// convert question uuid into id
$questions = $linker->getObjectsByType(PluginFormcreatorQuestion::class);
if ($questions !== false) {
$questionIdentifier = 'id';
if (isset($input['uuid'])) {
$questionIdentifier = 'uuid';
}
$taggableFields = $item->getTaggableFields();
foreach ($questions as $question) {
$id = $question->getID();
$originalId = $question->fields[$questionIdentifier];
foreach ($questions as $originalId => $question) {
$newId = $question->getID();
foreach ($taggableFields as $field) {
$content = $input[$field];
$content = str_replace("##question_$originalId##", "##question_$id##", $content);
$content = str_replace("##answer_$originalId##", "##answer_$id##", $content);
$content = str_replace("##question_$originalId##", "##question_$newId##", $content);
$content = str_replace("##answer_$originalId##", "##answer_$newId##", $content);
$input[$field] = $content;
}
}
Expand Down Expand Up @@ -1112,7 +1107,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con

protected function getTaggableFields() {
return [
'name',
'target_name',
'content',
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/suite-unit/PluginFormcreatorTargetChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function testGetTaggableFields() {
$instance = new PluginFormcreatorTargetChangeDummy();
$output = $instance->publicGetTaggableFields();
$this->array($output)->isEqualTo([
'name',
'target_name',
'content',
'impactcontent',
'controlistcontent',
Expand Down
2 changes: 1 addition & 1 deletion tests/suite-unit/PluginFormcreatorTargetTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function testGetTaggableFields() {
$instance = new PluginFormcreatorTargetTicketDummy();
$output = $instance->publicGetTaggableFields();
$this->array($output)->isEqualTo([
'name',
'target_name',
'content',
]);
}
Expand Down

0 comments on commit 22f765d

Please sign in to comment.