Skip to content

Commit af9e69a

Browse files
committed
fix: resolve conflicts
1 parent cce57f5 commit af9e69a

8 files changed

Lines changed: 112 additions & 38 deletions

File tree

install/install/init_datasources.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@
104104
Install::linkSourceZone($source_id, $zone_id, $code);
105105

106106
// Insert into the database
107-
$success = $DB->updateOrInsert($table, [
108-
'intensity' => $intensity,
109-
'data_quality' => 2 // constant GlpiPlugin\Carbon\DataTracking::DATA_QUALITY_ESTIMATED
110-
], [
111-
'date' => "$year-01-01 00:00:00",
112-
'plugin_carbon_sources_id' => $source_id,
113-
'plugin_carbon_zones_id' => $zone_id,
114-
]);
115-
116-
if ($success === false) {
107+
try {
108+
$DB->updateOrInsert($table, [
109+
'intensity' => $intensity,
110+
'data_quality' => 2 // constant GlpiPlugin\Carbon\DataTracking::DATA_QUALITY_ESTIMATED
111+
], [
112+
'date' => "$year-01-01 00:00:00",
113+
'plugin_carbon_sources_id' => $source_id,
114+
'plugin_carbon_zones_id' => $zone_id,
115+
]);
116+
} catch (\RuntimeException $e) {
117117
$file = null; // close the file
118118
throw new \RuntimeException("Failed to insert data for year $year");
119119
}
@@ -129,16 +129,16 @@
129129

130130
$quebec_carbon_intensity = include(dirname(__DIR__) . '/data/carbon_intensity/quebec.php');
131131
foreach ($quebec_carbon_intensity as $year => $intensity) {
132-
$success = $DB->updateOrInsert($table, [
133-
'intensity' => $intensity,
134-
'data_quality' => 2 // constant GlpiPlugin\Carbon\DataTracking::DATA_QUALITY_ESTIMATED
135-
], [
136-
'date' => "$year-01-01 00:00:00",
137-
'plugin_carbon_sources_id' => $source_id,
138-
'plugin_carbon_zones_id' => $zone_id_quebec,
139-
]);
140-
141-
if ($success === false) {
132+
try {
133+
$DB->updateOrInsert($table, [
134+
'intensity' => $intensity,
135+
'data_quality' => 2 // constant GlpiPlugin\Carbon\DataTracking::DATA_QUALITY_ESTIMATED
136+
], [
137+
'date' => "$year-01-01 00:00:00",
138+
'plugin_carbon_sources_id' => $source_id,
139+
'plugin_carbon_zones_id' => $zone_id_quebec,
140+
]);
141+
} catch (\RuntimeException $e) {
142142
$file = null; // close the file
143143
throw new \RuntimeException("Failed to insert data for year $year");
144144
}

install/migration/update_1.0.0_to_1.0.1.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ function update100to101(Migration $migration)
5757
}
5858

5959
$dbFile = plugin_carbon_getSchemaPath($to_version);
60-
if ($dbFile === null || !$DB->runFile($dbFile)) {
60+
if ($dbFile === null) {
6161
$migration->addWarningMessage("Error creating tables : " . $DB->error());
6262
$updateresult = false;
6363
}
64+
try {
65+
$DB->runFile($dbFile);
66+
} catch (\RuntimeException $e) {
67+
$migration->addWarningMessage("Error creating tables : " . $e->getMessage());
68+
$updateresult = false;
69+
}
6470

6571
// ************ Keep it at the end **************
6672
$migration->executeMigration();

install/migration/update_1.0.1_to_1.1.0.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ function update101to110(Migration $migration)
5757
}
5858

5959
$dbFile = plugin_carbon_getSchemaPath($to_version);
60-
if ($dbFile === null || !$DB->runFile($dbFile)) {
60+
if ($dbFile === null) {
6161
$migration->addWarningMessage("Error creating tables : " . $DB->error());
6262
$updateresult = false;
6363
}
64+
try {
65+
$DB->runFile($dbFile);
66+
} catch (\RuntimeException $e) {
67+
$migration->addWarningMessage("Error creating tables : " . $e->getMessage());
68+
$updateresult = false;
69+
}
70+
6471

6572
// ************ Keep it at the end **************
6673
$migration->executeMigration();

install/migration/update_1.1.1_to_1.2.0.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ function update111to120(Migration $migration)
5757
}
5858

5959
$dbFile = plugin_carbon_getSchemaPath($to_version);
60-
if ($dbFile === null || !$DB->runFile($dbFile)) {
60+
if ($dbFile === null) {
6161
$migration->addWarningMessage("Error creating tables : " . $DB->error());
6262
$updateresult = false;
6363
}
64+
try {
65+
$DB->runFile($dbFile);
66+
} catch (\RuntimeException $e) {
67+
$migration->addWarningMessage("Error creating tables : " . $e->getMessage());
68+
$updateresult = false;
69+
}
70+
6471

6572
// ************ Keep it at the end **************
6673
$migration->executeMigration();

install/migration/update_x.x.x_to_y.y.y.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ function update001to100(Migration $migration)
5757
}
5858

5959
$dbFile = plugin_carbon_getSchemaPath($to_version);
60-
if ($dbFile === null || !$DB->runFile($dbFile)) {
60+
if ($dbFile === null) {
6161
$migration->addWarningMessage("Error creating tables : " . $DB->error());
6262
$updateresult = false;
6363
}
64+
try {
65+
$DB->runFile($dbFile);
66+
} catch (\RuntimeException $e) {
67+
$migration->addWarningMessage("Error creating tables : " . $e->getMessage());
68+
$updateresult = false;
69+
}
70+
6471

6572
// ************ Keep it at the end **************
6673
$migration->executeMigration();

src/Dashboard/Grid.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,21 @@ protected static function getReportCards(): array
314314

315315
return $new_cards;
316316
}
317+
<<<<<<< HEAD
318+
=======
319+
320+
private static function getWidgetForImpact(bool $embodied, string $type): string
321+
{
322+
switch (($embodied ? 'embodied' : 'usage') . ' ' . $type) {
323+
case 'embodied gwp':
324+
return 'embodied_global_warming';
325+
case 'embodied adp':
326+
return 'embodied_abiotic_depletion';
327+
case 'embodied pe':
328+
return 'embodied_primary_energy';
329+
}
330+
331+
return '';
332+
}
333+
>>>>>>> c2a7925 (fix(Install): follow stricter lint checks)
317334
}

src/Impact/Embodied/Engine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
use CommonGLPI;
3636
use CommonDBTM;
37+
use DBmysql;
3738
use GlpiPlugin\Carbon\AbstractModel;
3839
use GlpiPlugin\Carbon\Config;
3940
use GlpiPlugin\Carbon\DataSource\Lca\Boaviztapi\Client;

src/Toolbox.php

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,6 @@ public static function getWeight(float $weight): string
227227
return sprintf(__('%1$s&nbsp;%2$s'), $weight, $human_readable_unit);
228228
}
229229

