Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update ticket status when ticket task is de-scheduled #16895

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
10 changes: 10 additions & 0 deletions src/CommonITILTask.php
Expand Up @@ -465,6 +465,16 @@ public function post_updateItem($history = true)
'_disablenotif' => true,
];
$item->update($input2);
} elseif (
$item->isStatusExists(CommonITILObject::ASSIGNED)
&& ($item->fields["status"] == CommonITILObject::PLANNED)
) {
$input2 = [
'id' => $item->getID(),
'status' => CommonITILObject::ASSIGNED,
cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
'_disablenotif' => false,
];
$item->update($input2);
}

if (!isset($this->input['_disablenotif']) && $CFG_GLPI["use_notifications"]) {
Expand Down
52 changes: 52 additions & 0 deletions tests/functional/TicketTask.php
Expand Up @@ -402,6 +402,58 @@ public function testAddFromTemplate()
$this->integer($task->fields['is_private'])->isEqualTo(0);
}

/**
* Test that the ticket status is correctly updated when the task is scheduled and then unscheduled.
*
* @return void
*/
public function testDePlanifiedUpdateParentStatus()
{
$this->login();
$ticket_id = $this->getNewTicket();
$task = new \TicketTask();

$uid = getItemByTypeName('User', TU_USER, true);
$date_begin = new \DateTime(); // ==> now
$date_begin_string = $date_begin->format('Y-m-d H:i:s');
$date_end = new \DateTime(); // ==> +2days
$date_end->add(new \DateInterval('P2D'));
$date_end_string = $date_end->format('Y-m-d H:i:s');

$task_id = $task->add([
'pending' => 0,
'tickets_id' => $ticket_id,
'content' => "Planned Task",
'state' => \Planning::TODO,
'users_id_tech' => $uid,
'begin' => $date_begin_string,
'end' => $date_end_string,
]);
$this->integer($task_id)->isGreaterThan(0);

$this->integer(\Ticket::getById($ticket_id)->fields['status'])->isEqualTo(\Ticket::PLANNED);

$this->boolean($task->update([
'id' => $task_id,
'tickets_id' => $ticket_id,
'content' => "De-planned Task",
'begin' => null,
'end' => null,
]))->isTrue();

$this->integer(\Ticket::getById($ticket_id)->fields['status'])->isEqualTo(\Ticket::ASSIGNED);

$this->boolean($task->update([
'id' => $task_id,
'tickets_id' => $ticket_id,
'content' => "Planned Task",
'begin' => $date_begin_string,
'end' => $date_end_string,
]))->isTrue();

$this->integer(\Ticket::getById($ticket_id)->fields['status'])->isEqualTo(\Ticket::PLANNED);
}

public function testUpdateParentStatus()
{
$this->login();
Expand Down