Completed
Push — master ( 8598d6...6dfca2 )
by Yannick
11:12
created

update_schema::update_from_23()   B

Complexity

Conditions 6
Paths 14

Size

Total Lines 35
Code Lines 26

Duplication

Lines 12
Ratio 34.29 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 6
eloc 26
c 1
b 1
f 0
nc 14
nop 0
dl 12
loc 35
rs 8.439
1
<?php
2
require_once(dirname(__FILE__).'/../require/settings.php');
3
require_once(dirname(__FILE__).'/../require/class.Connection.php');
4
require_once(dirname(__FILE__).'/../require/class.Scheduler.php');
5
require_once(dirname(__FILE__).'/class.create_db.php');
6
require_once(dirname(__FILE__).'/class.update_db.php');
7
8
class update_schema {
9
10
	public static function update_schedule() {
11
	    $Connection = new Connection();
12
	    $Schedule = new Schedule();
13
	    $query = "SELECT * FROM schedule";
14
            try {
15
            	$sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
16
		$sth->execute();
17
    	    } catch(PDOException $e) {
18
		return "error : ".$e->getMessage()."\n";
19
    	    }
20
    	    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
21
    		$Schedule->addSchedule($row['ident'],$row['departure_airport_icao'],$row['departure_airport_time'],$row['arrival_airport_icao'],$row['arrival_airport_time']);
22
    	    }
23
	
24
	}
25
/*
26
	private static function tableExists($tableName) {
27
	    $Connection = new Connection();
28
	    $query = "SHOW TABLES LIKE :tableName";
29
            try {
30
            	$sth = $Connection->db->prepare($query);
31
		$sth->execute(array(':tableName' => $tableName));
32
    	    } catch(PDOException $e) {
33
		return "error : ".$e->getMessage()."\n";
34
    	    }
35
    	    $row = $sth->fetch(PDO::FETCH_NUM);
36
    	    if ($row[0]) {
37
        	//echo 'table was found';
38
        	return true;
39
    	    } else {
40
        	//echo 'table was not found';
41
        	return false;
42
    	    }
43
    	}
44
*/	
45
	private static function update_from_1() {
46
    		$Connection = new Connection();
47
    		// Add new column to routes table
48
    		//$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10),`ToAirport_Time` VARCHAR(10),`Source` VARCHAR(255),`date_added` DATETIME DEFAULT CURRENT TIMESTAMP,`date_modified` DATETIME,`date_lastseen` DATETIME";
49
		$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10) NULL , ADD `ToAirport_Time` VARCHAR(10) NULL , ADD `Source` VARCHAR(255) NULL, ADD `date_added` timestamp DEFAULT CURRENT_TIMESTAMP, ADD `date_modified` timestamp NULL, ADD `date_lastseen` timestamp NULL";
50
        	try {
51
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
52
		    $sth->execute();
53
    		} catch(PDOException $e) {
54
		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
55
    		}
56
    		// Copy schedules data to routes table
57
    		self::update_schedule();
58
    		// Delete schedule table
59
		$query = "DROP TABLE `schedule`";
60
        	try {
61
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
62
		    $sth->execute();
63
    		} catch(PDOException $e) {
64
		    return "error (delete schedule table) : ".$e->getMessage()."\n";
65
    		}
66
    		// Add source column
67
    		$query = "ALTER TABLE `aircraft_modes` ADD `Source` VARCHAR(255) NULL";
68
    		try {
69
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
70
		    $sth->execute();
71
    		} catch(PDOException $e) {
72
		    return "error (add source column to aircraft_modes) : ".$e->getMessage()."\n";
73
    		}
74
		// Delete unused column
75
		$query = "ALTER TABLE `aircraft_modes`  DROP `SerialNo`,  DROP `OperatorFlagCode`,  DROP `Manufacturer`,  DROP `Type`,  DROP `FirstRegDate`,  DROP `CurrentRegDate`,  DROP `Country`,  DROP `PreviousID`,  DROP `DeRegDate`,  DROP `Status`,  DROP `PopularName`,  DROP `GenericName`,  DROP `AircraftClass`,  DROP `Engines`,  DROP `OwnershipStatus`,  DROP `RegisteredOwners`,  DROP `MTOW`,  DROP `TotalHours`,  DROP `YearBuilt`,  DROP `CofACategory`,  DROP `CofAExpiry`,  DROP `UserNotes`,  DROP `Interested`,  DROP `UserTag`,  DROP `InfoUrl`,  DROP `PictureUrl1`,  DROP `PictureUrl2`,  DROP `PictureUrl3`,  DROP `UserBool1`,  DROP `UserBool2`,  DROP `UserBool3`,  DROP `UserBool4`,  DROP `UserBool5`,  DROP `UserString1`,  DROP `UserString2`,  DROP `UserString3`,  DROP `UserString4`,  DROP `UserString5`,  DROP `UserInt1`,  DROP `UserInt2`,  DROP `UserInt3`,  DROP `UserInt4`,  DROP `UserInt5`";