230-
public static function dynamicRound(float $number): float
231-
{
232-
if ($number < 10) {
233-
$number = round($number, 2);
234-
} else if ($number < 100) {
235-
$number = round($number, 1);
236-
} else {
237-
$number = round($number, 0);
238-
}
239-
240-
return $number;
241-
}
242-
243230
/**
244231
* Format a power passing a power in grams
245232
*
@@ -307,7 +294,49 @@ public static function getEnergy(float $p): string
307294
$p = self::dynamicRound($p);
308295

309296
//TRANS: %1$s is a number maybe float or string and %2$s the unit
310-
return sprintf(__('%1$s&nbsp;%2$s'), $p, $human_readable_unit);
297+
return sprintf(__('%1$s %2$s'), $p, $human_readable_unit);
298+
}
299+
300+
public static function dynamicRound(float $number): float
301+
{
302+
if ($number < 10) {
303+
$number = round($number, 2);
304+
} else if ($number < 100) {
305+
$number = round($number, 1);
306+
} else {
307+
$number = round($number, 0);
308+
}
309+
310+
return $number;
311+
}
312+
313+
/**
314+
* Convert a value and its unit into a human readable value
315+
*
316+
* Unit is an array i.e. ['g', 'CO2 eq'] for grams of carbondioxyde equivalent
317+
*
318+
* @param float $value value of the quantity to convert
319+
* @param array $unit unit splitted into a standard unit and a qualification.
320+
* @return string
321+
*/
322+
public static function getHumanReadableValue(float $value, array $unit): string
323+
{
324+
switch ($unit[0]) {
325+
case 'g':
326+
return self::getWeight($value) . $unit[1];
327+
case 'J':
328+
// To be converted into watt.hour
329+
return self::getEnergy($value / 3600) . $unit[1];
330+
case 'Wh':
331+
return self::getEnergy($value) . $unit[1];
332+
case '':
333+
// Value is in m^3
334+
return sprintf(__('%1$s %2$s', 'carbon'), $value * 1000, 'L');
335+
case 'mol':
336+
break;
337+
}
338+
339+
return sprintf(__('%1$s %2$s', 'carbon'), $value, implode(' ', $unit));
311340
}
312341

313342
/**

0 commit comments

Comments
 (0)