Skip to content

Commit 144a930

Browse files
committed
ola tto & ttr completed when ola group removed from assignees.
1 parent 4e4f412 commit 144a930

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

phpunit/functional/OLATest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
* - is not done when a user not in the dedicated group is assigned to the ticket : @see self::testOlaTtoIsNotCompleteWhenTicketIsAssignedToUserNotInDedicatedGroup()
9696
* - is not done when the group is added and the ola added by rule : @see self::testOlaTtoIsNotCompleteWhenTicketIsAssignedToDedicatedGroupAndOlaAddedByRule()
9797
* - is done when a group associated to ola is removed from ticket assigned group : @see self::testOlaTtoIsCompleteWhenGroupAssociatedToOlaIsRemovedFromTicketAssignedGroup()
98+
* - @todo same for user of group
9899
* - is done when ticket is "taken into account" (add task, add followup) by a user of the ola group : @todoseb - d'abord vérifier à quoi correspond taken_into_account(_delay)
99100
* - is not done when ticket is updated(add task, add followup) by a user not in the ola group : @todoseb - d'abord vérifier à quoi correspond taken_into_account(_delay)
100101
* @todoseb voir quels tests sont à répliquer pour les TTR
@@ -741,12 +742,12 @@ public function testOlaTtoIsCompleteWhenGroupAssociatedToOlaIsRemovedFromTicketA
741742
// act : remove group associated to OLA TTO from ticket assigned groups, maybe there is a cleaner way to do this
742743
$gt = new \Group_Ticket();
743744
assert(true === $gt->deleteByCriteria(['tickets_id' => $ticket->getID(), 'groups_id' => $g_n1->getID()]));
744-
throw new \Exception('mise à jour des olas pas lancée dans le deleteByCriteria, hors on a besoin de mettre à jour item_olas ');
745745

746746
$ticket = $this->reloadItem($ticket);
747747
assert(false === $ticket->isGroup(CommonITILActor::ASSIGN, $g_n1->getID()), 'Group N1 should not be assigned to ticket anymore');
748748

749749
// assert OLA TTO is now complete
750+
$fetched_ola_data = $ticket->getOlasTTOData()[0] ?? throw new \Exception('Tested OLA TTO not fetched');
750751
$this->assertNotNull($fetched_ola_data['end_time']);
751752
}
752753

src/Group_Ticket.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,12 @@ public function post_addItem()
6666
parent::post_addItem();
6767
$this->_force_log_option = 0;
6868
}
69+
70+
71+
public function post_purgeItem()
72+
{
73+
Item_Ola::computeGroupAssigneeRemoval((int) $this->fields['tickets_id'], (int) $this->fields['groups_id']);
74+
75+
parent::post_purgeItem();
76+
}
6977
}

src/Item_Ola.php

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ public static function compute(Ticket $ticket, mixed $olas_id): void
168168
// - except if update is triggered by a rule
169169
// - except if end_time is already set
170170
// @todoseb refacto en mettant end_time, sur l'ensemble.
171-
// @todoseb traitement de la suppression du groupe de l'OLA (à été présent, ne l'ai plus -> ola tto terminée (idem ttr probablement))
172-
$ola_group_removed = $ticket->haveAGroup(CommonITILActor::ASSIGN, [$ola->fields['groups_id']]);
173171

174172
if ($item_ola_data['ola_type'] === SLM::TTO) {
175173
if (
@@ -209,6 +207,60 @@ public static function compute(Ticket $ticket, mixed $olas_id): void
209207
$ticket->manageOlaLevel($item_ola->fields['olas_id']);
210208
}
211209

210+
/**
211+
* When the ola dedicated group is removed from a ticket, the ola is considered completed.
212+
*
213+
* The $groups_id_removed is the group id that has been removed from the ticket assignees.
214+
* Be sure that the group was previously assigned to the ticket.
215+
*/
216+
public static function computeGroupAssigneeRemoval(int $tickets_id, int $groups_id_removed)
217+
{
218+
/** @var DBmysql $DB */
219+
global $DB;
220+
221+
// find all items_olas OLA related to this group & ticket
222+
$items_olas_to_update_results = $DB->request([
223+
'SELECT' => [
224+
Item_Ola::getTable() . '.id',
225+
Item_Ola::getTable() . '.olas_id',
226+
],
227+
'FROM' => Item_Ola::getTable(),
228+
'INNER JOIN' => [
229+
OLA::getTable() => [
230+
'FKEY' => [
231+
Item_Ola::getTable() => 'olas_id',
232+
OLA::getTable() => 'id',
233+
],
234+
],
235+
],
236+
'WHERE' => [
237+
'items_id' => $tickets_id,
238+
'itemtype' => Ticket::class,
239+
'groups_id' => $groups_id_removed,
240+
],
241+
]);
242+
243+
foreach ($items_olas_to_update_results as $item_ola_row) {
244+
$ticket = new Ticket();
245+
if (!$ticket->getFromDB($tickets_id)) {
246+
throw new Exception('Ticket related to Ticket_group not found');
247+
}
248+
249+
if (!(new self())->update(
250+
[
251+
'end_time' => Session::getCurrentTime(),
252+
'id' => $item_ola_row['id'],
253+
]
254+
)
255+
) {
256+
throw new Exception('Failed to update end_time on Item_Ola #' . $item_ola_row['id']);
257+
}
258+
259+
Item_Ola::compute($ticket, (int) $item_ola_row['olas_id']);
260+
}
261+
}
262+
263+
212264
public function getOla(): OLA
213265
{
214266
$item = $this->getConnexityItem(self::$itemtype_2, self::$items_id_2);

0 commit comments

Comments
 (0)