|
104 | 104 | Install::linkSourceZone($source_id, $zone_id, $code); |
105 | 105 |
|
106 | 106 | // 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) { |
117 | 117 | $file = null; // close the file |
118 | 118 | throw new \RuntimeException("Failed to insert data for year $year"); |
119 | 119 | } |
|
129 | 129 |
|
130 | 130 | $quebec_carbon_intensity = include(dirname(__DIR__) . '/data/carbon_intensity/quebec.php'); |
131 | 131 | 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) { |
142 | 142 | $file = null; // close the file |
143 | 143 | throw new \RuntimeException("Failed to insert data for year $year"); |
144 | 144 | } |
|
0 commit comments