Skip to content

Commit 6d261dc

Browse files
authored
Fix - Only propagate followups/tasks/documents to parent ticket when child is deleted (#23741)
1 parent 259ef0e commit 6d261dc

File tree

2 files changed

+114
-4
lines changed

2 files changed

+114
-4
lines changed

src/Ticket.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6065,16 +6065,25 @@ public static function getMergedTickets(int $id): array
60656065
{
60666066
global $DB;
60676067

6068-
//look for merged tickets
6068+
//look for merged tickets (only when the source ticket is deleted, i.e. actually merged)
60696069
$merged = [];
60706070
$iterator = $DB->request(
60716071
[
60726072
'FROM' => Ticket_Ticket::getTable(),
6073-
'SELECT' => ['tickets_id_2'],
6073+
'SELECT' => [Ticket_Ticket::getTable() . '.tickets_id_2'],
60746074
'DISTINCT' => true,
6075+
'INNER JOIN' => [
6076+
Ticket::getTable() => [
6077+
'ON' => [
6078+
Ticket_Ticket::getTable() => 'tickets_id_1',
6079+
Ticket::getTable() => 'id',
6080+
],
6081+
],
6082+
],
60756083
'WHERE' => [
6076-
'tickets_id_1' => $id,
6077-
'link' => Ticket_Ticket::SON_OF,
6084+
Ticket_Ticket::getTable() . '.tickets_id_1' => $id,
6085+
Ticket_Ticket::getTable() . '.link' => Ticket_Ticket::SON_OF,
6086+
Ticket::getTable() . '.is_deleted' => 1,
60786087
],
60796088
]
60806089
);

tests/functional/TicketTest.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,6 +4341,107 @@ public function testResponsesAfterMerge(): void
43414341
]));
43424342
}
43434343

4344+
/**
4345+
* When two tickets have a SON_OF link but the child is NOT deleted (not actually merged),
4346+
* responses added to the child must NOT be propagated to the parent.
4347+
*/
4348+
public function testResponsesNotPropagatedWhenChildNotDeleted(): void
4349+
{
4350+
$this->login();
4351+
$_SESSION['glpiactiveprofile']['interface'] = '';
4352+
$this->setEntity('Root entity', true);
4353+
4354+
$parent_id = $this->createItem(
4355+
Ticket::class,
4356+
[
4357+
'name' => 'Parent ticket',
4358+
'content' => 'Parent ticket',
4359+
'entities_id' => 0,
4360+
'status' => CommonITILObject::INCOMING,
4361+
]
4362+
)->getID();
4363+
4364+
$child_id = $this->createItem(
4365+
Ticket::class,
4366+
[
4367+
'name' => 'Child ticket',
4368+
'content' => 'Child ticket',
4369+
'entities_id' => 0,
4370+
'status' => CommonITILObject::INCOMING,
4371+
]
4372+
)->getID();
4373+
4374+
// Create a SON_OF link WITHOUT merging (child is not deleted)
4375+
$this->createItem(
4376+
\Ticket_Ticket::class,
4377+
[
4378+
'link' => \Ticket_Ticket::SON_OF,
4379+
'tickets_id_1' => $child_id,
4380+
'tickets_id_2' => $parent_id,
4381+
]
4382+
);
4383+
4384+
// Add a followup to the child ticket
4385+
$followup = $this->createItem(
4386+
ITILFollowup::class,
4387+
[
4388+
'itemtype' => 'Ticket',
4389+
'items_id' => $child_id,
4390+
'content' => 'Followup on non-deleted child',
4391+
]
4392+
);
4393+
4394+
// The followup must NOT have been copied to the parent
4395+
$this->assertEmpty($followup->find([
4396+
'itemtype' => 'Ticket',
4397+
'items_id' => $parent_id,
4398+
'sourceitems_id' => $child_id,
4399+
]));
4400+
4401+
// Add a task to the child ticket
4402+
$task = $this->createItem(
4403+
TicketTask::class,
4404+
[
4405+
'tickets_id' => $child_id,
4406+
'content' => 'Task on non-deleted child',
4407+
]
4408+
);
4409+
4410+
// The task must NOT have been copied to the parent
4411+
$this->assertEmpty($task->find([
4412+
'tickets_id' => $parent_id,
4413+
'sourceitems_id' => $child_id,
4414+
]));
4415+
4416+
// Add a document to the child ticket
4417+
$documents_id = $this->createItem(
4418+
\Document::class,
4419+
[
4420+
'name' => 'Child ticket document',
4421+
'filename' => 'doc.xls',
4422+
'users_id' => Session::getLoginUserID(),
4423+
]
4424+
)->getID();
4425+
4426+
$document_item = $this->createItem(
4427+
\Document_Item::class,
4428+
[
4429+
'itemtype' => 'Ticket',
4430+
'items_id' => $child_id,
4431+
'documents_id' => $documents_id,
4432+
'entities_id' => '0',
4433+
'is_recursive' => 0,
4434+
]
4435+
);
4436+
4437+
// The document must NOT have been copied to the parent
4438+
$this->assertEmpty($document_item->find([
4439+
'itemtype' => 'Ticket',
4440+
'items_id' => $parent_id,
4441+
'documents_id' => $documents_id,
4442+
]));
4443+
}
4444+
43444445
public function testKeepScreenshotsOnFormReload()
43454446
{
43464447
//login to get session

0 commit comments

Comments
 (0)