Skip to content

Commit 22f765d

Browse files
committed
fix(targettichet,targetchange): question tags not updated on duplication
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 47cf0c9 commit 22f765d

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

inc/targetchange.class.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function getCategoryFilter() {
8787

8888
protected function getTaggableFields() {
8989
return [
90-
'name',
90+
'target_name',
9191
'content',
9292
'impactcontent',
9393
'controlistcontent',
@@ -166,18 +166,13 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
166166
// convert question uuid into id
167167
$questions = $linker->getObjectsByType(PluginFormcreatorQuestion::class);
168168
if ($questions !== false) {
169-
$questionIdentifier = 'id';
170-
if (isset($input['uuid'])) {
171-
$questionIdentifier = 'uuid';
172-
}
173169
$taggableFields = $item->getTaggableFields();
174-
foreach ($questions as $question) {
175-
$id = $question['id'];
176-
$originalId = $question[$questionIdentifier];
170+
foreach ($questions as $originalId => $question) {
171+
$newId = $question->getID();
177172
foreach ($taggableFields as $field) {
178173
$content = $input[$field];
179-
$content = str_replace("##question_$originalId##", "##question_$id##", $content);
180-
$content = str_replace("##answer_$originalId##", "##answer_$id##", $content);
174+
$content = str_replace("##question_$originalId##", "##question_$newId##", $content);
175+
$content = str_replace("##answer_$originalId##", "##answer_$newId##", $content);
181176
$input[$field] = $content;
182177
}
183178
}

inc/targetticket.class.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,18 +1061,13 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
10611061
// convert question uuid into id
10621062
$questions = $linker->getObjectsByType(PluginFormcreatorQuestion::class);
10631063
if ($questions !== false) {
1064-
$questionIdentifier = 'id';
1065-
if (isset($input['uuid'])) {
1066-
$questionIdentifier = 'uuid';
1067-
}
10681064
$taggableFields = $item->getTaggableFields();
1069-
foreach ($questions as $question) {
1070-
$id = $question->getID();
1071-
$originalId = $question->fields[$questionIdentifier];
1065+
foreach ($questions as $originalId => $question) {
1066+
$newId = $question->getID();
10721067
foreach ($taggableFields as $field) {
10731068
$content = $input[$field];
1074-
$content = str_replace("##question_$originalId##", "##question_$id##", $content);
1075-
$content = str_replace("##answer_$originalId##", "##answer_$id##", $content);
1069+
$content = str_replace("##question_$originalId##", "##question_$newId##", $content);
1070+
$content = str_replace("##answer_$originalId##", "##answer_$newId##", $content);
10761071
$input[$field] = $content;
10771072
}
10781073
}
@@ -1112,7 +1107,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
11121107

11131108
protected function getTaggableFields() {
11141109
return [
1115-
'name',
1110+
'target_name',
11161111
'content',
11171112
];
11181113
}

tests/suite-unit/PluginFormcreatorTargetChange.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function testGetTaggableFields() {
206206
$instance = new PluginFormcreatorTargetChangeDummy();
207207
$output = $instance->publicGetTaggableFields();
208208
$this->array($output)->isEqualTo([
209-
'name',
209+
'target_name',
210210
'content',
211211
'impactcontent',
212212
'controlistcontent',

tests/suite-unit/PluginFormcreatorTargetTicket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function testGetTaggableFields() {
270270
$instance = new PluginFormcreatorTargetTicketDummy();
271271
$output = $instance->publicGetTaggableFields();
272272
$this->array($output)->isEqualTo([
273-
'name',
273+
'target_name',
274274
'content',
275275
]);
276276
}

0 commit comments

Comments
 (0)