76
    		try {
77
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
78
		    $sth->execute();
79
    		} catch(PDOException $e) {
80
		    return "error (Delete unused column of aircraft_modes) : ".$e->getMessage()."\n";
81
    		}
82
		// Add ModeS column
83
		$query = "ALTER TABLE `spotter_output`  ADD `ModeS` VARCHAR(255) NULL";
84
    		try {
85
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
86
		    $sth->execute();
87
    		} catch(PDOException $e) {
88
		    return "error (Add ModeS column in spotter_output) : ".$e->getMessage()."\n";
89
    		}
90
		$query = "ALTER TABLE `spotter_live`  ADD `ModeS` VARCHAR(255)";
91
    		try {
92
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
93
		    $sth->execute();
94
    		} catch(PDOException $e) {
95
		    return "error (Add ModeS column in spotter_live) : ".$e->getMessage()."\n";
96
    		}
97
    		// Add auto_increment for aircraft_modes
98
    		$query = "ALTER TABLE `aircraft_modes` CHANGE `AircraftID` `AircraftID` INT(11) NOT NULL AUTO_INCREMENT";
99
    		try {
100
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
101
		    $sth->execute();
102
    		} catch(PDOException $e) {
103
		    return "error (Add Auto increment in aircraft_modes) : ".$e->getMessage()."\n";
104
    		}
105
    		$error = '';
106
		$error .= create_db::import_file('../db/acars_live.sql');
107
		$error .= create_db::import_file('../db/config.sql');
108
		// Update schema_version to 2
109
		$query = "UPDATE `config` SET `value` = '2' WHERE `name` = 'schema_version'";
110
        	try {
111
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
112
		    $sth->execute();
113
    		} catch(PDOException $e) {
114
		    return "error (update schema_version) : ".$e->getMessage()."\n";
115
    		}
116
		return $error;
117
        }
118
119 View Code Duplication
	private static function update_from_2() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
    		$Connection = new Connection();
121
    		// Add new column decode to acars_live table
122
		$query = "ALTER TABLE `acars_live` ADD `decode` TEXT";
123
        	try {
124
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
125
		    $sth->execute();
126
    		} catch(PDOException $e) {
127
		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
128
    		}
129
    		$error = '';
130
    		// Create table acars_archive
131
		$error .= create_db::import_file('../db/acars_archive.sql');
132
		// Update schema_version to 3
133
		$query = "UPDATE `config` SET `value` = '3' WHERE `name` = 'schema_version'";
134
        	try {
135
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
136
		    $sth->execute();
137
    		} catch(PDOException $e) {
138
		    return "error (update schema_version) : ".$e->getMessage()."\n";
139
    		}
140
		return $error;
141
	}
142
143
	private static function update_from_3() {
144
    		$Connection = new Connection();
145
    		// Add default CURRENT_TIMESTAMP to aircraft_modes column FirstCreated
146
		$query = "ALTER TABLE `aircraft_modes` CHANGE `FirstCreated` `FirstCreated` timestamp DEFAULT CURRENT_TIMESTAMP";
147
        	try {
148
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
149
		    $sth->execute();
150
    		} catch(PDOException $e) {
151
		    return "error (add new columns to aircraft_modes) : ".$e->getMessage()."\n";
152
    		}
153
    		// Add image_source_website column to spotter_image
154
		$query = "ALTER TABLE `spotter_image` ADD `image_source_website` VARCHAR(999) NULL";
155
        	try {
156
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
157
		    $sth->execute();
158
    		} catch(PDOException $e) {
159
		    return "error (add new columns to spotter_image) : ".$e->getMessage()."\n";
160
    		}
161
    		$error = '';
162
		// Update schema_version to 4
163
		$query = "UPDATE `config` SET `value` = '4' WHERE `name` = 'schema_version'";
164
        	try {
165
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
166
		    $sth->execute();
167
    		} catch(PDOException $e) {
168
		    return "error (update schema_version) : ".$e->getMessage()."\n";
169
    		}
170
		return $error;
171
	}
172
	
173
	private static function update_from_4() {
174
    		$Connection = new Connection();
175
	
176
    		$error = '';
177
    		// Create table acars_label
178
		$error .= create_db::import_file('../db/acars_label.sql');
179 View Code Duplication
		if ($error == '') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
180
		    // Update schema_version to 5
181
		    $query = "UPDATE `config` SET `value` = '5' WHERE `name` = 'schema_version'";
182
        	    try {
183
            		$sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
184
			$sth->execute();
185
    		    } catch(PDOException $e) {
186
			return "error (update schema_version) : ".$e->getMessage()."\n";
187
    		    }
188
    		}
