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 9 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
49 changes: 47 additions & 2 deletions 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 @@ -2349,7 +2350,7 @@ public function testCloneActor()
);

$this->assertCount(
8,
9,
$clonedTicket->getTimelineItems(['with_logs' => true])
);
//User: Add a link with an item: 5 times
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']);
}
}
5 changes: 5 additions & 0 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5210,6 +5210,11 @@ 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) {
$update['takeintoaccount_delay_stat'] = 0;
Copy link
Member

Choose a reason for hiding this comment

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

IMHO, we should not force the value here. takeintoaccount_delay_stat may have already been defined by a previous action.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like that it's okay ?

if ($this->fields['takeintoaccount_delay_stat'] == 0) {
    $update['takeintoaccount_delay_stat'] = 0;
}

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure to understand what you are trying to do. Also, the ticket specific case should probably be managed in the Ticker::updateDateMod() override.

}

$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