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

Add _do_not_compute_takeintoaccount in Common Task #18527

Open
wants to merge 10 commits into
base: 10.0/bugfixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion phpunit/functional/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use TicketValidation;
use User;
use Session;
use Ticket;

/* Test for inc/ticket.class.php */

Expand Down Expand Up @@ -7651,7 +7652,51 @@ public function testGlobalValidationUpdate(): void
'status' => \CommonITILValidation::REFUSED,
]);


$this->assertEquals(\CommonITILValidation::REFUSED, TicketValidation::computeValidationStatus($ticket));
}

public static function doNotComputeTakeIntoAccountProvider(): array
{

return [
[
'input' => [
'is_private' => true,
'state' => \Planning::INFO,
'content' => 'Do Not Compute Take Into Account Task 1',
'_do_not_compute_takeintoaccount' => true
],
'expected' => 0,
],
[
'input' => [
'is_private' => true,
'state' => \Planning::INFO,
'content' => 'Compute Take Into Account Task 2',
],
'expected' => 1,
],
];
}

/**
* @dataProvider doNotComputeTakeIntoAccountProvider
*/
public function testDoNotComputeTakeIntoAccount(array $input, int $expected): void
{
$this->login();

$ticket = $this->createItem('Ticket', [
'name' => 'Do Not Compute Take Into Account Ticket',
'content' => 'Do Not Compute Take Into Account Ticket',
]);

$this->assertEquals(0, $ticket->fields['takeintoaccount_delay_stat']);

$this->createItem('TicketTask', array_merge($input, ['tickets_id' => $ticket->getID()]));

$t = new Ticket();
$t->getFromDB($ticket->getID());
$this->assertEquals($expected, $t->fields['takeintoaccount_delay_stat']);
}
}
7 changes: 7 additions & 0 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5210,6 +5210,13 @@ public function updateDateMod($ID, $no_stat_computation = false, $users_id_lastu
$update['users_id_lastupdater'] = $users_id_lastupdater;
}

// set take into account delay stat
if ($no_stat_computation && $this->getType() == Ticket::class) {
if ($this->fields['takeintoaccount_delay_stat'] == 0) {
$update['takeintoaccount_delay_stat'] = 0;
}
Comment on lines +5215 to +5217
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained in the internal chat, this code does not make sense to me. If $this->fields['takeintoaccount_delay_stat'] equals 0, why should we update it to the same value ?

Also, $no_stat_computation probably means that we should not change the value of the takeintoaccount_delay_stat field, even if we set it to 0.

}

$DB->update(
$this->getTable(),
$update,
Expand Down
2 changes: 1 addition & 1 deletion src/CommonITILTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public function post_addItem()
}
}

$this->input["_job"]->updateDateMod($this->input[$this->input["_job"]->getForeignKeyField()]);
$this->input["_job"]->updateDateMod($this->input[$this->input["_job"]->getForeignKeyField()], $this->input['_do_not_compute_takeintoaccount'] ?? false);
Lainow marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should probably de done to all the calls to updateDateMod. This same ability to not alter SLA/OLA stats will probably be usefull for other actions, like adding an actor, updating a task, adding an automatic followup, ...


if (isset($this->input["actiontime"]) && ($this->input["actiontime"] > 0)) {
$this->input["_job"]->updateActionTime($this->input[$this->input["_job"]->getForeignKeyField()]);
Expand Down
Loading