189
		return $error;
190
	}
191
192
	private static function update_from_5() {
193
    		$Connection = new Connection();
194
    		// Add columns to translation
195
		$query = "ALTER TABLE `translation` ADD `Source` VARCHAR(255) NULL, ADD `date_added` timestamp DEFAULT CURRENT_TIMESTAMP , ADD `date_modified` timestamp DEFAULT CURRENT_TIMESTAMP ;";
196
        	try {
197
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
198
		    $sth->execute();
199
    		} catch(PDOException $e) {
200
		    return "error (add new columns to translation) : ".$e->getMessage()."\n";
201
    		}
202
    		// Add aircraft_shadow column to aircraft
203
    		$query = "ALTER TABLE `aircraft` ADD `aircraft_shadow` VARCHAR(255) NULL";
204
        	try {
205
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
206
		    $sth->execute();
207
    		} catch(PDOException $e) {
208
		    return "error (add new column to aircraft) : ".$e->getMessage()."\n";
209
    		}
210
    		// Add aircraft_shadow column to spotter_live
211
    		$query = "ALTER TABLE `spotter_live` ADD `aircraft_shadow` VARCHAR(255) NULL";
212
        	try {
213
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
214
		    $sth->execute();
215
    		} catch(PDOException $e) {
216
		    return "error (add new column to spotter_live) : ".$e->getMessage()."\n";
217
    		}
218
    		$error = '';
219
    		// Update table aircraft
220
		$error .= create_db::import_file('../db/aircraft.sql');
221
		$error .= create_db::import_file('../db/spotter_archive.sql');
222
223
		// Update schema_version to 6
224
		$query = "UPDATE `config` SET `value` = '6' WHERE `name` = 'schema_version'";
225
        	try {
226
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
227
		    $sth->execute();
228
    		} catch(PDOException $e) {
229
		    return "error (update schema_version) : ".$e->getMessage()."\n";
230
    		}
231
		return $error;
232
	}
233
234
	private static function update_from_6() {
235
    		$Connection = new Connection();
236
    		if (!$Connection−>indexExists('spotter_output','flightaware_id')) {
0 ignored issues
show
Bug introduced by
The variable $Connection− does not exist. Did you mean $Connection?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
237
    		    $query = "ALTER TABLE spotter_output ADD INDEX(flightaware_id);
238
			ALTER TABLE spotter_output ADD INDEX(date);
239
			ALTER TABLE spotter_output ADD INDEX(ident);
240
			ALTER TABLE spotter_live ADD INDEX(flightaware_id);
241
			ALTER TABLE spotter_live ADD INDEX(ident);
242
			ALTER TABLE spotter_live ADD INDEX(date);
243
			ALTER TABLE spotter_live ADD INDEX(longitude);
244
			ALTER TABLE spotter_live ADD INDEX(latitude);
245
			ALTER TABLE routes ADD INDEX(CallSign);
246
			ALTER TABLE aircraft_modes ADD INDEX(ModeS);
247
			ALTER TABLE aircraft ADD INDEX(icao);
248
			ALTER TABLE airport ADD INDEX(icao);
249
			ALTER TABLE translation ADD INDEX(Operator);";
250
        	    try {
251
            		$sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
252
			$sth->execute();
253
    		    } catch(PDOException $e) {
254
			return "error (add some indexes) : ".$e->getMessage()."\n";
255
    		    }
256
    		}
257
    		$error = '';
258
    		// Update table countries
259
    		if ($Connection->tableExists('airspace')) {
260
    		    $error .= update_db::update_countries();
261
		    if ($error != '') return $error;
262
		}
263
		// Update schema_version to 7
264
		$query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'";
265
        	try {
266
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
267
		    $sth->execute();
268
    		} catch(PDOException $e) {
269
		    return "error (update schema_version) : ".$e->getMessage()."\n";
270
    		}
271
		return $error;
272
    	}
