Skip to content

Commit a494309

Browse files
committed
fix(Impact\Embodied\Boavizta): service version not saved in DB
1 parent c3c38e9 commit a494309

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

setup.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
*/
3232

3333
use Config as GlpiConfig;
34-
use CommonDBTM;
3534
use GlpiPlugin\Carbon\Dashboard\Widget;
3635
use Glpi\Plugin\Hooks;
3736
use GlpiPlugin\Carbon\Config;

src/Impact/Embodied/AbstractEmbodiedImpact.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function __construct()
6969
}
7070
}
7171

72+
abstract protected function getVersion(): string;
73+
7274
/**
7375
* Get the unit of an impact
7476
*
@@ -200,7 +202,7 @@ public function evaluateItem(int $id): bool
200202
$impact_types = Type::getImpactTypes();
201203

202204
$input['engine'] = $this->engine;
203-
$input['engine_version'] = $this->engine_version;
205+
$input['engine_version'] = $this->getVersion();
204206

205207
// Prepare inputs for add or update
206208
foreach ($impacts as $type => $value) {
@@ -245,7 +247,10 @@ public function getEvaluableQuery(array $crit = [], bool $entity_restrict = true
245247
// }
246248

247249
$crit[] = [
248-
$item_type_table . '.is_ignore' => false,
250+
'OR' => [
251+
$item_type_table . '.is_ignore' => 0,
252+
$item_type_table . '.id' => null,
253+
]
249254
];
250255

251256
$request = [

src/Impact/Embodied/Boavizta/AbstractAsset.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ public function setClient(Boaviztapi $client)
8080

8181
protected function getVersion(): string
8282
{
83+
if ($this->engine_version !== 'unknown') {
84+
return $this->engine_version;
85+
}
86+
8387
try {
8488
$response = $this->client->get('utils/version');
8589
} catch (\RuntimeException $e) {
@@ -93,8 +97,8 @@ protected function getVersion(): string
9397
), E_USER_WARNING);
9498
throw new \RuntimeException('Invalid response from Boavizta API');
9599
}
96-
97-
return $response[0];
100+
$this->engine_version = $response[0];
101+
return $this->engine_version;
98102
}
99103

100104
protected function query($description): array

src/Impact/Embodied/Internal/AbstractAsset.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ abstract class AbstractAsset extends AbstractEmbodiedImpact
4141

4242
/** @var string $engine_version Version of the calculation engine */
4343
protected string $engine_version = '1';
44+
45+
protected function getVersion(): string
46+
{
47+
return $this->engine_version;
48+
}
4449
}

tests/units/CronTaskTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ public function testFillIncompleteLocations()
100100
{
101101
$cron_task = new CronTask();
102102
$glpi_cron_task = new GlpiCronTask();
103-
$glpi_cron_task->getFromDBByCrit([
104-
'itemtype' => get_class($cron_task),
105-
'name' => 'LocationCountryCode',
103+
$glpi_cron_task = $this->getItem(GlpiCronTask::class, [
104+
'WHERE' => [
105+
'itemtype' => CronTask::class,
106+
'name' => 'LocationCountryCode',
107+
]
106108
]);
107109

108110
// Mock the getGeocoder method to return a callable that simulates geocoding
109-
$geocoder_collection = new AddressCollection([
111+
$address_collection = new AddressCollection([
110112
new NominatimAddress(
111113
'',
112114
new AdminLevelCollection([
@@ -127,7 +129,7 @@ public function testFillIncompleteLocations()
127129
),
128130
]);
129131
$geocoder = $this->createStub(Geocoder::class);
130-
$geocoder->method('geocodeQuery')->willReturn($geocoder_collection);
132+
$geocoder->method('geocodeQuery')->willReturn($address_collection);
131133
$cron_task->setGeocoder(function () use ($geocoder) {
132134
return $geocoder;
133135
});

0 commit comments

Comments
 (0)