Skip to content

Commit

Permalink
Change(timeline): Use last tracked date to create reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
MyvTsv committed Feb 6, 2025
1 parent 30daf6a commit 59fc9bf
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 35 deletions.
94 changes: 78 additions & 16 deletions phpunit/functional/PendingReasonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable
'pendingreasons_id' => $pending_reason1->getID(),
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
// Pending reason is attached to the first followup
// Pending reason is attached to the last followup
'pending_timeline_index' => 0,
]
];
Expand All @@ -515,21 +515,23 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
],
['type' => TicketTask::class],
[
'type' => TicketTask::class,
],

],
'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 task
// Pending reason is attached to the last task
'pending_timeline_index' => 0,
]
];

// Case 4: ticket with two followups
// The first set the pending data and the second change it
// The first set the pending data and the second change the pending data
yield [
'timeline' => [
[
Expand All @@ -553,8 +555,8 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable
'pendingreasons_id' => $pending_reason2->getID(),
'followup_frequency' => 2 * DAY_TIMESTAMP,
'followups_before_resolution' => 1,
// Pending reason is still attached to the first followup, the second one only edited its value
'pending_timeline_index' => 0,
// The pending reason is always attached to the last follow-up, the second one changes the value of the first one
'pending_timeline_index' => 1,
]
];

Expand Down Expand Up @@ -644,8 +646,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable
];

// 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
// This simulates what will be sent if a pending task is sent after a follow-up with retry
yield [
'timeline' => [
[
Expand All @@ -662,17 +663,16 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable
],
'expected' => [
'status' => CommonITILObject::WAITING,
'pendingreasons_id' => 0,
'followup_frequency' => 0,
'followups_before_resolution' => 0,
// Pending reason is attached to the first timeline item
'pendingreasons_id' => $pending_reason1->getID(),
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
// Pending reason is attached to the last followup
'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
// This simulate what will be sent if a pending followup with relauch added after the pending followup without relauch
yield [
'timeline' => [
[
Expand All @@ -693,7 +693,65 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable
'pendingreasons_id' => $pending_reason1->getID(),
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
// Pending reason is attached to the first timeline item
// Pending reason is attached to the last timeline item
'pending_timeline_index' => 1,
]
];

// Case 10: ticket with 2 timeline items
// This simulates what will be sent if a pending follow up without retry is added after a task with waiting
yield [
'timeline' => [
[
'type' => TicketTask::class,
'pending' => 1,
'pendingreasons_id' => $pending_reason1->getID(),
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
],
[
'type' => ITILFollowup::class,
'pending' => 1,
'pendingreasons_id' => 0,
'followup_frequency' => 0,
'followups_before_resolution' => 0,
],
],
'expected' => [
'status' => CommonITILObject::WAITING,
'pendingreasons_id' => 0,
'followup_frequency' => 0,
'followups_before_resolution' => 0,
// Pending reason is attached to the last timeline item
'pending_timeline_index' => 1,
]
];

// Case 11: ticket with 2 timeline items
// This simulates what will be sent if a pending follow with prompt is added after a pending task
yield [
'timeline' => [
[
'type' => TicketTask::class,
'pending' => 1,
'pendingreasons_id' => $pending_reason1->getID(),
'followup_frequency' => 3 * DAY_TIMESTAMP,
'followups_before_resolution' => 2,
],
[
'type' => ITILFollowup::class,
'pending' => 1,
'pendingreasons_id' => $pending_reason2->getID(),
'followup_frequency' => 2 * DAY_TIMESTAMP,
'followups_before_resolution' => 1,
],
],
'expected' => [
'status' => CommonITILObject::WAITING,
'pendingreasons_id' => $pending_reason2->getID(),
'followup_frequency' => 2 * DAY_TIMESTAMP,
'followups_before_resolution' => 1,
// Pending reason is attached to the last timeline item
'pending_timeline_index' => 1,
]
];
Expand Down Expand Up @@ -742,7 +800,7 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void
'pending',
'pendingreasons_id',
'followup_frequency',
'followups_before_resolution'
'followups_before_resolution',
]);
}

Expand Down Expand Up @@ -779,6 +837,10 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void
$correct_timeline_item->getID(),
$last_timeline_item_pending_data->fields['items_id']
);
$this->assertEquals(
$last_timeline_item_pending_data->fields['last_bump_date'],
$ticket_pending_data->fields['last_bump_date']
);
}
}
}
Expand Down
28 changes: 9 additions & 19 deletions src/PendingReason_Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,33 +414,23 @@ public static function handlePendingReasonUpdateFromNewTimelineItem(
}
}

if (!isset($new_timeline_item->input['pendingreasons_id']) && $new_timeline_item->getType() === 'TicketTask') {
$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') {
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'];
}
if (isset($new_timeline_item->input['last_bump_date'])) {
$pending_updates['last_bump_date'] = $new_timeline_item->input['last_bump_date'];
}

$pending_updates_timeline_item = $pending_updates;
$pending_updates_timeline_item['items_id'] = $new_timeline_item->getID();
$pending_updates_timeline_item['itemtype'] = $new_timeline_item::getType();

// 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']);
self::updateForItem($last_pending_timeline_item, $pending_updates);
if ($pending_updates['pendingreasons_id'] > 0 || $new_timeline_item::getType() !== $last_pending::getType()) {
self::createForItem($new_timeline_item, $pending_updates_timeline_item);
}
self::updateForItem($new_timeline_item->input['_job'], $pending_updates);
}

Expand Down

0 comments on commit 59fc9bf

Please sign in to comment.