273
274
	private static function update_from_7() {
275
		global $globalDBname, $globalDBdriver;
276
    		$Connection = new Connection();
277
    		$query="ALTER TABLE spotter_live ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
278
    			ALTER TABLE spotter_output ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;";
279
        	try {
280
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
281
		    $sth->execute();
282
    		} catch(PDOException $e) {
283
		    return "error (add pilot column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
284
    		}
285 View Code Duplication
    		if ($globalDBdriver == 'mysql') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
286
    		    $query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
287
		    try {
288
            		$sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
289
			$sth->execute();
290
    		    } catch(PDOException $e) {
291
			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
292
    		    }
293
    		    $row = $sth->fetch(PDO::FETCH_ASSOC);
294
    		    if ($row['engine'] == 'ARCHIVE') {
295
			$query = "CREATE TABLE copy LIKE spotter_archive; 
296
				ALTER TABLE copy ENGINE=ARCHIVE;
297
				ALTER TABLE copy ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
298
				INSERT INTO copy SELECT *, '' as pilot_name, '' as pilot_id FROM spotter_archive ORDER BY `spotter_archive_id`;
299
				DROP TABLE spotter_archive;
300
				RENAME TABLE copy TO spotter_archive;";
301
            	    } else {
302
    			$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
303
            	    }
304
                } else {
305
    		    $query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
306
                }
307
        	try {
308
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
309
		    $sth->execute();
310
    		} catch(PDOException $e) {
311
		    return "error (add pilot column to spotter_archive) : ".$e->getMessage()."\n";
312
    		}
313
314
    		$error = '';
315
    		// Update table aircraft
316
		$error .= create_db::import_file('../db/source_location.sql');
317
		if ($error != '') return $error;
318
		// Update schema_version to 6
319
		$query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'";
320
        	try {
321
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
322
		    $sth->execute();
323
    		} catch(PDOException $e) {
324
		    return "error (update schema_version) : ".$e->getMessage()."\n";
325
    		}
326
		return $error;
327
	}
328
329 View Code Duplication
	private static function update_from_8() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
330
    		$Connection = new Connection();
331
    		$error = '';
332
    		// Update table aircraft
333
		$error .= create_db::import_file('../db/notam.sql');
334
		if ($error != '') return $error;
335
		$query = "DELETE FROM config WHERE name = 'last_update_db';
336
                        INSERT INTO config (name,value) VALUES ('last_update_db',NOW());
337
                        DELETE FROM config WHERE name = 'last_update_notam_db';
338
                        INSERT INTO config (name,value) VALUES ('last_update_notam_db',NOW());";
339
        	try {
340
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
341
		    $sth->execute();
342
    		} catch(PDOException $e) {
343
		    return "error (insert last_update values) : ".$e->getMessage()."\n";
344
    		}
345
		$query = "UPDATE `config` SET `value` = '9' WHERE `name` = 'schema_version'";
346
        	try {
347
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
348
		    $sth->execute();
349
    		} catch(PDOException $e) {
350
		    return "error (update schema_version) : ".$e->getMessage()."\n";
351
    		}
352
		return $error;
353
	}
354
355 View Code Duplication
	private static function update_from_9() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
356
    		$Connection = new Connection();
357
    		$query="ALTER TABLE spotter_live ADD verticalrate INT(11) NULL;
358
    			ALTER TABLE spotter_output ADD verticalrate INT(11) NULL;";
359
        	try {
360
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
361
		    $sth->execute();
362
    		} catch(PDOException $e) {
363
		    return "error (add verticalrate column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
364
    		}
365
		$error = '';
366
    		// Update table atc
367
		$error .= create_db::import_file('../db/atc.sql');
368
		if ($error != '') return $error;
369
		
370
		$query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'";
371
        	try {
372
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
373
		    $sth->execute();
374
    		} catch(PDOException $e) {
375
		    return "error (update schema_version) : ".$e->getMessage()."\n";
376
    		}
377
		return $error;
378
	}
379
380
	private static function update_from_10() {
381
    		$Connection = new Connection();
382
    		$query="ALTER TABLE atc CHANGE `type` `type` ENUM('Observer','Flight Information','Delivery','Tower','Approach','ACC','Departure','Ground','Flight Service Station','Control Radar or Centre') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
383
        	try {
384
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
385
		    $sth->execute();
386
    		} catch(PDOException $e) {
387
		    return "error (add new enum to ATC table) : ".$e->getMessage()."\n";
388
    		}
389
		$error = '';
390
    		// Add tables
391
		$error .= create_db::import_file('../db/aircraft_owner.sql');
392
		if ($error != '') return $error;
393
		$error .= create_db::import_file('../db/metar.sql');
394
		if ($error != '') return $error;
395
		$error .= create_db::import_file('../db/taf.sql');
396
		if ($error != '') return $error;
397
		$error .= create_db::import_file('../db/airport.sql');
398
		if ($error != '') return $error;
399
		
400
		$query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'";
401
        	try {
402
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
403
		    $sth->execute();
404
    		} catch(PDOException $e) {
405
		    return "error (update schema_version) : ".$e->getMessage()."\n";
406
    		}
407
		return $error;
408
	}
