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(timeline): correct updating of reminders and reasons for waiting … #18915

Draft
wants to merge 12 commits into
base: 10.0/bugfixes
Choose a base branch
from
55 changes: 55 additions & 0 deletions phpunit/functional/PendingReasonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,61 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable
'pending_timeline_index' => 0,
]
];

// Case 8: ticket with 2 timeline items
// The first set the pending data and the second send the same data
// This simulate what will be sent if a pending task is added after the pending followup
MyvTsv marked this conversation as resolved.
Show resolved Hide resolved
yield [
'timeline' => [
[
'type' => ITILFollowup::class,
'pending' => 1,
'pendingreasons_id' => $pending_reason1->getID(),
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
],
[
'type' => TicketTask::class,
'pending' => 1,
],
],
'expected' => [
'status' => CommonITILObject::WAITING,
'pendingreasons_id' => 0,
'followup_frequency' => 0,
'followups_before_resolution' => 0,
// Pending reason is attached to the first timeline item
'pending_timeline_index' => 0,
]
];

// Case 9: ticket with 2 timeline items
// The first set the pending data and the second send the same data
// This simulate what will be sent if a pending followup with relauch added after the pending followup relauch
yield [
'timeline' => [
[
'type' => ITILFollowup::class,
'pending' => 1,
'pendingreasons_id' => 0,
],
[
'type' => ITILFollowup::class,
'pending' => 1,
'pendingreasons_id' => $pending_reason1->getID(),
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
],
],
'expected' => [
'status' => CommonITILObject::WAITING,
'pendingreasons_id' => $pending_reason1->getID(),
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
// Pending reason is attached to the first timeline item
'pending_timeline_index' => 1,
]
];
}

/**
Expand Down
19 changes: 19 additions & 0 deletions src/PendingReason_Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ public static function handlePendingReasonUpdateFromNewTimelineItem(

// Let's check if there is any real updates before going any further
$pending_updates = [];

$fields_to_check_for_updates = ['pendingreasons_id', 'followup_frequency', 'followups_before_resolution'];
foreach ($fields_to_check_for_updates as $field) {
if (
Expand All @@ -413,11 +414,29 @@ public static function handlePendingReasonUpdateFromNewTimelineItem(
}
}

if (!isset($new_timeline_item->input['pendingreasons_id']) && $new_timeline_item->getType() === 'TicketTask') {
MyvTsv marked this conversation as resolved.
Show resolved Hide resolved
$pending_updates = [
'pendingreasons_id' => 0,
'followup_frequency' => 0,
'followups_before_resolution' => 0,
];
}

// No actual updates -> nothing to be done
if (count($pending_updates) == 0) {
return;
}

if ($new_timeline_item->getType() === 'ITILFollowup') {
MyvTsv marked this conversation as resolved.
Show resolved Hide resolved
if ($last_pending->fields['pendingreasons_id'] == 0) {
$pending_updates['items_id'] = $new_timeline_item->getID();
$pending_updates['itemtype'] = $new_timeline_item::getType();
$pending_updates['last_bump_date'] = $new_timeline_item->fields['last_bump_date'];
} else {
$pending_updates['last_bump_date'] = $last_pending->fields['last_bump_date'];
}
}

// Update last pending item and parent
$last_pending_timeline_item = new $last_pending->fields['itemtype']();
$last_pending_timeline_item->getFromDB($last_pending->fields['items_id']);
Expand Down