From b12780da7d04532200a8a96089b23d0a06f15d42 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 4 Feb 2025 15:25:05 +0100 Subject: [PATCH 01/12] fix(timeline): correct updating of reminders and reasons for waiting messages --- src/PendingReason_Item.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/PendingReason_Item.php b/src/PendingReason_Item.php index 2f61958945b..6dfaaf7285f 100644 --- a/src/PendingReason_Item.php +++ b/src/PendingReason_Item.php @@ -403,25 +403,22 @@ 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 ( isset($new_timeline_item->input[$field]) - && $new_timeline_item->input[$field] != $last_pending->fields[$field] ) { $pending_updates[$field] = $new_timeline_item->input[$field]; + } else { + $pending_updates[$field] = 0; } } - // No actual updates -> nothing to be done - if (count($pending_updates) == 0) { - return; + if ($new_timeline_item::class === ITILFollowup::class) { + self::createForItem($new_timeline_item, $pending_updates); } - // 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); self::updateForItem($new_timeline_item->input['_job'], $pending_updates); } From 727a78e4277332eb3e801ec30de15d3c8265bbcc Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 4 Feb 2025 16:08:36 +0100 Subject: [PATCH 02/12] fix bug --- src/PendingReason_Item.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/PendingReason_Item.php b/src/PendingReason_Item.php index 6dfaaf7285f..29690a81771 100644 --- a/src/PendingReason_Item.php +++ b/src/PendingReason_Item.php @@ -411,15 +411,16 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( ) { $pending_updates[$field] = $new_timeline_item->input[$field]; } else { - $pending_updates[$field] = 0; + $pending_updates[$field] = "0"; } } - if ($new_timeline_item::class === ITILFollowup::class) { - self::createForItem($new_timeline_item, $pending_updates); - } + self::createForItem($new_timeline_item, $pending_updates); - self::updateForItem($new_timeline_item->input['_job'], $pending_updates); + // If the ticket is already pending and the follow-up is pending, updating the ticket waiting is not necessary + if (!($new_timeline_item::class === ITILFollowup::class && $pending_updates['pendingreasons_id'] === "0")) { + self::updateForItem($new_timeline_item->input['_job'], $pending_updates); + } } /** From 2934a77fd6867fe06c0beffe5253c164764b4974 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 5 Feb 2025 09:28:26 +0100 Subject: [PATCH 03/12] fix bug and add TU --- phpunit/functional/PendingReasonTest.php | 56 ++++++++++++++++++++++++ src/PendingReason_Item.php | 33 +++++++++++--- 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index 943792f9fda..e82cd95e3c6 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -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 + 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, + ] + ]; } /** @@ -720,6 +775,7 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void $correct_timeline_item::getType(), $last_timeline_item_pending_data->fields['itemtype'] ); + $test = $correct_timeline_item->getID(); $this->assertEquals( $correct_timeline_item->getID(), $last_timeline_item_pending_data->fields['items_id'] diff --git a/src/PendingReason_Item.php b/src/PendingReason_Item.php index 29690a81771..6c2aaa05ae1 100644 --- a/src/PendingReason_Item.php +++ b/src/PendingReason_Item.php @@ -408,19 +408,40 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( foreach ($fields_to_check_for_updates as $field) { if ( isset($new_timeline_item->input[$field]) + && $new_timeline_item->input[$field] != $last_pending->fields[$field] ) { $pending_updates[$field] = $new_timeline_item->input[$field]; - } else { - $pending_updates[$field] = "0"; } } - self::createForItem($new_timeline_item, $pending_updates); + 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 the ticket is already pending and the follow-up is pending, updating the ticket waiting is not necessary - if (!($new_timeline_item::class === ITILFollowup::class && $pending_updates['pendingreasons_id'] === "0")) { - self::updateForItem($new_timeline_item->input['_job'], $pending_updates); + 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']; + } } + + // 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); + self::updateForItem($new_timeline_item->input['_job'], $pending_updates); } /** From 30daf6a58be046a5707153cbb237be1597a44b1f Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 5 Feb 2025 09:43:26 +0100 Subject: [PATCH 04/12] remove unused var --- phpunit/functional/PendingReasonTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index e82cd95e3c6..3ca579db208 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -775,7 +775,6 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void $correct_timeline_item::getType(), $last_timeline_item_pending_data->fields['itemtype'] ); - $test = $correct_timeline_item->getID(); $this->assertEquals( $correct_timeline_item->getID(), $last_timeline_item_pending_data->fields['items_id'] From 59fc9bf1229fd0df54d793a1900571b6b2a149cf Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 6 Feb 2025 15:01:04 +0100 Subject: [PATCH 05/12] Change(timeline): Use last tracked date to create reminders --- phpunit/functional/PendingReasonTest.php | 94 ++++++++++++++++++++---- src/PendingReason_Item.php | 28 +++---- 2 files changed, 87 insertions(+), 35 deletions(-) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index 3ca579db208..e29ae4cf59a 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -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, ] ]; @@ -515,7 +515,9 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, ], - ['type' => TicketTask::class], + [ + 'type' => TicketTask::class, + ], ], 'expected' => [ @@ -523,13 +525,13 @@ 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 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' => [ [ @@ -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, ] ]; @@ -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' => [ [ @@ -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' => [ [ @@ -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, ] ]; @@ -742,7 +800,7 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void 'pending', 'pendingreasons_id', 'followup_frequency', - 'followups_before_resolution' + 'followups_before_resolution', ]); } @@ -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'] + ); } } } diff --git a/src/PendingReason_Item.php b/src/PendingReason_Item.php index 6c2aaa05ae1..0d84bc45817 100644 --- a/src/PendingReason_Item.php +++ b/src/PendingReason_Item.php @@ -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); } From f0a902d1b664ec3d630d28fcb0ee8252b554305b Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 7 Feb 2025 11:49:40 +0100 Subject: [PATCH 06/12] add TU --- phpunit/functional/PendingReasonTest.php | 116 +++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index e29ae4cf59a..46924f022b5 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -844,4 +844,120 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void } } } + + protected function testCronPendingReasonAutobumpAutosolveProvider() + { + $this->login(); + $entity = getItemByTypeName('Entity', '_test_root_entity', true); + + $currentDate = $_SESSION['glpi_currenttime']; + + // Create a set of pending reasons that will be reused in our test cases + list( + $pending_reason1, + ) = $this->createItems(\PendingReason::class, [ + ['entities_id' => $entity, 'is_recursive' => true, 'name' => 'Pending 1'], + ]); + + yield [ + 'timeline' => [ + [ + 'type' => ITILFollowup::class, + 'pending' => 1, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => 3 * DAY_TIMESTAMP, + 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-30 seconds', strtotime($currentDate))), + 'dump_count' => 0, + ], + ], + 'expected' => [ + [ + 'pending' => 1, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => 3 * DAY_TIMESTAMP, + 'followups_before_resolution' => 2, + ] + ], + 'expectedTicket' => [ + 'status' => CommonITILObject::WAITING, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => 3 * DAY_TIMESTAMP, + 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-30 seconds', strtotime($currentDate))), + 'dump_count' => 0, + ] + ]; + } + + public function testCronPendingReasonAutobumpAutosolve() + { + $provider = $this->testCronPendingReasonAutobumpAutosolveProvider(); + foreach ($provider as $row) { + $timeline = $row['timeline']; + $expected = $row['expected']; + $expectedTicket = $row['expectedTicket']; + + // Create test ticket + $ticket = $this->createItem(Ticket::class, [ + 'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true), + 'name' => 'test', + 'content' => 'test', + ]); + + // Insert timeline + $items = []; + foreach ($timeline as $timeline_item) { + // Insert fake content + $timeline_item['content'] = 'test'; + + // Read and prepare itemtype (task or followup) + $itemtype = $timeline_item['type']; + unset($timeline_item['type']); + + if ($itemtype == ITILFollowup::class) { + $timeline_item['itemtype'] = Ticket::class; + $timeline_item['items_id'] = $ticket->getID(); + } else { + $timeline_item['tickets_id'] = $ticket->getID(); + } + $items[] = $this->createItem($itemtype, $timeline_item, [ + 'pending', + 'pendingreasons_id', + 'followup_frequency', + 'followups_before_resolution', + 'last_bump_date', + 'dump_count', + ]); + } + + // launch Cron for closing tickets + $mode = - \CronTask::MODE_EXTERNAL; // force + \CronTask::launch($mode, 5, 'pendingreason_autobump_autosolve'); + + // Reload ticket + $this->assertTrue($ticket->getFromDB($ticket->getID())); + + /** @var Ticket $ticket */ + $timeline = $ticket->getTimelineItems(); + + foreach ($timeline as $index => $timeline_item) { + $this->assertEquals($expected[$index]['pending'], $timeline_item->fields['pending']); + if ($expected[$index]['pending']) { + $pending_item = PendingReason_Item::getForItem($timeline_item); + $this->assertEquals($expected[$index]['pendingreasons_id'], $pending_item->fields['pendingreasons_id']); + $this->assertEquals($expected[$index]['followup_frequency'], $pending_item->fields['followup_frequency']); + $this->assertEquals($expected[$index]['followups_before_resolution'], $pending_item->fields['followups_before_resolution']); + } + } + + $ticket_pending_data = PendingReason_Item::getForItem($ticket); + $this->assertEquals($expectedTicket['status'], $ticket->fields['status']); + $this->assertEquals($expectedTicket['pendingreasons_id'], $ticket_pending_data->fields['pendingreasons_id']); + $this->assertEquals($expectedTicket['followup_frequency'], $ticket_pending_data->fields['followup_frequency']); + $this->assertEquals($expectedTicket['followups_before_resolution'], $ticket_pending_data->fields['followups_before_resolution']); + $this->assertEquals($expectedTicket['last_bump_date'], $ticket_pending_data->fields['last_bump_date']); + $this->assertEquals($expectedTicket['dump_count'], $ticket_pending_data->fields['dump_count']); + } + } } From 61108691f444df31f8293c0bf9258639b5833aa9 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 7 Feb 2025 15:03:42 +0100 Subject: [PATCH 07/12] add TU --- phpunit/functional/PendingReasonTest.php | 104 +++++++++++++++++------ src/PendingReason_Item.php | 15 ++-- 2 files changed, 84 insertions(+), 35 deletions(-) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index 46924f022b5..b835d7c05ab 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -850,7 +850,8 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() $this->login(); $entity = getItemByTypeName('Entity', '_test_root_entity', true); - $currentDate = $_SESSION['glpi_currenttime']; + $currentDate = date('Y-m-d H:i:s'); + $followup_frequency = 3 * DAY_TIMESTAMP; // Create a set of pending reasons that will be reused in our test cases list( @@ -865,27 +866,85 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'type' => ITILFollowup::class, 'pending' => 1, 'pendingreasons_id' => $pending_reason1->getID(), - 'followup_frequency' => 3 * DAY_TIMESTAMP, + 'followup_frequency' => $followup_frequency, + 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, + 'bump_count' => 0, + ], + ], + 'expected' => [ + 'status' => CommonITILObject::WAITING, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => $followup_frequency, + 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, + 'bump_count' => 0, + ] + ]; + + yield [ + 'timeline' => [ + [ + 'type' => TicketTask::class, + 'pending' => 1, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-30 seconds', strtotime($currentDate))), - 'dump_count' => 0, + 'bump_count' => 0, + ], + ], + 'expected' => [ + 'status' => CommonITILObject::WAITING, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => $followup_frequency, + 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-30 seconds', strtotime($currentDate))), + 'bump_count' => 0, + ] + ]; + + yield [ + 'timeline' => [ + [ + 'type' => ITILFollowup::class, + 'pending' => 1, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => $followup_frequency, + 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . DAY_TIMESTAMP . ' seconds', strtotime($currentDate))), + 'bump_count' => 0, ], ], 'expected' => [ + 'status' => CommonITILObject::WAITING, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => $followup_frequency, + 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . DAY_TIMESTAMP . ' seconds', strtotime($currentDate))), + 'bump_count' => 0, + ] + ]; + + yield [ + 'timeline' => [ [ + 'type' => ITILFollowup::class, 'pending' => 1, 'pendingreasons_id' => $pending_reason1->getID(), - 'followup_frequency' => 3 * DAY_TIMESTAMP, + 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - ] + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency + 1 . ' seconds', strtotime($currentDate))), + 'bump_count' => 0, + ], ], - 'expectedTicket' => [ + 'expected' => [ 'status' => CommonITILObject::WAITING, 'pendingreasons_id' => $pending_reason1->getID(), - 'followup_frequency' => 3 * DAY_TIMESTAMP, + 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-30 seconds', strtotime($currentDate))), - 'dump_count' => 0, + 'last_bump_date' => $currentDate, + 'bump_count' => 1, ] ]; } @@ -896,7 +955,6 @@ public function testCronPendingReasonAutobumpAutosolve() foreach ($provider as $row) { $timeline = $row['timeline']; $expected = $row['expected']; - $expectedTicket = $row['expectedTicket']; // Create test ticket $ticket = $this->createItem(Ticket::class, [ @@ -927,13 +985,13 @@ public function testCronPendingReasonAutobumpAutosolve() 'followup_frequency', 'followups_before_resolution', 'last_bump_date', - 'dump_count', + 'bump_count', ]); } // launch Cron for closing tickets $mode = - \CronTask::MODE_EXTERNAL; // force - \CronTask::launch($mode, 5, 'pendingreason_autobump_autosolve'); + \CronTask::launch($mode, 1, 'pendingreason_autobump_autosolve'); // Reload ticket $this->assertTrue($ticket->getFromDB($ticket->getID())); @@ -941,23 +999,13 @@ public function testCronPendingReasonAutobumpAutosolve() /** @var Ticket $ticket */ $timeline = $ticket->getTimelineItems(); - foreach ($timeline as $index => $timeline_item) { - $this->assertEquals($expected[$index]['pending'], $timeline_item->fields['pending']); - if ($expected[$index]['pending']) { - $pending_item = PendingReason_Item::getForItem($timeline_item); - $this->assertEquals($expected[$index]['pendingreasons_id'], $pending_item->fields['pendingreasons_id']); - $this->assertEquals($expected[$index]['followup_frequency'], $pending_item->fields['followup_frequency']); - $this->assertEquals($expected[$index]['followups_before_resolution'], $pending_item->fields['followups_before_resolution']); - } - } - $ticket_pending_data = PendingReason_Item::getForItem($ticket); - $this->assertEquals($expectedTicket['status'], $ticket->fields['status']); - $this->assertEquals($expectedTicket['pendingreasons_id'], $ticket_pending_data->fields['pendingreasons_id']); - $this->assertEquals($expectedTicket['followup_frequency'], $ticket_pending_data->fields['followup_frequency']); - $this->assertEquals($expectedTicket['followups_before_resolution'], $ticket_pending_data->fields['followups_before_resolution']); - $this->assertEquals($expectedTicket['last_bump_date'], $ticket_pending_data->fields['last_bump_date']); - $this->assertEquals($expectedTicket['dump_count'], $ticket_pending_data->fields['dump_count']); + $this->assertEquals($expected['status'], $ticket->fields['status']); + $this->assertEquals($expected['pendingreasons_id'], $ticket_pending_data->fields['pendingreasons_id']); + $this->assertEquals($expected['followup_frequency'], $ticket_pending_data->fields['followup_frequency']); + $this->assertEquals($expected['followups_before_resolution'], $ticket_pending_data->fields['followups_before_resolution']); + $this->assertEquals($expected['last_bump_date'], $ticket_pending_data->fields['last_bump_date']); + $this->assertEquals($expected['bump_count'], $ticket_pending_data->fields['bump_count']); } } } diff --git a/src/PendingReason_Item.php b/src/PendingReason_Item.php index 0d84bc45817..63b2bca4b6c 100644 --- a/src/PendingReason_Item.php +++ b/src/PendingReason_Item.php @@ -375,6 +375,13 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( ): void { $last_pending = self::getLastPendingTimelineItemDataForItem($new_timeline_item->input['_job']); + // Let's check if there is any real updates before going any further + $pending_updates = []; + + if (isset($new_timeline_item->input['last_bump_date'])) { + $pending_updates['last_bump_date'] = $new_timeline_item->input['last_bump_date']; + } + // There is no existing pending data on previous timeline items for this ticket // Nothing to be done here since the goal of this method is to update active pending data if (!$last_pending) { @@ -388,6 +395,7 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( $last_pending->fields['itemtype'] == $new_timeline_item::getType() && $last_pending->fields['items_id'] == $new_timeline_item->getID() ) { + self::updateForItem($new_timeline_item->input['_job'], $pending_updates); return; } @@ -401,9 +409,6 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( // was added on a CommonITILObject which already had pending data // This mean the user might be trying to update the existing pending reason data - // 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 ( @@ -419,10 +424,6 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( return; } - 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(); From c9960172b473c80a414935ef9b90784ffbe59b57 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 10 Feb 2025 14:01:39 +0100 Subject: [PATCH 08/12] fix TU --- phpunit/functional/PendingReasonTest.php | 105 +++++++++++++++++++++-- src/Features/ParentStatus.php | 4 + src/PendingReasonCron.php | 9 +- src/PendingReason_Item.php | 31 ++++--- 4 files changed, 123 insertions(+), 26 deletions(-) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index b835d7c05ab..0cbe36c7472 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -45,6 +45,8 @@ use ProblemTask; use Ticket; use TicketTask; +use ITILFollowupTemplate; +use SolutionTemplate; class PendingReasonTest extends DbTestCase { @@ -464,6 +466,9 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable $this->login(); $entity = getItemByTypeName('Entity', '_test_root_entity', true); + $currentDate = date('Y-m-d H:i:s'); + $_SESSION['glpi_currenttime'] = $currentDate; + // Create a set of pending reasons that will be reused in our test cases list( $pending_reason1, @@ -493,6 +498,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, ], ], 'expected' => [ @@ -502,6 +508,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the last followup 'pending_timeline_index' => 0, + 'last_bump_date' => $currentDate, ] ]; @@ -514,6 +521,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, ], [ 'type' => TicketTask::class, @@ -527,6 +535,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the last task 'pending_timeline_index' => 0, + 'last_bump_date' => $currentDate, ] ]; @@ -540,6 +549,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, ], [ 'type' => ITILFollowup::class, @@ -547,6 +557,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason2->getID(), 'followup_frequency' => 2 * DAY_TIMESTAMP, 'followups_before_resolution' => 1, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ], ], @@ -557,6 +568,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 1, // 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, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ] ]; @@ -592,6 +604,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, ], [ 'type' => TicketTask::class, @@ -603,6 +616,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason2->getID(), 'followup_frequency' => 0, 'followups_before_resolution' => 0, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ], ], 'expected' => [ @@ -612,6 +626,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 0, // Pending reason is attached to the third timeline item 'pending_timeline_index' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ] ]; @@ -626,6 +641,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, ], [ 'type' => ITILFollowup::class, @@ -633,6 +649,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ], ], 'expected' => [ @@ -642,6 +659,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the first timeline item 'pending_timeline_index' => 0, + 'last_bump_date' => $currentDate, ] ]; @@ -655,10 +673,12 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, ], [ 'type' => TicketTask::class, 'pending' => 1, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ], ], 'expected' => [ @@ -668,6 +688,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the last followup 'pending_timeline_index' => 0, + 'last_bump_date' => $currentDate, ] ]; @@ -679,6 +700,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'type' => ITILFollowup::class, 'pending' => 1, 'pendingreasons_id' => 0, + 'last_bump_date' => $currentDate, ], [ 'type' => ITILFollowup::class, @@ -686,6 +708,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ], ], 'expected' => [ @@ -695,6 +718,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the last timeline item 'pending_timeline_index' => 1, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ] ]; @@ -708,6 +732,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, ], [ 'type' => ITILFollowup::class, @@ -715,6 +740,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => 0, 'followup_frequency' => 0, 'followups_before_resolution' => 0, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ], ], 'expected' => [ @@ -724,6 +750,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 0, // Pending reason is attached to the last timeline item 'pending_timeline_index' => 1, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ] ]; @@ -737,6 +764,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, ], [ 'type' => ITILFollowup::class, @@ -744,6 +772,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason2->getID(), 'followup_frequency' => 2 * DAY_TIMESTAMP, 'followups_before_resolution' => 1, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ], ], 'expected' => [ @@ -753,6 +782,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 1, // Pending reason is attached to the last timeline item 'pending_timeline_index' => 1, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), ] ]; } @@ -801,6 +831,7 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void 'pendingreasons_id', 'followup_frequency', 'followups_before_resolution', + 'last_bump_date', ]); } @@ -848,16 +879,30 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void protected function testCronPendingReasonAutobumpAutosolveProvider() { $this->login(); + $entity = getItemByTypeName('Entity', '_test_root_entity', true); $currentDate = date('Y-m-d H:i:s'); $followup_frequency = 3 * DAY_TIMESTAMP; + $_SESSION['glpi_currenttime'] = $currentDate; + + $itilfollowuptemplate = $this->createItem(ITILFollowupTemplate::class, [ + 'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true), + 'name' => 'test', + 'content' => 'test', + ]); + + $itilsolutiontemplate = $this->createItem(SolutionTemplate::class, [ + 'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true), + 'name' => 'test', + 'content' => 'test', + ]); // Create a set of pending reasons that will be reused in our test cases list( $pending_reason1, ) = $this->createItems(\PendingReason::class, [ - ['entities_id' => $entity, 'is_recursive' => true, 'name' => 'Pending 1'], + ['entities_id' => $entity, 'is_recursive' => true, 'name' => 'Pending 1', 'itilfollowuptemplates_id' => $itilfollowuptemplate->getID(), 'solutiontemplates_id' => $itilsolutiontemplate->getID()], ]); yield [ @@ -877,7 +922,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $currentDate, 'bump_count' => 0, ] ]; @@ -947,6 +992,50 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'bump_count' => 1, ] ]; + + yield [ + 'timeline' => [ + [ + 'type' => ITILFollowup::class, + 'pending' => 1, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => $followup_frequency, + 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency + 1 . ' seconds', strtotime($currentDate))), + 'bump_count' => 1, + ], + ], + 'expected' => [ + 'status' => CommonITILObject::WAITING, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => $followup_frequency, + 'followups_before_resolution' => 2, + 'last_bump_date' => $currentDate, + 'bump_count' => 2, + ] + ]; + + yield [ + 'timeline' => [ + [ + 'type' => ITILFollowup::class, + 'pending' => 1, + 'pendingreasons_id' => $pending_reason1->getID(), + 'followup_frequency' => $followup_frequency, + 'followups_before_resolution' => 2, + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency + 1 . ' seconds', strtotime($currentDate))), + 'bump_count' => 2, + ], + ], + 'expected' => [ + 'status' => CommonITILObject::SOLVED, + 'pendingreasons_id' => 0, + 'followup_frequency' => 0, + 'followups_before_resolution' => 0, + 'last_bump_date' => $currentDate, + 'bump_count' => 3, + ] + ]; } public function testCronPendingReasonAutobumpAutosolve() @@ -1001,11 +1090,13 @@ public function testCronPendingReasonAutobumpAutosolve() $ticket_pending_data = PendingReason_Item::getForItem($ticket); $this->assertEquals($expected['status'], $ticket->fields['status']); - $this->assertEquals($expected['pendingreasons_id'], $ticket_pending_data->fields['pendingreasons_id']); - $this->assertEquals($expected['followup_frequency'], $ticket_pending_data->fields['followup_frequency']); - $this->assertEquals($expected['followups_before_resolution'], $ticket_pending_data->fields['followups_before_resolution']); - $this->assertEquals($expected['last_bump_date'], $ticket_pending_data->fields['last_bump_date']); - $this->assertEquals($expected['bump_count'], $ticket_pending_data->fields['bump_count']); + if ($ticket->fields['status'] == CommonITILObject::WAITING) { + $this->assertEquals($expected['pendingreasons_id'], $ticket_pending_data->fields['pendingreasons_id']); + $this->assertEquals($expected['followup_frequency'], $ticket_pending_data->fields['followup_frequency']); + $this->assertEquals($expected['followups_before_resolution'], $ticket_pending_data->fields['followups_before_resolution']); + $this->assertEquals($expected['last_bump_date'], $ticket_pending_data->fields['last_bump_date']); + $this->assertEquals($expected['bump_count'], $ticket_pending_data->fields['bump_count']); + } } } } diff --git a/src/Features/ParentStatus.php b/src/Features/ParentStatus.php index d83563d17c4..af7bfd7f55b 100644 --- a/src/Features/ParentStatus.php +++ b/src/Features/ParentStatus.php @@ -66,11 +66,15 @@ public function updateParentStatus(CommonITILObject $parentitem, array $input): 'followup_frequency' => $input['followup_frequency'] ?? 0, 'followups_before_resolution' => $input['followups_before_resolution'] ?? 0, 'previous_status' => $parentitem->fields['status'], + 'last_bump_date' => $input["last_bump_date"] ?? $_SESSION["glpi_currenttime"], + 'bump_count' => $input["bump_count"] ?? 0, ]); PendingReason_Item::createForItem($this, [ 'pendingreasons_id' => $input['pendingreasons_id'] ?? 0, 'followup_frequency' => $input['followup_frequency'] ?? 0, 'followups_before_resolution' => $input['followups_before_resolution'] ?? 0, + 'last_bump_date' => $input["last_bump_date"] ?? $_SESSION["glpi_currenttime"], + 'bump_count' => $input["bump_count"] ?? 0, ]); } } diff --git a/src/PendingReasonCron.php b/src/PendingReasonCron.php index e6744016057..09bafee4743 100644 --- a/src/PendingReasonCron.php +++ b/src/PendingReasonCron.php @@ -90,10 +90,9 @@ public static function cronPendingreason_autobump_autosolve(CronTask $task) $now = date("Y-m-d H:i:s"); - $data = $DB->request([ - 'SELECT' => 'id', - 'FROM' => PendingReason_Item::getTable(), - 'WHERE' => [ + $pending_items = new PendingReason_Item(); + $data = $pending_items->find([ + [ 'pendingreasons_id' => ['>', 0], 'followup_frequency' => ['>', 0], 'itemtype' => $targets @@ -144,7 +143,7 @@ public static function cronPendingreason_autobump_autosolve(CronTask $task) $success = $pending_item->update([ 'id' => $pending_item->getID(), 'bump_count' => $pending_item->fields['bump_count'] + 1, - 'last_bump_date' => date("Y-m-d H:i:s"), + 'last_bump_date' => $_SESSION['glpi_currenttime'], ]); if (!$success) { diff --git a/src/PendingReason_Item.php b/src/PendingReason_Item.php index 63b2bca4b6c..50b96a5b323 100644 --- a/src/PendingReason_Item.php +++ b/src/PendingReason_Item.php @@ -96,7 +96,7 @@ public static function createForItem(CommonDBTM $item, array $fields): bool $fields['itemtype'] = $item::getType(); $fields['items_id'] = $item->getID(); - $fields['last_bump_date'] = $_SESSION['glpi_currenttime']; + //$fields['last_bump_date'] = $_SESSION['glpi_currenttime']; $success = $em->add($fields); if (!$success) { trigger_error("Failed to create PendingReason_Item", E_USER_WARNING); @@ -374,13 +374,7 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( CommonDBTM $new_timeline_item ): void { $last_pending = self::getLastPendingTimelineItemDataForItem($new_timeline_item->input['_job']); - - // Let's check if there is any real updates before going any further - $pending_updates = []; - - if (isset($new_timeline_item->input['last_bump_date'])) { - $pending_updates['last_bump_date'] = $new_timeline_item->input['last_bump_date']; - } + $ticket_pending_updates = []; // There is no existing pending data on previous timeline items for this ticket // Nothing to be done here since the goal of this method is to update active pending data @@ -388,6 +382,10 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( return; } + if (isset($new_timeline_item->input['last_bump_date'])) { + $ticket_pending_updates['last_bump_date'] = $new_timeline_item->input['last_bump_date']; + } + // The new timeline item is the latest pending reason // This mean there was no active pending reason before this timeline item was added // Nothing to be done here as we don't have any older active pending reason to update @@ -395,7 +393,7 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( $last_pending->fields['itemtype'] == $new_timeline_item::getType() && $last_pending->fields['items_id'] == $new_timeline_item->getID() ) { - self::updateForItem($new_timeline_item->input['_job'], $pending_updates); + self::updateForItem($new_timeline_item->input['_job'], $ticket_pending_updates); return; } @@ -409,30 +407,35 @@ public static function handlePendingReasonUpdateFromNewTimelineItem( // was added on a CommonITILObject which already had pending data // This mean the user might be trying to update the existing pending reason data + // Let's check if there is any real updates before going any further + $pending_updates_timeline_item = []; + $fields_to_check_for_updates = ['pendingreasons_id', 'followup_frequency', 'followups_before_resolution']; foreach ($fields_to_check_for_updates as $field) { if ( isset($new_timeline_item->input[$field]) && $new_timeline_item->input[$field] != $last_pending->fields[$field] ) { - $pending_updates[$field] = $new_timeline_item->input[$field]; + $pending_updates_timeline_item[$field] = $new_timeline_item->input[$field]; } } // No actual updates -> nothing to be done - if (count($pending_updates) == 0) { + if (count($pending_updates_timeline_item) == 0) { return; } - $pending_updates_timeline_item = $pending_updates; + $ticket_pending_updates += $pending_updates_timeline_item; + $pending_updates_timeline_item = $ticket_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 - if ($pending_updates['pendingreasons_id'] > 0 || $new_timeline_item::getType() !== $last_pending::getType()) { + if ($ticket_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); + self::updateForItem($new_timeline_item->input['_job'], $ticket_pending_updates); } /** From 9e2ddb5ab373951db7722f15578df0d8ab4be456 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 10 Feb 2025 14:12:22 +0100 Subject: [PATCH 09/12] add comment TU --- phpunit/functional/PendingReasonTest.php | 10 ++++++++-- src/PendingReasonCron.php | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index 0cbe36c7472..8b0cc347e5c 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -905,6 +905,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() ['entities_id' => $entity, 'is_recursive' => true, 'name' => 'Pending 1', 'itilfollowuptemplates_id' => $itilfollowuptemplate->getID(), 'solutiontemplates_id' => $itilsolutiontemplate->getID()], ]); + // Case 1: followup just published yield [ 'timeline' => [ [ @@ -927,6 +928,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() ] ]; + // Case 2: task just published yield [ 'timeline' => [ [ @@ -949,6 +951,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() ] ]; + // Case 3: follow up that will soon be bumped yield [ 'timeline' => [ [ @@ -957,7 +960,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . DAY_TIMESTAMP . ' seconds', strtotime($currentDate))), + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency . ' seconds', strtotime($currentDate))), 'bump_count' => 0, ], ], @@ -966,11 +969,12 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . DAY_TIMESTAMP . ' seconds', strtotime($currentDate))), + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency . ' seconds', strtotime($currentDate))), 'bump_count' => 0, ] ]; + // Case 4: follow up that will be bumped one time yield [ 'timeline' => [ [ @@ -993,6 +997,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() ] ]; + // Case 5: follow up that will be bumped two times yield [ 'timeline' => [ [ @@ -1015,6 +1020,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() ] ]; + // Case 6: follow up that will be bumped three times. Close the ticket yield [ 'timeline' => [ [ diff --git a/src/PendingReasonCron.php b/src/PendingReasonCron.php index 09bafee4743..05efda38011 100644 --- a/src/PendingReasonCron.php +++ b/src/PendingReasonCron.php @@ -90,9 +90,10 @@ public static function cronPendingreason_autobump_autosolve(CronTask $task) $now = date("Y-m-d H:i:s"); - $pending_items = new PendingReason_Item(); - $data = $pending_items->find([ - [ + $data = $DB->request([ + 'SELECT' => 'id', + 'FROM' => PendingReason_Item::getTable(), + 'WHERE' => [ 'pendingreasons_id' => ['>', 0], 'followup_frequency' => ['>', 0], 'itemtype' => $targets From e5f28c27c5df7908ec121e3d23460097715c2be9 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 10 Feb 2025 14:17:47 +0100 Subject: [PATCH 10/12] fix bug --- src/PendingReason_Item.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PendingReason_Item.php b/src/PendingReason_Item.php index 50b96a5b323..8e73645f7f0 100644 --- a/src/PendingReason_Item.php +++ b/src/PendingReason_Item.php @@ -96,7 +96,9 @@ public static function createForItem(CommonDBTM $item, array $fields): bool $fields['itemtype'] = $item::getType(); $fields['items_id'] = $item->getID(); - //$fields['last_bump_date'] = $_SESSION['glpi_currenttime']; + if (!isset($fields['last_bump_date'])) { + $fields['last_bump_date'] = $_SESSION['glpi_currenttime']; + } $success = $em->add($fields); if (!$success) { trigger_error("Failed to create PendingReason_Item", E_USER_WARNING); From 304b99b800b1563286e413bdf97500881e66e15a Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 11 Feb 2025 09:29:13 +0100 Subject: [PATCH 11/12] fix TU --- phpunit/functional/PendingReasonTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index 8b0cc347e5c..18356dcec8e 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -951,7 +951,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() ] ]; - // Case 3: follow up that will soon be bumped + // Case 3: follow up published one day ago yield [ 'timeline' => [ [ @@ -960,7 +960,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency . ' seconds', strtotime($currentDate))), + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . DAY_TIMESTAMP . ' seconds', strtotime($currentDate))), 'bump_count' => 0, ], ], @@ -969,7 +969,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency . ' seconds', strtotime($currentDate))), + 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . DAY_TIMESTAMP . ' seconds', strtotime($currentDate))), 'bump_count' => 0, ] ]; From 3045390c5f49d22b6602e9bf97d1be4fdbf31eb5 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 11 Feb 2025 12:10:12 +0100 Subject: [PATCH 12/12] update TU --- phpunit/functional/PendingReasonTest.php | 89 +++++++++++++----------- src/PendingReasonCron.php | 2 +- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/phpunit/functional/PendingReasonTest.php b/phpunit/functional/PendingReasonTest.php index 18356dcec8e..05e7001b787 100644 --- a/phpunit/functional/PendingReasonTest.php +++ b/phpunit/functional/PendingReasonTest.php @@ -466,9 +466,10 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable $this->login(); $entity = getItemByTypeName('Entity', '_test_root_entity', true); - $currentDate = date('Y-m-d H:i:s'); - $_SESSION['glpi_currenttime'] = $currentDate; + $current_date = '2025-01-31 12:00:00'; + $date2 = '2025-01-31 13:00:00'; + $_SESSION['glpi_currenttime'] = $current_date; // Create a set of pending reasons that will be reused in our test cases list( $pending_reason1, @@ -498,7 +499,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], ], 'expected' => [ @@ -508,7 +509,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the last followup 'pending_timeline_index' => 0, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ] ]; @@ -521,7 +522,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], [ 'type' => TicketTask::class, @@ -535,7 +536,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the last task 'pending_timeline_index' => 0, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ] ]; @@ -549,7 +550,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], [ 'type' => ITILFollowup::class, @@ -557,7 +558,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason2->getID(), 'followup_frequency' => 2 * DAY_TIMESTAMP, 'followups_before_resolution' => 1, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ], ], @@ -568,7 +569,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 1, // 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, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ] ]; @@ -604,7 +605,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], [ 'type' => TicketTask::class, @@ -616,7 +617,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason2->getID(), 'followup_frequency' => 0, 'followups_before_resolution' => 0, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ], ], 'expected' => [ @@ -626,7 +627,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 0, // Pending reason is attached to the third timeline item 'pending_timeline_index' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ] ]; @@ -641,7 +642,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], [ 'type' => ITILFollowup::class, @@ -649,7 +650,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ], ], 'expected' => [ @@ -659,7 +660,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the first timeline item 'pending_timeline_index' => 0, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ] ]; @@ -673,12 +674,12 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], [ 'type' => TicketTask::class, 'pending' => 1, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ], ], 'expected' => [ @@ -688,7 +689,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the last followup 'pending_timeline_index' => 0, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ] ]; @@ -700,7 +701,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'type' => ITILFollowup::class, 'pending' => 1, 'pendingreasons_id' => 0, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], [ 'type' => ITILFollowup::class, @@ -708,7 +709,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ], ], 'expected' => [ @@ -718,7 +719,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 2, // Pending reason is attached to the last timeline item 'pending_timeline_index' => 1, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ] ]; @@ -732,7 +733,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], [ 'type' => ITILFollowup::class, @@ -740,7 +741,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => 0, 'followup_frequency' => 0, 'followups_before_resolution' => 0, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ], ], 'expected' => [ @@ -750,7 +751,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 0, // Pending reason is attached to the last timeline item 'pending_timeline_index' => 1, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ] ]; @@ -764,7 +765,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => 3 * DAY_TIMESTAMP, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, ], [ 'type' => ITILFollowup::class, @@ -772,7 +773,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'pendingreasons_id' => $pending_reason2->getID(), 'followup_frequency' => 2 * DAY_TIMESTAMP, 'followups_before_resolution' => 1, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ], ], 'expected' => [ @@ -782,7 +783,7 @@ protected function testUpdatesFromNewTimelineItemProvider(): iterable 'followups_before_resolution' => 1, // Pending reason is attached to the last timeline item 'pending_timeline_index' => 1, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('+30 seconds', strtotime($currentDate))), + 'last_bump_date' => $date2, ] ]; } @@ -882,9 +883,13 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() $entity = getItemByTypeName('Entity', '_test_root_entity', true); - $currentDate = date('Y-m-d H:i:s'); $followup_frequency = 3 * DAY_TIMESTAMP; - $_SESSION['glpi_currenttime'] = $currentDate; + + $current_date = '2025-01-31 12:00:00'; + $date_before_bump = '2025-01-28 12:00:00'; + $date_to_bump = '2025-01-28 11:59:59'; + + $_SESSION['glpi_currenttime'] = $current_date; $itilfollowuptemplate = $this->createItem(ITILFollowupTemplate::class, [ 'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true), @@ -914,7 +919,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, 'bump_count' => 0, ], ], @@ -923,7 +928,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, 'bump_count' => 0, ] ]; @@ -937,7 +942,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-30 seconds', strtotime($currentDate))), + 'last_bump_date' => $current_date, 'bump_count' => 0, ], ], @@ -946,12 +951,12 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-30 seconds', strtotime($currentDate))), + 'last_bump_date' => $current_date, 'bump_count' => 0, ] ]; - // Case 3: follow up published one day ago + // Case 3: follow up published just before the bump date yield [ 'timeline' => [ [ @@ -960,7 +965,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . DAY_TIMESTAMP . ' seconds', strtotime($currentDate))), + 'last_bump_date' => $date_before_bump, 'bump_count' => 0, ], ], @@ -969,7 +974,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . DAY_TIMESTAMP . ' seconds', strtotime($currentDate))), + 'last_bump_date' => $date_before_bump, 'bump_count' => 0, ] ]; @@ -983,7 +988,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency + 1 . ' seconds', strtotime($currentDate))), + 'last_bump_date' => $date_to_bump, 'bump_count' => 0, ], ], @@ -992,7 +997,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, 'bump_count' => 1, ] ]; @@ -1006,7 +1011,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency + 1 . ' seconds', strtotime($currentDate))), + 'last_bump_date' => $date_to_bump, 'bump_count' => 1, ], ], @@ -1015,7 +1020,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, 'bump_count' => 2, ] ]; @@ -1029,7 +1034,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => $pending_reason1->getID(), 'followup_frequency' => $followup_frequency, 'followups_before_resolution' => 2, - 'last_bump_date' => date('Y-m-d H:i:s', strtotime('-' . $followup_frequency + 1 . ' seconds', strtotime($currentDate))), + 'last_bump_date' => $date_to_bump, 'bump_count' => 2, ], ], @@ -1038,7 +1043,7 @@ protected function testCronPendingReasonAutobumpAutosolveProvider() 'pendingreasons_id' => 0, 'followup_frequency' => 0, 'followups_before_resolution' => 0, - 'last_bump_date' => $currentDate, + 'last_bump_date' => $current_date, 'bump_count' => 3, ] ]; diff --git a/src/PendingReasonCron.php b/src/PendingReasonCron.php index 05efda38011..92ad8f40624 100644 --- a/src/PendingReasonCron.php +++ b/src/PendingReasonCron.php @@ -88,7 +88,7 @@ public static function cronPendingreason_autobump_autosolve(CronTask $task) Problem::getType(), ]; - $now = date("Y-m-d H:i:s"); + $now = $_SESSION['glpi_currenttime']; $data = $DB->request([ 'SELECT' => 'id',