409
410
	private static function update_from_11() {
411
    		$Connection = new Connection();
412
    		$query="ALTER TABLE spotter_output ADD owner_name VARCHAR(255) NULL DEFAULT NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD last_latitude FLOAT NULL, ADD last_longitude FLOAT NULL, ADD last_altitude INT(11) NULL, ADD last_ground_speed INT(11), ADD real_arrival_airport_icao VARCHAR(999), ADD real_arrival_airport_time VARCHAR(20),ADD real_departure_airport_icao VARCHAR(999), ADD real_departure_airport_time VARCHAR(20)";
413
        	try {
414
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
415
		    $sth->execute();
416
    		} catch(PDOException $e) {
417
		    return "error (add owner_name & format_source column to spotter_output) : ".$e->getMessage()."\n";
418
    		}
419
    		$query="ALTER TABLE spotter_live ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
420
        	try {
421
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
422
		    $sth->execute();
423
    		} catch(PDOException $e) {
424
		    return "error (format_source column to spotter_live) : ".$e->getMessage()."\n";
425
    		}
426 View Code Duplication
    		if ($globalDBdriver == 'mysql') {
1 ignored issue
show
Bug introduced by
The variable $globalDBdriver does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
427
    		    $query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
0 ignored issues
show
Bug introduced by
The variable $globalDBname does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
428
		    try {
429
            		$sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
430
			$sth->execute();
431
    		    } catch(PDOException $e) {
432
			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
433
    		    }
434
    		    $row = $sth->fetch(PDO::FETCH_ASSOC);
435
    		    if ($row['engine'] == 'ARCHIVE') {
436
			$query = "CREATE TABLE copy LIKE spotter_archive; 
437
				ALTER TABLE copy ENGINE=ARCHIVE;
438
				ALTER TABLE copy ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE;
439
				INSERT INTO copy SELECT *, '' as verticalrate, '' as format_source, '0' as ground FROM spotter_archive ORDER BY `spotter_archive_id`;
440
				DROP TABLE spotter_archive;
441
				RENAME TABLE copy TO spotter_archive;";
442
            	    } else {
443
    			$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
444
            	    }
445
                } else {
446
    		    $query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
447
                }
448
        	try {
449
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
450
		    $sth->execute();
451
    		} catch(PDOException $e) {
452
		    return "error (add columns to spotter_archive) : ".$e->getMessage()."\n";
453
    		}
454
455
		$error = '';
456
		
457
		$query = "UPDATE `config` SET `value` = '12' WHERE `name` = 'schema_version'";
458
        	try {
459
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
460
		    $sth->execute();
461
    		} catch(PDOException $e) {
462
		    return "error (update schema_version) : ".$e->getMessage()."\n";
463
    		}
464
		return $error;
465
	}
466
	private static function update_from_12() {
467
    		$Connection = new Connection();
468
		$error = '';
469
    		// Add tables
470
		$error .= create_db::import_file('../db/stats.sql');
471
		if ($error != '') return $error;
472
		$error .= create_db::import_file('../db/stats_aircraft.sql');
473
		if ($error != '') return $error;
474
		$error .= create_db::import_file('../db/stats_airline.sql');
475
		if ($error != '') return $error;
476
		$error .= create_db::import_file('../db/stats_airport.sql');
477
		if ($error != '') return $error;
478
		$error .= create_db::import_file('../db/stats_owner.sql');
479
		if ($error != '') return $error;
480
		$error .= create_db::import_file('../db/stats_pilot.sql');
481
		if ($error != '') return $error;
482
		$error .= create_db::import_file('../db/spotter_archive_output.sql');
483
		if ($error != '') return $error;
484
		
485
		$query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'";
486
        	try {
487
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
488
		    $sth->execute();
489
    		} catch(PDOException $e) {
490
		    return "error (update schema_version) : ".$e->getMessage()."\n";
491
    		}
492
		return $error;
493
	}
494
495 View Code Duplication
	private static function update_from_13() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
496
    		$Connection = new Connection();
497
    		$query="ALTER TABLE spotter_archive_output ADD real_departure_airport_icao VARCHAR(20), ADD real_departure_airport_time VARCHAR(20)";
498
        	try {
499
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
500
		    $sth->execute();
501
    		} catch(PDOException $e) {
502
		    return "error (update spotter_archive_output) : ".$e->getMessage()."\n";
503
    		}
504
	
505
    		$error = '';
506
		$query = "UPDATE `config` SET `value` = '14' WHERE `name` = 'schema_version'";
507
        	try {
508
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
509
		    $sth->execute();
510
    		} catch(PDOException $e) {
511
		    return "error (update schema_version) : ".$e->getMessage()."\n";
512
    		}
513
		return $error;
514
	}
515
516 View Code Duplication
	private static function update_from_14() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
517
    		$Connection = new Connection();
518
		$error = '';
519
    		// Add tables
