Skip to content

Commit 6a2478a

Browse files
committed
Postrebase fixes
SLMTest::testOlaBeginDate() moved to OLATest::testInitialOlaTtoValuesOnUpdate() & OLATest::testInitialOlaTtoValuesOnCreation() - missed SLMField::getSLMClass() replaced by getSLM() - clean SQLProvider - csfix − new static::$levelclass() replaced by getItemForItemtype(static::$levelclass) (same for $levelticketclass)
1 parent 99f6331 commit 6a2478a

9 files changed

Lines changed: 20 additions & 71 deletions

File tree

phpunit/functional/OLATest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public function testOlaAssociationCanBeDoneWhenNoGroupIsAssociatedToOla(): void
439439
}
440440

441441
/**
442-
* - start_time is set using ticket 'date' field (which is the current time when not specified))
442+
* - start_time is set using ticket 'date' field (which is the current time when not specified)
443443
* - due_time is set at the moment the Ola is assigned to the ticket
444444
* - endtime is set not set
445445
* - waiting_time is not set

phpunit/functional/SLMTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,6 @@ public function testOlaTtrComputation()
615615
$ticket = $this->updateItem(Ticket::class, $ticket->getID(), ['_la_update' => true, '_olas_id' => [(int) $ola_id]]);
616616
$_SESSION['glpi_currenttime'] = $currenttime_bak;
617617
$this->assertTrue($ticket->getFromDB($ticket_id));
618-
$this->assertEquals($ola_id, (int) $ticket->fields['olas_id_ttr']);
619-
$this->assertEquals($update_time, strtotime($ticket->fields['ola_ttr_begin_date']), 'OLA begin date should be time of assignment of OLA to the ticket');
620-
$this->assertEquals($tomorrow_1pm, $ticket->fields['internal_time_to_resolve']);
621618

622619
$ola_ttr = $ticket->getOlasTTRData()[0];
623620
$this->assertEquals($ola_id, (int) $ola_ttr['olas_id']);
@@ -2333,48 +2330,6 @@ public function testEscalationLevelsChangesWithMultiplesOlas(): void
23332330
// - when ticket status is CLOSED or CLOSED
23342331
// - when levelAgreement is an TTO and takeintoaccount_delay_stat is > 0
23352332

2336-
/**
2337-
* Ola begin date values business logic test
2338-
*
2339-
* ola begin date fields (ola_tto_begin_date, ola_ttr_begin_date) logic is as follows:
2340-
* - ola is set on ticket creation : ola begin date is set ticket.date field
2341-
* - ola is set on ticket update : ola begin date is set to the current time
2342-
*/
2343-
public function testOlaBeginDate(): void
2344-
{
2345-
$this->login();
2346-
2347-
// on creation, the OLA begin date is set to the ticket date
2348-
$provided_date = '2025-05-26 10:00:00';
2349-
foreach ([\SLM::TTR, \SLM::TTO] as $type) {
2350-
['ola' => $ola] = $this->createOLA(ola_type: $type);
2351-
[$olas_id_fk, $olas_begin_field] = match ($type) {
2352-
\SLM::TTO => ['olas_id_tto', 'ola_tto_begin_date'],
2353-
\SLM::TTR => ['olas_id_ttr', 'ola_ttr_begin_date'],
2354-
};
2355-
// create ticket with OLA set on creation + provided date
2356-
$ticket = $this->createTicket(['date' => $provided_date, $olas_id_fk => $ola->getID()]);
2357-
2358-
$this->assertEquals($provided_date, $ticket->fields[$olas_begin_field]);
2359-
}
2360-
2361-
// on update, the OLA begin date is set to the current time
2362-
$now = $this->setCurrentTime('09:00:00', '2022-05-26');
2363-
$provided_date = '2022-05-01 10:00:00';
2364-
foreach ([\SLM::TTR, \SLM::TTO] as $type) {
2365-
['ola' => $ola] = $this->createOLA(ola_type: $type);
2366-
[$olas_id_fk, $olas_begin_field] = match ($type) {
2367-
\SLM::TTO => ['olas_id_tto', 'ola_tto_begin_date'],
2368-
\SLM::TTR => ['olas_id_ttr', 'ola_ttr_begin_date'],
2369-
};
2370-
// create ticket with OLA set on creation + provided date
2371-
$ticket = $this->createTicket(['date' => $provided_date]);
2372-
$ticket = $this->updateItem($ticket::class, $ticket->getID(), [$olas_id_fk => $ola->getID(),]);
2373-
2374-
$this->assertEquals($now->format('Y-m-d H:i:s'), $ticket->fields[$olas_begin_field]);
2375-
}
2376-
}
2377-
23782333
/**
23792334
* Check recalculating the SLA when the SLA is changed to an SLA with a different calendar
23802335
*

src/Glpi/Form/Destination/CommonITILField/OLAField.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ public function applyConfiguratedValueToInputUsingAnswers(
2424
$slm_id = $strategy->getSLMID($config);
2525

2626
// Do not edit input if invalid value was found
27-
/** @var class-string<\OLA> $slm_class */
28-
$slm_class = $this->getSLMClass();
29-
if (!$slm_class::getById($slm_id)) {
27+
$slm = $this->getSLM();
28+
if (!$slm::getById($slm_id)) {
3029
return $input;
3130
}
3231

src/Glpi/Form/Destination/CommonITILField/OLATTOField.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
namespace Glpi\Form\Destination\CommonITILField;
3737

3838
use LevelAgreement;
39-
use Glpi\DBAL\JsonFieldInterface;
40-
use Glpi\Form\AnswersSet;
4139
use OLA;
4240
use Override;
4341
use SLM;

src/Glpi/Form/Destination/CommonITILField/SLAField.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ public function applyConfiguratedValueToInputUsingAnswers(
2424
$slm_id = $strategy->getSLMID($config);
2525

2626
// Do not edit input if invalid value was found
27-
/** @var class-string<\SLA> $slm_class */
28-
$slm_class = $this->getSLMClass();
29-
if (!$slm_class::getById($slm_id)) {
27+
$slm = $this->getSLM();
28+
if (!$slm::getById($slm_id)) {
3029
return $input;
3130
}
3231

33-
$input[$slm_class::getFieldNames($this->getType())[1]] = $slm_id;
32+
$input[$slm::getFieldNames($this->getType())[1]] = $slm_id;
3433

3534
return $input;
3635
}

src/Glpi/Search/Provider/SQLProvider.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5568,10 +5568,7 @@ public static function giveItem(
55685568
$data[$ID][0]['status'] == CommonITILObject::WAITING
55695569
) {
55705570
// No due date in waiting status for TTRs
5571-
if (
5572-
$table . '.' . $field == "glpi_tickets.time_to_resolve"
5573-
|| $table . '.' . $field == "glpi_tickets.internal_time_to_resolve"
5574-
) {
5571+
if ($table . '.' . $field == "glpi_tickets.time_to_resolve") {
55755572
return '';
55765573
} else {
55775574
$color = '#AAAAAA';
@@ -5721,7 +5718,7 @@ public static function giveItem(
57215718
}
57225719
break;
57235720

5724-
// OLA TTO / OLA TTR
5721+
// OLA TTO / OLA TTR
57255722
case "glpi_items_olas.due_time":
57265723
$out = '';
57275724
// Due date + progress

src/LevelAgreement.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,12 @@ public function showForm($ID, array $options = [])
216216
'display_emptychoice' => false,
217217
'condition' => ['is_assign' => 1],
218218
// @todoseb rendre le choix obligatoire, pas réussi
219-
// 'specific_tags' => [
220-
// 'required' => 'required',
221-
// ],
222-
// 'required' => true,
223-
]);
219+
// 'specific_tags' => [
220+
// 'required' => 'required',
221+
// ],
222+
// 'required' => true,
223+
]
224+
);
224225
echo "</td>";
225226
echo "</tr>";
226227
}

