@@ -9,7 +9,9 @@ discard block |
||
| 9 | 9 | if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { |
| 10 | 10 | exec("ps ux", $output, $result); |
| 11 | 11 | $j = 0; |
| 12 | - foreach ($output as $line) if(strpos($line, "update_db.php") && !strpos($line, "sh ")) $j++; |
|
| 12 | + foreach ($output as $line) { |
|
| 13 | + if(strpos($line, "update_db.php") && !strpos($line, "sh ")) $j++; |
|
| 14 | + } |
|
| 13 | 15 | if ($j > 1) { |
| 14 | 16 | echo "Script is already runnning..."; |
| 15 | 17 | die(); |
@@ -29,14 +31,18 @@ discard block |
||
| 29 | 31 | $update_db->update_notam(); |
| 30 | 32 | } |
| 31 | 33 | $update_db->insert_last_notam_update(); |
| 32 | - } elseif (isset($globalDebug) && $globalDebug && isset($globalNOTAM) && $globalNOTAM) echo "NOTAM are only updated once a day.\n"; |
|
| 34 | + } elseif (isset($globalDebug) && $globalDebug && isset($globalNOTAM) && $globalNOTAM) { |
|
| 35 | + echo "NOTAM are only updated once a day.\n"; |
|
| 36 | + } |
|
| 33 | 37 | if ($update_db->check_last_update() && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) { |
| 34 | 38 | $update_db->update_all(); |
| 35 | 39 | // require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
| 36 | 40 | // $Spotter = new Spotter(); |
| 37 | 41 | // $Spotter->updateFieldsFromOtherTables(); |
| 38 | 42 | $update_db->insert_last_update(); |
| 39 | - } elseif (isset($globalDebug) && $globalDebug && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM)) echo "DB are populated with external data only every 15 days ! Files are not updated more often.\n"; |
|
| 43 | + } elseif (isset($globalDebug) && $globalDebug && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM)) { |
|
| 44 | + echo "DB are populated with external data only every 15 days ! Files are not updated more often.\n"; |
|
| 45 | + } |
|
| 40 | 46 | if (isset($globalWaypoints) && $globalWaypoints && $update_db->check_last_airspace_update()) { |
| 41 | 47 | echo "Check if new airspace version exist..."; |
| 42 | 48 | echo $update_db->update_airspace_fam(); |
@@ -51,7 +57,9 @@ discard block |
||
| 51 | 57 | $update_db->delete_duplicateowner(); |
| 52 | 58 | } |
| 53 | 59 | $update_db->insert_last_owner_update(); |
| 54 | - } elseif (isset($globalDebug) && $globalDebug && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) echo "Owner are only updated every 15 days.\n"; |
|
| 60 | + } elseif (isset($globalDebug) && $globalDebug && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) { |
|
| 61 | + echo "Owner are only updated every 15 days.\n"; |
|
| 62 | + } |
|
| 55 | 63 | |
| 56 | 64 | if (isset($globalAccidents) && $globalAccidents && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) { |
| 57 | 65 | require_once(dirname(__FILE__).'/../require/class.Accident.php'); |
@@ -60,7 +68,9 @@ discard block |
||
| 60 | 68 | if ($Accident->check_last_accidents_update()) { |
| 61 | 69 | $Accident->download_update(); |
| 62 | 70 | $Accident->insert_last_accidents_update(); |
| 63 | - } else echo "Accidents are updated once a day.\n"; |
|
| 71 | + } else { |
|
| 72 | + echo "Accidents are updated once a day.\n"; |
|
| 73 | + } |
|
| 64 | 74 | } |
| 65 | 75 | |
| 66 | 76 | } |
@@ -73,15 +83,19 @@ discard block |
||
| 73 | 83 | if ($METAR->check_last_update()) { |
| 74 | 84 | $METAR->addMETARCycle(); |
| 75 | 85 | $METAR->insert_last_update(); |
| 76 | - } else echo "METAR are only updated every 30 minutes.\n"; |
|
| 77 | -} |
|
| 86 | + } else { |
|
| 87 | + echo "METAR are only updated every 30 minutes.\n"; |
|
| 88 | + } |
|
| 89 | + } |
|
| 78 | 90 | |
| 79 | 91 | if (isset($globalSchedules) && $globalSchedules && $update_db->check_last_schedules_update() && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) { |
| 80 | 92 | echo "Updating schedules..."; |
| 81 | 93 | //$update_db->update_oneworld(); |
| 82 | 94 | $update_db->update_skyteam(); |
| 83 | 95 | $update_db->insert_last_schedules_update(); |
| 84 | -} elseif (isset($globalDebug) && $globalDebug && isset($globalOwner) && $globalOwner && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) echo "Schedules are only updated every 15 days.\n"; |
|
| 96 | +} elseif (isset($globalDebug) && $globalDebug && isset($globalOwner) && $globalOwner && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) { |
|
| 97 | + echo "Schedules are only updated every 15 days.\n"; |
|
| 98 | +} |
|
| 85 | 99 | |
| 86 | 100 | if (isset($globalArchiveMonths) && $globalArchiveMonths > 0) { |
| 87 | 101 | echo "Updating statistics and archive old data..."; |
@@ -65,8 +65,11 @@ discard block |
||
| 65 | 65 | $data = array(); |
| 66 | 66 | if ($row['registration'] != '') { |
| 67 | 67 | $image_array = $Image->getSpotterImage($row['registration']); |
| 68 | - if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website'])); |
|
| 69 | - else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 68 | + if (count($image_array) > 0) { |
|
| 69 | + $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website'])); |
|
| 70 | + } else { |
|
| 71 | + $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 72 | + } |
|
| 70 | 73 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
| 71 | 74 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
| 72 | 75 | if (!empty($aircraft_info)) { |
@@ -82,32 +85,50 @@ discard block |
||
| 82 | 85 | $data['aircraft_base'] = $owner_data['base']; |
| 83 | 86 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
| 84 | 87 | } |
| 85 | - } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 86 | - if ($row['registration'] == '') $row['registration'] = 'NA'; |
|
| 87 | - if ($row['ident'] == '') $row['ident'] = 'NA'; |
|
| 88 | + } else { |
|
| 89 | + $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 90 | + } |
|
| 91 | + if ($row['registration'] == '') { |
|
| 92 | + $row['registration'] = 'NA'; |
|
| 93 | + } |
|
| 94 | + if ($row['ident'] == '') { |
|
| 95 | + $row['ident'] = 'NA'; |
|
| 96 | + } |
|
| 88 | 97 | $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2)); |
| 89 | 98 | if (isset($identicao[0])) { |
| 90 | 99 | if (substr($row['ident'],0,2) == 'AF') { |
| 91 | - if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
| 92 | - else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
| 93 | - } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
| 100 | + if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) { |
|
| 101 | + $icao = $row['ident']; |
|
| 102 | + } else { |
|
| 103 | + $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
| 104 | + } |
|
| 105 | + } else { |
|
| 106 | + $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
| 107 | + } |
|
| 94 | 108 | $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
| 95 | - } else $icao = $row['ident']; |
|
| 109 | + } else { |
|
| 110 | + $icao = $row['ident']; |
|
| 111 | + } |
|
| 96 | 112 | $icao = $Translation->checkTranslation($icao,false); |
| 97 | 113 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
| 98 | 114 | $data = array_merge($row,$data); |
| 99 | - if ($data['ident'] == null) $data['ident'] = $icao; |
|
| 115 | + if ($data['ident'] == null) { |
|
| 116 | + $data['ident'] = $icao; |
|
| 117 | + } |
|
| 100 | 118 | if ($data['title'] == null) { |
| 101 | 119 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
| 102 | - } else $data['message'] = strtolower($data['title']); |
|
| 120 | + } else { |
|
| 121 | + $data['message'] = strtolower($data['title']); |
|
| 122 | + } |
|
| 103 | 123 | $result[] = $data; |
| 104 | 124 | $i++; |
| 105 | 125 | } |
| 106 | 126 | if (isset($result)) { |
| 107 | 127 | $result[0]['query_number_rows'] = $i; |
| 108 | 128 | return $result; |
| 129 | + } else { |
|
| 130 | + return array(); |
|
| 109 | 131 | } |
| 110 | - else return array(); |
|
| 111 | 132 | } |
| 112 | 133 | |
| 113 | 134 | |
@@ -117,7 +138,9 @@ discard block |
||
| 117 | 138 | */ |
| 118 | 139 | public function import($file) { |
| 119 | 140 | global $globalTransaction, $globalDebug; |
| 120 | - if ($globalDebug) echo 'Import '.$file."\n"; |
|
| 141 | + if ($globalDebug) { |
|
| 142 | + echo 'Import '.$file."\n"; |
|
| 143 | + } |
|
| 121 | 144 | $result = array(); |
| 122 | 145 | if (file_exists($file)) { |
| 123 | 146 | if (($handle = fopen($file,'r')) !== FALSE) { |
@@ -128,7 +151,9 @@ discard block |
||
| 128 | 151 | } |
| 129 | 152 | fclose($handle); |
| 130 | 153 | } |
| 131 | - if (!empty($result)) $this->add($result,true); |
|
| 154 | + if (!empty($result)) { |
|
| 155 | + $this->add($result,true); |
|
| 156 | + } |
|
| 132 | 157 | } |
| 133 | 158 | } |
| 134 | 159 | |
@@ -168,7 +193,9 @@ discard block |
||
| 168 | 193 | //print_r($result); |
| 169 | 194 | foreach ($result as $file => $md5) { |
| 170 | 195 | $Common->download('https://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
| 171 | - if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 196 | + if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) { |
|
| 197 | + $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 198 | + } |
|
| 172 | 199 | } |
| 173 | 200 | } |
| 174 | 201 | |
@@ -179,13 +206,17 @@ discard block |
||
| 179 | 206 | $Connection = new Connection(); |
| 180 | 207 | $Image = new Image(); |
| 181 | 208 | |
| 182 | - if (empty($crash)) return false; |
|
| 209 | + if (empty($crash)) { |
|
| 210 | + return false; |
|
| 211 | + } |
|
| 183 | 212 | if (!$new) { |
| 184 | 213 | $query_delete = 'DELETE FROM accidents WHERE source = :source'; |
| 185 | 214 | $sthd = $Connection->db->prepare($query_delete); |
| 186 | 215 | $sthd->execute(array(':source' => $crash[0]['source'])); |
| 187 | 216 | } |
| 188 | - if ($globalTransaction) $Connection->db->beginTransaction(); |
|
| 217 | + if ($globalTransaction) { |
|
| 218 | + $Connection->db->beginTransaction(); |
|
| 219 | + } |
|
| 189 | 220 | $initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null); |
| 190 | 221 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
| 191 | 222 | $sth_check = $Connection->db->prepare($query_check); |
@@ -220,9 +251,13 @@ discard block |
||
| 220 | 251 | $Connection->db->beginTransaction(); |
| 221 | 252 | } |
| 222 | 253 | } |
| 223 | - if ($globalTransaction) $Connection->db->commit(); |
|
| 254 | + if ($globalTransaction) { |
|
| 255 | + $Connection->db->commit(); |
|
| 256 | + } |
|
| 224 | 257 | } catch(PDOException $e) { |
| 225 | - if ($globalTransaction) $Connection->db->rollBack(); |
|
| 258 | + if ($globalTransaction) { |
|
| 259 | + $Connection->db->rollBack(); |
|
| 260 | + } |
|
| 226 | 261 | echo $e->getMessage(); |
| 227 | 262 | } |
| 228 | 263 | $sth_check->closeCursor(); |
@@ -257,8 +292,11 @@ discard block |
||
| 257 | 292 | return "error : ".$e->getMessage(); |
| 258 | 293 | } |
| 259 | 294 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
| 260 | - if ($row['nb'] > 0) return false; |
|
| 261 | - else return true; |
|
| 295 | + if ($row['nb'] > 0) { |
|
| 296 | + return false; |
|
| 297 | + } else { |
|
| 298 | + return true; |
|
| 299 | + } |
|
| 262 | 300 | } |
| 263 | 301 | |
| 264 | 302 | public static function insert_last_accidents_update() { |