520
		$error .= create_db::import_file('../db/stats_flight.sql');
521
		if ($error != '') return $error;
522
		$query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'";
523
        	try {
524
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
525
		    $sth->execute();
526
    		} catch(PDOException $e) {
527
		    return "error (update schema_version) : ".$e->getMessage()."\n";
528
    		}
529
		return $error;
530
	}
531
532
533 View Code Duplication
	private static function update_from_15() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
534
    		$Connection = new Connection();
535
		$error = '';
536
    		// Add tables
537
    		$query="ALTER TABLE `stats` CHANGE `stats_date` `stats_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
538
        	try {
539
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
540
		    $sth->execute();
541
    		} catch(PDOException $e) {
542
		    return "error (update stats) : ".$e->getMessage()."\n";
543
    		}
544
		if ($error != '') return $error;
545
		$query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'";
546
        	try {
547
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
548
		    $sth->execute();
549
    		} catch(PDOException $e) {
550
		    return "error (update schema_version) : ".$e->getMessage()."\n";
551
    		}
552
		return $error;
553
	}
554
555 View Code Duplication
	private static function update_from_16() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
556
    		$Connection = new Connection();
557
		$error = '';
558
    		// Add tables
559
		$error .= create_db::import_file('../db/stats_registration.sql');
560
		$error .= create_db::import_file('../db/stats_callsign.sql');
561
		if ($error != '') return $error;
562
		$query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'";
563
        	try {
564
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
565
		    $sth->execute();
566
    		} catch(PDOException $e) {
567
		    return "error (update schema_version) : ".$e->getMessage()."\n";
568
    		}
569
		return $error;
570
	}
571
572 View Code Duplication
	private static function update_from_17() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
573
    		$Connection = new Connection();
574
		$error = '';
575
    		// Add tables
576
		$error .= create_db::import_file('../db/stats_country.sql');
577
		if ($error != '') return $error;
578
		$query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'";
579
        	try {
580
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
581
		    $sth->execute();
582
    		} catch(PDOException $e) {
583
		    return "error (update schema_version) : ".$e->getMessage()."\n";
584
    		}
585
		return $error;
586
	}
587 View Code Duplication
	private static function update_from_18() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
588
    		$Connection = new Connection();
589
		$error = '';
590
    		// Modify stats_airport table
591
    		$query = "ALTER TABLE `stats_airport` ADD `type` VARCHAR(50) NOT NULL DEFAULT 'yearly', ADD `airport_name` VARCHAR(255) NOT NULL, ADD `date` DATE NULL DEFAULT NULL, DROP INDEX `airport_icao`, ADD UNIQUE `airport_icao` (`airport_icao`, `type`, `date`)";
592
        	try {
593
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
594
		    $sth->execute();
595
    		} catch(PDOException $e) {
596
		    return "error (update stats) : ".$e->getMessage()."\n";
597
    		}
598
		if ($error != '') return $error;
599
		$query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'";
600
        	try {
601
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
602
		    $sth->execute();
603
    		} catch(PDOException $e) {
604
		    return "error (update schema_version) : ".$e->getMessage()."\n";
605
    		}
606
		return $error;
607
	}
608
609
	private static function update_from_19() {
610
    		$Connection = new Connection();
611
		$error = '';
612
    		// Update airport table
613
		$error .= create_db::import_file('../db/airport.sql');
614
		if ($error != '') return 'Import airport.sql : '.$error;
615
		// Remove primary key on Spotter_Archive
616
		$query = "alter table spotter_archive drop spotter_archive_id, add spotter_archive_id INT(11)";
617
        	try {
618
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
619
		    $sth->execute();
620
    		} catch(PDOException $e) {
621
		    return "error (remove primary key on spotter_archive) : ".$e->getMessage()."\n";
622
    		}
623
624
    		// Add column over_country
625
    		$query = "ALTER TABLE `spotter_archive` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL;ALTER TABLE `spotter_live` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL;";
626
        	try {
627
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
628
		    $sth->execute();
629
    		} catch(PDOException $e) {
630
		    return "error (add over_country) : ".$e->getMessage()."\n";
631
    		}
632
    		// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
633
    		$query = "ALTER TABLE `spotter_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;ALTER TABLE `spotter_live` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;ALTER TABLE `spotter_archive_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;ALTER TABLE `spotter_archive` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;";
634
        	try {
635
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
636
		    $sth->execute();
637
    		} catch(PDOException $e) {
638
		    return "error (add source_name column) : ".$e->getMessage()."\n";
639
    		}
640
		if ($error != '') return $error;
641
		$query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'";
642
        	try {
643
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
644
		    $sth->execute();
645
    		} catch(PDOException $e) {
646
		    return "error (update schema_version) : ".$e->getMessage()."\n";
647
    		}
648
		return $error;
649
	}
