Skip to content

Commit

Permalink
fix(ticket): solvedate and closedate on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B authored Sep 2, 2024
1 parent 51176a7 commit 5c08bc2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
49 changes: 49 additions & 0 deletions phpunit/functional/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7160,4 +7160,53 @@ public function testGetCommonCriteria()
$result = $DB->request($request);
$this->assertEquals($existing_tickets + 1, $result->count());
}

public function testComputeDefaultValuesForAdd(): void
{
// OK : Inputs dates are good (no modification expected)
$this->createItem('Ticket', [
'name' => __FUNCTION__,
'content' => __FUNCTION__,
'status' => \CommonITILObject::CLOSED,
'date_creation' => '2024-01-11 09:00:00',
'date' => '2024-01-12 09:00:00',
'solvedate' => '2024-01-13 09:00:00',
'date_mod' => '2024-01-14 09:00:00',
'closedate' => '2024-01-15 09:00:00',
]);

// OK : All inputs dates are equal (no modification expected)
$this->createItem('Ticket', [
'name' => __FUNCTION__,
'content' => __FUNCTION__,
'status' => \CommonITILObject::CLOSED,
'date_creation' => '2024-01-11 09:00:00',
'date' => '2024-01-11 09:00:00',
'solvedate' => '2024-01-11 09:00:00',
'date_mod' => '2024-01-11 09:00:00',
'closedate' => '2024-01-11 09:00:00',
]);

// NOK : Bad inputs dates -> fixed durring add
$input = [
'name' => __FUNCTION__,
'content' => __FUNCTION__,
'status' => \CommonITILObject::CLOSED,
'date_creation' => '2024-01-11 09:00:00',
'date' => '2024-01-12 09:00:00',
'solvedate' => '2024-01-11 09:00:00',
'date_mod' => '2024-01-11 09:00:00',
'closedate' => '2024-01-11 09:00:00',
];
$expected = $input;
$expected['solvedate'] = $input['date'];
$expected['closedate'] = $input['date'];

$ticket = new \Ticket();
$input = Sanitizer::sanitize($input);
$id = $ticket->add($input);
$this->assertIsInt($id);
$this->assertGreaterThan(0, $id);
$this->checkInput($ticket, $id, $expected);
}
}
30 changes: 19 additions & 11 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2817,25 +2817,33 @@ public function computeDefaultValuesForAdd($input)
$input["date"] = $_SESSION["glpi_currenttime"];
}

if (isset($input["status"]) && in_array($input["status"], $this->getSolvedStatusArray())) {
if (isset($input["date"])) {
if (in_array($input["status"], $this->getSolvedStatusArray())) {
if (
!isset($input["solvedate"])
|| $input["solvedate"] < $input["date"]
) {
$input["solvedate"] = $input["date"];
} else {
$input["solvedate"] = $_SESSION["glpi_currenttime"];
}
}

if (isset($input["status"]) && in_array($input["status"], $this->getClosedStatusArray())) {
if (isset($input["date"])) {
if (in_array($input["status"], $this->getClosedStatusArray())) {
if (
!isset($input["closedate"])
|| $input["closedate"] < $input["date"]
) {
$input["closedate"] = $input["date"];
} else {
$input["closedate"] = $_SESSION["glpi_currenttime"];
}
$input['solvedate'] = $input["closedate"];
if (
!isset($input["solvedate"])
|| $input["solvedate"] < $input["date"]
|| $input["solvedate"] > $input["closedate"]
) {
$input['solvedate'] = $input["closedate"];
}
}

// Set begin waiting time if status is waiting
if (isset($input["status"]) && ($input["status"] == self::WAITING)) {
// Set begin waiting time if status is waiting
if ($input["status"] == self::WAITING) {
$input['begin_waiting_date'] = $input['date'];
}

Expand Down

0 comments on commit 5c08bc2

Please sign in to comment.