Jacek Kowalski
2019-06-21 ea2e9b41b3b1eace8e99d6e2672ffffb07665e04
commit | author | age
ea2e9b 1 <?php
JK 2 require_once(__DIR__.'/vendor/autoload.php');
3 require_once(__DIR__.'/lib/database.php');
4 require_once(__DIR__.'/lib/vehicle_types.php');
5 require_once(__DIR__.'/config.php');
6
7 foreach($sources as $name => $source) {
8     $logger = new Monolog\Logger('regenerate_'.$name);
9     try {
10         $logger->info('Regenerating '.$name.'...');
11         
12         $db = new Database($source['database']);
13         
14         $jsonContent = [];
15         foreach($db->getAll() as $vehicle) {
16             $jsonContent[$vehicle['id']] = $source['mapper']($vehicle['num']);
17         }
18         
19         $json = json_encode($jsonContent);
20         if(!file_put_contents($source['result_temp'], $json)) {
21             throw new Exception('Result save failed');
22         }
23         rename($source['result_temp'], $source['result']);
24         $logger->info('Finished');
25     } catch(Throwable $e) {
26         $logger->error($e->getMessage(), ['exception' => $e, 'exception_string' => (string)$e]);
27     }
28 }