650
651
	private static function update_from_20() {
652
		global $globalIVAO, $globalVATSIM, $globalphpVMS;
653
    		$Connection = new Connection();
654
		$error = '';
655
    		// Update airline table
656
    		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
657
			$error .= create_db::import_file('../db/airlines.sql');
658
			if ($error != '') return 'Import airlinesport.sql : '.$error;
659
		}
660
    		// Add column over_country
661
    		$query = "ALTER TABLE `aircraft_modes` ADD `type_flight` VARCHAR(50) NULL DEFAULT NULL;";
662
        	try {
663
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
664
		    $sth->execute();
665
    		} catch(PDOException $e) {
666
		    return "error (add over_country) : ".$e->getMessage()."\n";
667
    		}
668
		if ($error != '') return $error;
669
		/*
670
    		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
671
			// Force update ModeS (this will put type_flight data
672
			$error .= update_db::update_ModeS;
673
			if ($error != '') return "error (update ModeS) : ".$error;
674
		}
675
		*/
676
		$query = "UPDATE `config` SET `value` = '21' WHERE `name` = 'schema_version'";
677
        	try {
678
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
679
		    $sth->execute();
680
    		} catch(PDOException $e) {
681
		    return "error (update schema_version) : ".$e->getMessage()."\n";
682
    		}
683
		return $error;
684
	}
685
686 View Code Duplication
	private static function update_from_21() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
687
    		$Connection = new Connection();
688
		$error = '';
689
		// Rename type to stats_type
690
		$query = "ALTER TABLE `stats_airport` CHANGE `type` `stats_type` VARCHAR(50);ALTER TABLE `stats` CHANGE `type` `stats_type` VARCHAR(50);ALTER TABLE `stats_flight` CHANGE `type` `stats_type` VARCHAR(50);";
691
        	try {
692
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
693
		    $sth->execute();
694
    		} catch(PDOException $e) {
695
		    return "error (rename type to stats_type on stats*) : ".$e->getMessage()."\n";
696
    		}
697
		if ($error != '') return $error;
698
		$query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'";
699
        	try {
700
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
701
		    $sth->execute();
702
    		} catch(PDOException $e) {
703
		    return "error (update schema_version) : ".$e->getMessage()."\n";
704
    		}
705
		return $error;
706
	}
707
708 View Code Duplication
	private static function update_from_22() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
709
		global $globalDBdriver;
710
    		$Connection = new Connection();
711
		$error = '';
712
		// Add table stats polar
713
		if ($globalDBdriver == 'mysql') {
714
			$error .= create_db::import_file('../db/stats_source.sql');
715
		} else {
716
			$error .= create_db::import_file('../db/pgsql/stats_source.sql');
717
		}
718
		if ($error != '') return $error;
719
		$query = "UPDATE config SET value = '23' WHERE name = 'schema_version'";
720
        	try {
721
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
722
		    $sth->execute();
723
    		} catch(PDOException $e) {
724
		    return "error (update schema_version) : ".$e->getMessage()."\n";
725
    		}
726
		return $error;
727
	}
728
729
730
	private static function update_from_23() {
1 ignored issue
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
731
		global $globalDBdriver;
732
    		$Connection = new Connection();
733
		$error = '';
734
		// Add table stats polar
735 View Code Duplication
		if ($globalDBdriver == 'mysql') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
736
			//$error .= create_db::import_file('../db/stats_source.sql');
737
		} else {
738
			//$error .= create_db::import_file('../db/pgsql/stats_source.sql');
739
			$query = "create index flightaware_id_idx ON spotter_archive USING btree(flightaware_id)";
740
        		try {
741
		    		$sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
742
				$sth->execute();
743
			} catch(PDOException $e) {
744
				return "error (create index on spotter_archive) : ".$e->getMessage()."\n";
745
			}
746
		}
747
    		$query = "";
748
        	try {
749
			$sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
750
			$sth->execute();
751
		} catch(PDOException $e) {
752
			return "error (create index on spotter_archive) : ".$e->getMessage()."\n";
753
		}
754
755
		if ($error != '') return $error;
756
		$query = "UPDATE config SET value = '24' WHERE name = 'schema_version'";
757
        	try {
758
            	    $sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
759
		    $sth->execute();
760
    		} catch(PDOException $e) {
761
		    return "error (update schema_version) : ".$e->getMessage()."\n";
762
    		}
763
		return $error;
764
	}