src/OLA.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function cleanDBonPurge()
7373

7474
// Clean levels
7575
$ola_fk = getForeignKeyFieldForItemType(static::class);
76-
$level = new static::$levelclass();
76+
$level = getItemForItemtype(static::$levelclass);
7777
$level->deleteByCriteria([$ola_fk => $this->getID()]);
7878

7979
// Clean levels todo
@@ -144,7 +144,7 @@ public function addLevelToDo(Ticket $ticket, $levels_id, $olas_id)
144144
$toadd['date'] = $date;
145145
$toadd[$pre . 'levels_id'] = $levels_id;
146146
$toadd['tickets_id'] = $ticket->fields["id"];
147-
$levelticket = new static::$levelticketclass();
147+
$levelticket = getItemForItemtype(static::$levelticketclass);
148148
$levelticket->add($toadd);
149149
}
150150
}
@@ -165,7 +165,7 @@ public static function deleteLevelsToDo(Ticket $ticket)
165165
// but the function is likely always called if the ticket has an OLA TTR
166166
// so it's performed all the time
167167
// on this version I remove the check, all levels todo are deleted, whatever OLA type is.
168-
$levelticket = new static::$levelticketclass();
168+
$levelticket = getItemForItemtype(static::$levelticketclass);
169169
$iterator = $DB->request([
170170
'SELECT' => 'id',
171171
'FROM' => $levelticket::getTable(),

src/SLA.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function addLevelToDo(Ticket $ticket, $levels_id = 0)
7575
$toadd['date'] = $date;
7676
$toadd[$pre . 'levels_id'] = $levels_id;
7777
$toadd['tickets_id'] = $ticket->fields["id"];
78-
$levelticket = new static::$levelticketclass();
78+
$levelticket = getItemForItemtype(static::$levelticketclass);
7979
$levelticket->add($toadd);
8080
}
8181
}
@@ -96,7 +96,7 @@ public static function deleteLevelsToDo(Ticket $ticket)
9696
$ticketfield = static::$prefix . "levels_id_ttr";
9797

9898
if ($ticket->fields[$ticketfield] > 0) {
99-
$levelticket = new static::$levelticketclass();
99+
$levelticket = getItemForItemtype(static::$levelticketclass);
100100
$iterator = $DB->request([
101101
'SELECT' => 'id',
102102
'FROM' => $levelticket::getTable(),
@@ -137,7 +137,7 @@ public function cleanDBonPurge()
137137

138138
// Clean levels
139139
$fk = getForeignKeyFieldForItemType(static::class);
140-
$level = new static::$levelclass();
140+
$level = getItemForItemtype(static::$levelclass);
141141
$level->deleteByCriteria([$fk => $this->getID()]);
142142

143143
// Update tickets : clean SLA

0 commit comments

Comments
 (0)