765
766
767
768
    	public static function check_version($update = false) {
769
    	    global $globalDBname;
770
    	    $version = 0;
771
    	    $Connection = new Connection();
772
    	    if ($Connection->tableExists('aircraft')) {
773
    		if (!$Connection->tableExists('config')) {
774
    		    $version = '1';
775
    		    if ($update) return self::update_from_1();
776
    		    else return $version;
777
		} else {
778
    		    $Connection = new Connection();
779
		    $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
780
		    try {
781
            		$sth = $Connection->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $Connection->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
782
		        $sth->execute();
783
		    } catch(PDOException $e) {
784
			return "error : ".$e->getMessage()."\n";
785
    		    }
786
    		    $result = $sth->fetch(PDO::FETCH_ASSOC);
787
    		    if ($update) {
788
    			if ($result['value'] == '2') {
789
    			    $error = self::update_from_2();
790
    			    if ($error != '') return $error;
791
    			    else return self::check_version(true);
792 View Code Duplication
    			} elseif ($result['value'] == '3') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
793
    			    $error = self::update_from_3();
794
    			    if ($error != '') return $error;
795
    			    else return self::check_version(true);
796
    			} elseif ($result['value'] == '4') {
797
    			    $error = self::update_from_4();
798
    			    if ($error != '') return $error;
799
    			    else return self::check_version(true);
800 View Code Duplication
    			} elseif ($result['value'] == '5') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
801
    			    $error = self::update_from_5();
802
    			    if ($error != '') return $error;
803
    			    else return self::check_version(true);
804
    			} elseif ($result['value'] == '6') {
805
    			    $error = self::update_from_6();
806
    			    if ($error != '') return $error;
807
    			    else return self::check_version(true);
808 View Code Duplication
    			} elseif ($result['value'] == '7') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
809
    			    $error = self::update_from_7();
810
    			    if ($error != '') return $error;
811
    			    else return self::check_version(true);
812
    			} elseif ($result['value'] == '8') {
813
    			    $error = self::update_from_8();
814
    			    if ($error != '') return $error;
815
    			    else return self::check_version(true);
816 View Code Duplication
    			} elseif ($result['value'] == '9') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
817
    			    $error = self::update_from_9();
818
    			    if ($error != '') return $error;
819
    			    else return self::check_version(true);
820
    			} elseif ($result['value'] == '10') {
821
    			    $error = self::update_from_10();
822
    			    if ($error != '') return $error;
823
    			    else return self::check_version(true);
824 View Code Duplication
    			} elseif ($result['value'] == '11') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
825
    			    $error = self::update_from_11();
826
    			    if ($error != '') return $error;
827
    			    else return self::check_version(true);
828
    			} elseif ($result['value'] == '12') {
829
    			    $error = self::update_from_12();
830
    			    if ($error != '') return $error;
831
    			    else return self::check_version(true);
832 View Code Duplication
    			} elseif ($result['value'] == '13') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
833
    			    $error = self::update_from_13();
834
    			    if ($error != '') return $error;
835
    			    else return self::check_version(true);
836
    			} elseif ($result['value'] == '14') {
837
    			    $error = self::update_from_14();
838
    			    if ($error != '') return $error;
839
    			    else return self::check_version(true);
840 View Code Duplication
    			} elseif ($result['value'] == '15') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
841
    			    $error = self::update_from_15();
842
    			    if ($error != '') return $error;
843
    			    else return self::check_version(true);
844
    			} elseif ($result['value'] == '16') {
845
    			    $error = self::update_from_16();
846
    			    if ($error != '') return $error;
847
    			    else return self::check_version(true);
848 View Code Duplication
    			} elseif ($result['value'] == '17') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
849
    			    $error = self::update_from_17();
850
    			    if ($error != '') return $error;
851
    			    else return self::check_version(true);
852
    			} elseif ($result['value'] == '18') {
853
    			    $error = self::update_from_18();
854
    			    if ($error != '') return $error;
855
    			    else return self::check_version(true);
856 View Code Duplication
    			} elseif ($result['value'] == '19') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
857
    			    $error = self::update_from_19();
858
    			    if ($error != '') return $error;
859
    			    else return self::check_version(true);
860
    			} elseif ($result['value'] == '20') {
861
    			    $error = self::update_from_20();
862
    			    if ($error != '') return $error;
863
    			    else return self::check_version(true);
864 View Code Duplication
    			} elseif ($result['value'] == '21') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
865
    			    $error = self::update_from_21();
866
    			    if ($error != '') return $error;
867
    			    else return self::check_version(true);
868
    			} elseif ($result['value'] == '22') {
869
    			    $error = self::update_from_22();
870
    			    if ($error != '') return $error;
871
    			    else return self::check_version(true);
872
    			} else return '';
873
    		    }
874
    		    else return $result['value'];
875
		}
876
		
877
	    } else return $version;
878
    	}
879
    	
880
}
881
//echo update_schema::check_version();
882
?>
1 ignored issue
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...