Completed
Push — release-2.1 ( 48a6f4...e3ceef )
by Colin
14:57 queued 06:49
created
Sources/Subs-Db-mysql.php 1 patch
Braces   +254 added lines, -187 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -64,9 +65,11 @@  discard block
 block discarded – undo
64 65
 			'db_custom_order'			=> 'smf_db_custom_order',
65 66
 			'db_native_replace'			=> true,
66 67
 		);
68
+	}
67 69
 
68
-	if (!empty($db_options['persist']))
69
-		$db_server = 'p:' . $db_server;
70
+	if (!empty($db_options['persist'])) {
71
+			$db_server = 'p:' . $db_server;
72
+	}
70 73
 
71 74
 	$connection = mysqli_init();
72 75
 
@@ -76,24 +79,27 @@  discard block
 block discarded – undo
76 79
 
77 80
 	if ($connection)
78 81
 	{
79
-		if (!empty($db_options['port']))
80
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
81
-		else
82
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
82
+		if (!empty($db_options['port'])) {
83
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
84
+		} else {
85
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
86
+		}
83 87
 	}
84 88
 
85 89
 	// Something's wrong, show an error if its fatal (which we assume it is)
86 90
 	if ($success === false)
87 91
 	{
88
-		if (!empty($db_options['non_fatal']))
89
-			return null;
90
-		else
91
-			display_db_error();
92
+		if (!empty($db_options['non_fatal'])) {
93
+					return null;
94
+		} else {
95
+					display_db_error();
96
+		}
92 97
 	}
93 98
 
94 99
 	// Select the database, unless told not to
95
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
96
-		display_db_error();
100
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
101
+			display_db_error();
102
+	}
97 103
 
98 104
 	mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
99 105
 
@@ -166,34 +172,42 @@  discard block
 block discarded – undo
166 172
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
167 173
 
168 174
 	list ($values, $connection) = $db_callback;
169
-	if (!is_object($connection))
170
-		display_db_error();
175
+	if (!is_object($connection)) {
176
+			display_db_error();
177
+	}
171 178
 
172
-	if ($matches[1] === 'db_prefix')
173
-		return $db_prefix;
179
+	if ($matches[1] === 'db_prefix') {
180
+			return $db_prefix;
181
+	}
174 182
 
175
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
176
-		return $user_info[$matches[1]];
183
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
184
+			return $user_info[$matches[1]];
185
+	}
177 186
 
178
-	if ($matches[1] === 'empty')
179
-		return '\'\'';
187
+	if ($matches[1] === 'empty') {
188
+			return '\'\'';
189
+	}
180 190
 
181
-	if (!isset($matches[2]))
182
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
191
+	if (!isset($matches[2])) {
192
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
193
+	}
183 194
 
184
-	if ($matches[1] === 'literal')
185
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
195
+	if ($matches[1] === 'literal') {
196
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
197
+	}
186 198
 
187
-	if (!isset($values[$matches[2]]))
188
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
199
+	if (!isset($values[$matches[2]])) {
200
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
201
+	}
189 202
 
190 203
 	$replacement = $values[$matches[2]];
191 204
 
192 205
 	switch ($matches[1])
193 206
 	{
194 207
 		case 'int':
195
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
196
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
208
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
209
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210
+			}
197 211
 			return (string) (int) $replacement;
198 212
 		break;
199 213
 
@@ -205,65 +219,73 @@  discard block
 block discarded – undo
205 219
 		case 'array_int':
206 220
 			if (is_array($replacement))
207 221
 			{
208
-				if (empty($replacement))
209
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+				if (empty($replacement)) {
223
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224
+				}
210 225
 
211 226
 				foreach ($replacement as $key => $value)
212 227
 				{
213
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
214
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
229
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
230
+					}
215 231
 
216 232
 					$replacement[$key] = (string) (int) $value;
217 233
 				}
218 234
 
219 235
 				return implode(', ', $replacement);
236
+			} else {
237
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220 238
 			}
221
-			else
222
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223 239
 
224 240
 		break;
225 241
 
226 242
 		case 'array_string':
227 243
 			if (is_array($replacement))
228 244
 			{
229
-				if (empty($replacement))
230
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+				if (empty($replacement)) {
246
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247
+				}
231 248
 
232
-				foreach ($replacement as $key => $value)
233
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
249
+				foreach ($replacement as $key => $value) {
250
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
251
+				}
234 252
 
235 253
 				return implode(', ', $replacement);
254
+			} else {
255
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236 256
 			}
237
-			else
238
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239 257
 		break;
240 258
 
241 259
 		case 'date':
242
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
243
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
244
-			else
245
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
261
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
262
+			} else {
263
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
264
+			}
246 265
 		break;
247 266
 
248 267
 		case 'time':
249
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
250
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
251
-			else
252
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
269
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
270
+			} else {
271
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+			}
253 273
 		break;
254 274
 
255 275
 		case 'datetime':
256
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
257
-				return 'str_to_date('.
276
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
277
+							return 'str_to_date('.
258 278
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
259 279
 					',\'%Y-%m-%d %h:%i:%s\')';
260
-			else
261
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+			} else {
281
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+			}
262 283
 		break;
263 284
 
264 285
 		case 'float':
265
-			if (!is_numeric($replacement))
266
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			if (!is_numeric($replacement)) {
287
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+			}
267 289
 			return (string) (float) $replacement;
268 290
 		break;
269 291
 
@@ -277,32 +299,37 @@  discard block
 block discarded – undo
277 299
 		break;
278 300
 
279 301
 		case 'inet':
280
-			if ($replacement == 'null' || $replacement == '')
281
-				return 'null';
282
-			if (!isValidIP($replacement))
283
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
302
+			if ($replacement == 'null' || $replacement == '') {
303
+							return 'null';
304
+			}
305
+			if (!isValidIP($replacement)) {
306
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+			}
284 308
 			//we don't use the native support of mysql > 5.6.2
285 309
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
286 310
 
287 311
 		case 'array_inet':
288 312
 			if (is_array($replacement))
289 313
 			{
290
-				if (empty($replacement))
291
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314
+				if (empty($replacement)) {
315
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
316
+				}
292 317
 
293 318
 				foreach ($replacement as $key => $value)
294 319
 				{
295
-					if ($replacement == 'null' || $replacement == '')
296
-						$replacement[$key] = 'null';
297
-					if (!isValidIP($value))
298
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
320
+					if ($replacement == 'null' || $replacement == '') {
321
+											$replacement[$key] = 'null';
322
+					}
323
+					if (!isValidIP($value)) {
324
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
325
+					}
299 326
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
300 327
 				}
301 328
 
302 329
 				return implode(', ', $replacement);
330
+			} else {
331
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
303 332
 			}
304
-			else
305
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
306 333
 		break;
307 334
 
308 335
 		default:
@@ -373,18 +400,20 @@  discard block
 block discarded – undo
373 400
 	// One more query....
374 401
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
375 402
 
376
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
377
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
403
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
404
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
405
+	}
378 406
 
379 407
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
380 408
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
381 409
 	{
382 410
 		// Add before LIMIT
383
-		if ($pos = strpos($db_string, 'LIMIT '))
384
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
385
-		else
386
-			// Append it.
411
+		if ($pos = strpos($db_string, 'LIMIT ')) {
412
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
413
+		} else {
414
+					// Append it.
387 415
 			$db_string .= "\n\t\t\tORDER BY null";
416
+		}
388 417
 	}
389 418
 
390 419
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -410,17 +439,18 @@  discard block
 block discarded – undo
410 439
 		while (true)
411 440
 		{
412 441
 			$pos = strpos($db_string_1, '\'', $pos + 1);
413
-			if ($pos === false)
414
-				break;
442
+			if ($pos === false) {
443
+							break;
444
+			}
415 445
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
416 446
 
417 447
 			while (true)
418 448
 			{
419 449
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
420 450
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
421
-				if ($pos1 === false)
422
-					break;
423
-				elseif ($pos2 === false || $pos2 > $pos1)
451
+				if ($pos1 === false) {
452
+									break;
453
+				} elseif ($pos2 === false || $pos2 > $pos1)
424 454
 				{
425 455
 					$pos = $pos1;
426 456
 					break;
@@ -436,16 +466,19 @@  discard block
 block discarded – undo
436 466
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
437 467
 
438 468
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
439
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
440
-			$fail = true;
469
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
470
+					$fail = true;
471
+		}
441 472
 		// Trying to change passwords, slow us down, or something?
442
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
443
-			$fail = true;
444
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
445
-			$fail = true;
473
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
474
+					$fail = true;
475
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
476
+					$fail = true;
477
+		}
446 478
 
447
-		if (!empty($fail) && function_exists('log_error'))
448
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
479
+		if (!empty($fail) && function_exists('log_error')) {
480
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
481
+		}
449 482
 	}
450 483
 
451 484
 	// Debugging.
@@ -455,8 +488,9 @@  discard block
 block discarded – undo
455 488
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
456 489
 
457 490
 		// Initialize $db_cache if not already initialized.
458
-		if (!isset($db_cache))
459
-			$db_cache = array();
491
+		if (!isset($db_cache)) {
492
+					$db_cache = array();
493
+		}
460 494
 
461 495
 		if (!empty($_SESSION['debug_redirect']))
462 496
 		{
@@ -472,17 +506,20 @@  discard block
 block discarded – undo
472 506
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
473 507
 	}
474 508
 
475
-	if (empty($db_unbuffered))
476
-		$ret = @mysqli_query($connection, $db_string);
477
-	else
478
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
509
+	if (empty($db_unbuffered)) {
510
+			$ret = @mysqli_query($connection, $db_string);
511
+	} else {
512
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
513
+	}
479 514
 
480
-	if ($ret === false && empty($db_values['db_error_skip']))
481
-		$ret = smf_db_error($db_string, $connection);
515
+	if ($ret === false && empty($db_values['db_error_skip'])) {
516
+			$ret = smf_db_error($db_string, $connection);
517
+	}
482 518
 
483 519
 	// Debugging.
484
-	if (isset($db_show_debug) && $db_show_debug === true)
485
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
520
+	if (isset($db_show_debug) && $db_show_debug === true) {
521
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
522
+	}
486 523
 
487 524
 	return $ret;
488 525
 }
@@ -529,12 +566,13 @@  discard block
 block discarded – undo
529 566
 	// Decide which connection to use
530 567
 	$connection = $connection === null ? $db_connection : $connection;
531 568
 
532
-	if ($type == 'begin')
533
-		return @mysqli_query($connection, 'BEGIN');
534
-	elseif ($type == 'rollback')
535
-		return @mysqli_query($connection, 'ROLLBACK');
536
-	elseif ($type == 'commit')
537
-		return @mysqli_query($connection, 'COMMIT');
569
+	if ($type == 'begin') {
570
+			return @mysqli_query($connection, 'BEGIN');
571
+	} elseif ($type == 'rollback') {
572
+			return @mysqli_query($connection, 'ROLLBACK');
573
+	} elseif ($type == 'commit') {
574
+			return @mysqli_query($connection, 'COMMIT');
575
+	}
538 576
 
539 577
 	return false;
540 578
 }
@@ -572,8 +610,9 @@  discard block
 block discarded – undo
572 610
 	//    1213: Deadlock found.
573 611
 
574 612
 	// Log the error.
575
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
576
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
613
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
614
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
615
+	}
577 616
 
578 617
 	// Database error auto fixing ;).
579 618
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -582,8 +621,9 @@  discard block
 block discarded – undo
582 621
 		$old_cache = @$modSettings['cache_enable'];
583 622
 		$modSettings['cache_enable'] = '1';
584 623
 
585
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
586
-			$db_last_error = max(@$db_last_error, $temp);
624
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
625
+					$db_last_error = max(@$db_last_error, $temp);
626
+		}
587 627
 
588 628
 		if (@$db_last_error < time() - 3600 * 24 * 3)
589 629
 		{
@@ -599,8 +639,9 @@  discard block
 block discarded – undo
599 639
 					foreach ($tables as $table)
600 640
 					{
601 641
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
602
-						if (trim($table) != '')
603
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
642
+						if (trim($table) != '') {
643
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
644
+						}
604 645
 					}
605 646
 				}
606 647
 
@@ -609,8 +650,9 @@  discard block
 block discarded – undo
609 650
 			// Table crashed.  Let's try to fix it.
610 651
 			elseif ($query_errno == 1016)
611 652
 			{
612
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
613
-					$fix_tables = array('`' . $match[1] . '`');
653
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
654
+									$fix_tables = array('`' . $match[1] . '`');
655
+				}
614 656
 			}
615 657
 			// Indexes crashed.  Should be easy to fix!
616 658
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -629,13 +671,15 @@  discard block
 block discarded – undo
629 671
 
630 672
 			// Make a note of the REPAIR...
631 673
 			cache_put_data('db_last_error', time(), 600);
632
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
633
-				updateSettingsFile(array('db_last_error' => time()));
674
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
675
+							updateSettingsFile(array('db_last_error' => time()));
676
+			}
634 677
 
635 678
 			// Attempt to find and repair the broken table.
636
-			foreach ($fix_tables as $table)
637
-				$smcFunc['db_query']('', "
679
+			foreach ($fix_tables as $table) {
680
+							$smcFunc['db_query']('', "
638 681
 					REPAIR TABLE $table", false, false);
682
+			}
639 683
 
640 684
 			// And send off an email!
641 685
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -644,11 +688,12 @@  discard block
 block discarded – undo
644 688
 
645 689
 			// Try the query again...?
646 690
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
647
-			if ($ret !== false)
648
-				return $ret;
691
+			if ($ret !== false) {
692
+							return $ret;
693
+			}
694
+		} else {
695
+					$modSettings['cache_enable'] = $old_cache;
649 696
 		}
650
-		else
651
-			$modSettings['cache_enable'] = $old_cache;
652 697
 
653 698
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
654 699
 		if (in_array($query_errno, array(1205, 1213)))
@@ -661,24 +706,27 @@  discard block
 block discarded – undo
661 706
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
662 707
 
663 708
 					$new_errno = mysqli_errno($db_connection);
664
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
665
-						break;
709
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
710
+											break;
711
+					}
666 712
 				}
667 713
 
668 714
 				// If it failed again, shucks to be you... we're not trying it over and over.
669
-				if ($ret !== false)
670
-					return $ret;
715
+				if ($ret !== false) {
716
+									return $ret;
717
+				}
671 718
 			}
672 719
 		}
673 720
 		// Are they out of space, perhaps?
674 721
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
675 722
 		{
676
-			if (!isset($txt))
677
-				$query_error .= ' - check database storage space.';
678
-			else
723
+			if (!isset($txt)) {
724
+							$query_error .= ' - check database storage space.';
725
+			} else
679 726
 			{
680
-				if (!isset($txt['mysql_error_space']))
681
-					loadLanguage('Errors');
727
+				if (!isset($txt['mysql_error_space'])) {
728
+									loadLanguage('Errors');
729
+				}
682 730
 
683 731
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
684 732
 			}
@@ -686,15 +734,17 @@  discard block
 block discarded – undo
686 734
 	}
687 735
 
688 736
 	// Nothing's defined yet... just die with it.
689
-	if (empty($context) || empty($txt))
690
-		die($query_error);
737
+	if (empty($context) || empty($txt)) {
738
+			die($query_error);
739
+	}
691 740
 
692 741
 	// Show an error message, if possible.
693 742
 	$context['error_title'] = $txt['database_error'];
694
-	if (allowedTo('admin_forum'))
695
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
696
-	else
697
-		$context['error_message'] = $txt['try_again'];
743
+	if (allowedTo('admin_forum')) {
744
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
745
+	} else {
746
+			$context['error_message'] = $txt['try_again'];
747
+	}
698 748
 
699 749
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
700 750
 	{
@@ -726,8 +776,9 @@  discard block
 block discarded – undo
726 776
 	$return_var = null;
727 777
 
728 778
 	// With nothing to insert, simply return.
729
-	if (empty($data))
730
-		return;
779
+	if (empty($data)) {
780
+			return;
781
+	}
731 782
 
732 783
 	// Replace the prefix holder with the actual prefix.
733 784
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -737,23 +788,26 @@  discard block
 block discarded – undo
737 788
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
738 789
 	{
739 790
 		$with_returning = true;
740
-		if ($returnmode == 2)
741
-			$return_var = array();
791
+		if ($returnmode == 2) {
792
+					$return_var = array();
793
+		}
742 794
 	}
743 795
 
744 796
 	// Inserting data as a single row can be done as a single array.
745
-	if (!is_array($data[array_rand($data)]))
746
-		$data = array($data);
797
+	if (!is_array($data[array_rand($data)])) {
798
+			$data = array($data);
799
+	}
747 800
 
748 801
 	// Create the mold for a single row insert.
749 802
 	$insertData = '(';
750 803
 	foreach ($columns as $columnName => $type)
751 804
 	{
752 805
 		// Are we restricting the length?
753
-		if (strpos($type, 'string-') !== false)
754
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
755
-		else
756
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
806
+		if (strpos($type, 'string-') !== false) {
807
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
808
+		} else {
809
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
810
+		}
757 811
 	}
758 812
 	$insertData = substr($insertData, 0, -2) . ')';
759 813
 
@@ -762,8 +816,9 @@  discard block
 block discarded – undo
762 816
 
763 817
 	// Here's where the variables are injected to the query.
764 818
 	$insertRows = array();
765
-	foreach ($data as $dataRow)
766
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
819
+	foreach ($data as $dataRow) {
820
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
821
+	}
767 822
 
768 823
 	// Determine the method of insertion.
769 824
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -782,8 +837,7 @@  discard block
 block discarded – undo
782 837
 			),
783 838
 			$connection
784 839
 		);
785
-	}
786
-	else //special way for ignore method with returning
840
+	} else //special way for ignore method with returning
787 841
 	{
788 842
 		$count = count($insertRows);
789 843
 		$ai = 0;
@@ -803,19 +857,21 @@  discard block
 block discarded – undo
803 857
 			);
804 858
 			$new_id = $smcFunc['db_insert_id']();
805 859
 
806
-			if ($last_id != $new_id) //the inserted value was new
860
+			if ($last_id != $new_id) {
861
+				//the inserted value was new
807 862
 			{
808 863
 				$ai = $new_id;
809 864
 			}
810
-			else	// the inserted value already exists we need to find the pk
865
+			} else	// the inserted value already exists we need to find the pk
811 866
 			{
812 867
 				$where_string = '';
813 868
 				$count2 = count($indexed_columns);
814 869
 				for ($x = 0; $x < $count2; $x++)
815 870
 				{
816 871
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
817
-					if (($x + 1) < $count2)
818
-						$where_string += ' AND ';
872
+					if (($x + 1) < $count2) {
873
+											$where_string += ' AND ';
874
+					}
819 875
 				}
820 876
 
821 877
 				$request = $smcFunc['db_query']('','
@@ -831,25 +887,27 @@  discard block
 block discarded – undo
831 887
 				}
832 888
 			}
833 889
 
834
-			if ($returnmode == 1)
835
-				$return_var = $ai;
836
-			else if ($returnmode == 2)
837
-				$return_var[] = $ai;
890
+			if ($returnmode == 1) {
891
+							$return_var = $ai;
892
+			} else if ($returnmode == 2) {
893
+							$return_var[] = $ai;
894
+			}
838 895
 		}
839 896
 	}
840 897
 
841 898
 
842 899
 	if ($with_returning)
843 900
 	{
844
-		if ($returnmode == 1 && empty($return_var))
845
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
846
-		else if ($returnmode == 2 && empty($return_var))
901
+		if ($returnmode == 1 && empty($return_var)) {
902
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
903
+		} else if ($returnmode == 2 && empty($return_var))
847 904
 		{
848 905
 			$return_var = array();
849 906
 			$count = count($insertRows);
850 907
 			$start = smf_db_insert_id($table, $keys[0]);
851
-			for ($i = 0; $i < $count; $i++ )
852
-				$return_var[] = $start + $i;
908
+			for ($i = 0; $i < $count; $i++ ) {
909
+							$return_var[] = $start + $i;
910
+			}
853 911
 		}
854 912
 		return $return_var;
855 913
 	}
@@ -867,8 +925,9 @@  discard block
 block discarded – undo
867 925
  */
868 926
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
869 927
 {
870
-	if (empty($log_message))
871
-		$log_message = $error_message;
928
+	if (empty($log_message)) {
929
+			$log_message = $error_message;
930
+	}
872 931
 
873 932
 	foreach (debug_backtrace() as $step)
874 933
 	{
@@ -887,12 +946,14 @@  discard block
 block discarded – undo
887 946
 	}
888 947
 
889 948
 	// A special case - we want the file and line numbers for debugging.
890
-	if ($error_type == 'return')
891
-		return array($file, $line);
949
+	if ($error_type == 'return') {
950
+			return array($file, $line);
951
+	}
892 952
 
893 953
 	// Is always a critical error.
894
-	if (function_exists('log_error'))
895
-		log_error($log_message, 'critical', $file, $line);
954
+	if (function_exists('log_error')) {
955
+			log_error($log_message, 'critical', $file, $line);
956
+	}
896 957
 
897 958
 	if (function_exists('fatal_error'))
898 959
 	{
@@ -900,12 +961,12 @@  discard block
 block discarded – undo
900 961
 
901 962
 		// Cannot continue...
902 963
 		exit;
964
+	} elseif ($error_type) {
965
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
966
+	} else {
967
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
968
+	}
903 969
 	}
904
-	elseif ($error_type)
905
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
906
-	else
907
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
908
-}
909 970
 
910 971
 /**
911 972
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -922,10 +983,11 @@  discard block
 block discarded – undo
922 983
 		'\\' => '\\\\',
923 984
 	);
924 985
 
925
-	if ($translate_human_wildcards)
926
-		$replacements += array(
986
+	if ($translate_human_wildcards) {
987
+			$replacements += array(
927 988
 			'*' => '%',
928 989
 		);
990
+	}
929 991
 
930 992
 	return strtr($string, $replacements);
931 993
 }
@@ -939,8 +1001,9 @@  discard block
 block discarded – undo
939 1001
  */
940 1002
 function smf_is_resource($result)
941 1003
 {
942
-	if ($result instanceof mysqli_result)
943
-		return true;
1004
+	if ($result instanceof mysqli_result) {
1005
+			return true;
1006
+	}
944 1007
 
945 1008
 	return false;
946 1009
 }
@@ -969,19 +1032,22 @@  discard block
 block discarded – undo
969 1032
 	static $mysql_error_data_prep;
970 1033
 
971 1034
 	// without database we can't do anything
972
-	if (empty($db_connection))
973
-		return;
1035
+	if (empty($db_connection)) {
1036
+			return;
1037
+	}
974 1038
 
975
-	if (empty($mysql_error_data_prep))
976
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1039
+	if (empty($mysql_error_data_prep)) {
1040
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
977 1041
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
978 1042
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?)'
979 1043
 			);
1044
+	}
980 1045
 
981
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
982
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
983
-	else
984
-		$error_array[2] = null;
1046
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1047
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1048
+	} else {
1049
+			$error_array[2] = null;
1050
+	}
985 1051
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi',
986 1052
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
987 1053
 		$error_array[7], $error_array[8]);
@@ -1003,8 +1069,9 @@  discard block
 block discarded – undo
1003 1069
 	$count = count($array_values);
1004 1070
 	$then = ($desc ? ' THEN -' : ' THEN ');
1005 1071
 
1006
-	for ($i = 0; $i < $count; $i++)
1007
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1072
+	for ($i = 0; $i < $count; $i++) {
1073
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1074
+	}
1008 1075
 
1009 1076
 	$return .= 'END';
1010 1077
 	return $return;
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +904 added lines, -663 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -107,11 +108,14 @@  discard block
 block discarded – undo
107 108
 	ini_set('default_socket_timeout', 900);
108 109
 }
109 110
 // Clean the upgrade path if this is from the client.
110
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
111
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
111
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
112
+	for ($i = 1;
113
+}
114
+$i < $_SERVER['argc']; $i++)
112 115
 	{
113
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
114
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
116
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
117
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
118
+		}
115 119
 	}
116 120
 
117 121
 // Are we from the client?
@@ -119,16 +123,17 @@  discard block
 block discarded – undo
119 123
 {
120 124
 	$command_line = true;
121 125
 	$disable_security = true;
122
-}
123
-else
126
+} else {
124 127
 	$command_line = false;
128
+}
125 129
 
126 130
 // Load this now just because we can.
127 131
 require_once($upgrade_path . '/Settings.php');
128 132
 
129 133
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
130
-if (isset($language))
134
+if (isset($language)) {
131 135
 	$language = str_ireplace('-utf8', '', $language);
136
+}
132 137
 
133 138
 // Are we logged in?
134 139
 if (isset($upgradeData))
@@ -136,10 +141,12 @@  discard block
 block discarded – undo
136 141
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
137 142
 
138 143
 	// Check for sensible values.
139
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
140
-		$upcontext['user']['started'] = time();
141
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
142
-		$upcontext['user']['updated'] = 0;
144
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
145
+			$upcontext['user']['started'] = time();
146
+	}
147
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
148
+			$upcontext['user']['updated'] = 0;
149
+	}
143 150
 
144 151
 	$upcontext['started'] = $upcontext['user']['started'];
145 152
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 			'db_error_skip' => true,
205 212
 		)
206 213
 	);
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$modSettings[$row['variable']] = $row['value'];
214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
215
+			$modSettings[$row['variable']] = $row['value'];
216
+	}
209 217
 	$smcFunc['db_free_result']($request);
210 218
 }
211 219
 
@@ -215,10 +223,12 @@  discard block
 block discarded – undo
215 223
 	$modSettings['theme_url'] = 'Themes/default';
216 224
 	$modSettings['images_url'] = 'Themes/default/images';
217 225
 }
218
-if (!isset($settings['default_theme_url']))
226
+if (!isset($settings['default_theme_url'])) {
219 227
 	$settings['default_theme_url'] = $modSettings['theme_url'];
220
-if (!isset($settings['default_theme_dir']))
228
+}
229
+if (!isset($settings['default_theme_dir'])) {
221 230
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
231
+}
222 232
 
223 233
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
224 234
 // Default title...
@@ -236,13 +246,15 @@  discard block
 block discarded – undo
236 246
 	$support_js = $upcontext['upgrade_status']['js'];
237 247
 
238 248
 	// Only set this if the upgrader status says so.
239
-	if (empty($is_debug))
240
-		$is_debug = $upcontext['upgrade_status']['debug'];
249
+	if (empty($is_debug)) {
250
+			$is_debug = $upcontext['upgrade_status']['debug'];
251
+	}
241 252
 
242 253
 	// Load the language.
243
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
244
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
245
-}
254
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
255
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
256
+	}
257
+	}
246 258
 // Set the defaults.
247 259
 else
248 260
 {
@@ -260,15 +272,18 @@  discard block
 block discarded – undo
260 272
 }
261 273
 
262 274
 // If this isn't the first stage see whether they are logging in and resuming.
263
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
275
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
264 276
 	checkLogin();
277
+}
265 278
 
266
-if ($command_line)
279
+if ($command_line) {
267 280
 	cmdStep0();
281
+}
268 282
 
269 283
 // Don't error if we're using xml.
270
-if (isset($_GET['xml']))
284
+if (isset($_GET['xml'])) {
271 285
 	$upcontext['return_error'] = true;
286
+}
272 287
 
273 288
 // Loop through all the steps doing each one as required.
274 289
 $upcontext['overall_percent'] = 0;
@@ -289,9 +304,9 @@  discard block
 block discarded – undo
289 304
 		}
290 305
 
291 306
 		// Call the step and if it returns false that means pause!
292
-		if (function_exists($step[2]) && $step[2]() === false)
293
-			break;
294
-		elseif (function_exists($step[2])) {
307
+		if (function_exists($step[2]) && $step[2]() === false) {
308
+					break;
309
+		} elseif (function_exists($step[2])) {
295 310
 			//Start each new step with this unset, so the 'normal' template is called first
296 311
 			unset($_GET['xml']);
297 312
 			//Clear out warnings at the start of each step
@@ -337,17 +352,18 @@  discard block
 block discarded – undo
337 352
 		// This should not happen my dear... HELP ME DEVELOPERS!!
338 353
 		if (!empty($command_line))
339 354
 		{
340
-			if (function_exists('debug_print_backtrace'))
341
-				debug_print_backtrace();
355
+			if (function_exists('debug_print_backtrace')) {
356
+							debug_print_backtrace();
357
+			}
342 358
 
343 359
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
344 360
 			flush();
345 361
 			die();
346 362
 		}
347 363
 
348
-		if (!isset($_GET['xml']))
349
-			template_upgrade_above();
350
-		else
364
+		if (!isset($_GET['xml'])) {
365
+					template_upgrade_above();
366
+		} else
351 367
 		{
352 368
 			header('content-type: text/xml; charset=UTF-8');
353 369
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -369,25 +385,29 @@  discard block
 block discarded – undo
369 385
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
370 386
 
371 387
 			// Custom stuff to pass back?
372
-			if (!empty($upcontext['query_string']))
373
-				$upcontext['form_url'] .= $upcontext['query_string'];
388
+			if (!empty($upcontext['query_string'])) {
389
+							$upcontext['form_url'] .= $upcontext['query_string'];
390
+			}
374 391
 
375 392
 			// Call the appropriate subtemplate
376
-			if (is_callable('template_' . $upcontext['sub_template']))
377
-				call_user_func('template_' . $upcontext['sub_template']);
378
-			else
379
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
393
+			if (is_callable('template_' . $upcontext['sub_template'])) {
394
+							call_user_func('template_' . $upcontext['sub_template']);
395
+			} else {
396
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
397
+			}
380 398
 		}
381 399
 
382 400
 		// Was there an error?
383
-		if (!empty($upcontext['forced_error_message']))
384
-			echo $upcontext['forced_error_message'];
401
+		if (!empty($upcontext['forced_error_message'])) {
402
+					echo $upcontext['forced_error_message'];
403
+		}
385 404
 
386 405
 		// Show the footer.
387
-		if (!isset($_GET['xml']))
388
-			template_upgrade_below();
389
-		else
390
-			template_xml_below();
406
+		if (!isset($_GET['xml'])) {
407
+					template_upgrade_below();
408
+		} else {
409
+					template_xml_below();
410
+		}
391 411
 	}
392 412
 
393 413
 
@@ -399,15 +419,19 @@  discard block
 block discarded – undo
399 419
 		$seconds = intval($active % 60);
400 420
 
401 421
 		$totalTime = '';
402
-		if ($hours > 0)
403
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
404
-		if ($minutes > 0)
405
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
406
-		if ($seconds > 0)
407
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
422
+		if ($hours > 0) {
423
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
424
+		}
425
+		if ($minutes > 0) {
426
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
427
+		}
428
+		if ($seconds > 0) {
429
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
430
+		}
408 431
 
409
-		if (!empty($totalTime))
410
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
432
+		if (!empty($totalTime)) {
433
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
434
+		}
411 435
 	}
412 436
 
413 437
 	// Bang - gone!
@@ -428,8 +452,9 @@  discard block
 block discarded – undo
428 452
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
429 453
 		while ($entry = $dir->read())
430 454
 		{
431
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
432
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
455
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
456
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
457
+			}
433 458
 		}
434 459
 		$dir->close();
435 460
 	}
@@ -464,10 +489,11 @@  discard block
 block discarded – undo
464 489
 	}
465 490
 
466 491
 	// Override the language file?
467
-	if (isset($_GET['lang_file']))
468
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
469
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
470
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
492
+	if (isset($_GET['lang_file'])) {
493
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
494
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
495
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
496
+	}
471 497
 
472 498
 	// Make sure it exists, if it doesn't reset it.
473 499
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -476,12 +502,14 @@  discard block
 block discarded – undo
476 502
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
477 503
 
478 504
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
479
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
480
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
505
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
506
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
507
+		}
481 508
 
482 509
 		// For backup we load the english at first -> second language overwrite the english one
483
-		if (count($incontext['detected_languages']) > 1)
484
-			require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
510
+		if (count($incontext['detected_languages']) > 1) {
511
+					require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
512
+		}
485 513
 	}
486 514
 
487 515
 	// And now include the actual language file itself.
@@ -489,11 +517,12 @@  discard block
 block discarded – undo
489 517
 
490 518
 	// Which language did we load? Assume that he likes his language.
491 519
 	preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches);
492
-	if (empty($matches[1]))
493
-		$matches = [
520
+	if (empty($matches[1])) {
521
+			$matches = [
494 522
 			0 => 'nothing',
495 523
 			1 => 'english',
496 524
 		];
525
+	}
497 526
 	$user_info['language'] = $matches[1];
498 527
 }
499 528
 
@@ -503,8 +532,9 @@  discard block
 block discarded – undo
503 532
 	global $upgradeurl, $upcontext, $command_line;
504 533
 
505 534
 	// Command line users can't be redirected.
506
-	if ($command_line)
507
-		upgradeExit(true);
535
+	if ($command_line) {
536
+			upgradeExit(true);
537
+	}
508 538
 
509 539
 	// Are we providing the core info?
510 540
 	if ($addForm)
@@ -530,12 +560,14 @@  discard block
 block discarded – undo
530 560
 	define('SMF', 1);
531 561
 
532 562
 	// Start the session.
533
-	if (@ini_get('session.save_handler') == 'user')
534
-		@ini_set('session.save_handler', 'files');
563
+	if (@ini_get('session.save_handler') == 'user') {
564
+			@ini_set('session.save_handler', 'files');
565
+	}
535 566
 	@session_start();
536 567
 
537
-	if (empty($smcFunc))
538
-		$smcFunc = array();
568
+	if (empty($smcFunc)) {
569
+			$smcFunc = array();
570
+	}
539 571
 
540 572
 	// We need this for authentication and some upgrade code
541 573
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -562,24 +594,27 @@  discard block
 block discarded – undo
562 594
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
563 595
 
564 596
 		// Make the connection...
565
-		if (empty($db_connection))
566
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
567
-		else
568
-			// If we've returned here, ping/reconnect to be safe
597
+		if (empty($db_connection)) {
598
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
599
+		} else {
600
+					// If we've returned here, ping/reconnect to be safe
569 601
 			$smcFunc['db_ping']($db_connection);
602
+		}
570 603
 
571 604
 		// Oh dear god!!
572
-		if ($db_connection === null)
573
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
605
+		if ($db_connection === null) {
606
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
607
+		}
574 608
 
575
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
576
-			$smcFunc['db_query']('', '
609
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
610
+					$smcFunc['db_query']('', '
577 611
 			SET NAMES {string:db_character_set}',
578 612
 			array(
579 613
 				'db_error_skip' => true,
580 614
 				'db_character_set' => $db_character_set,
581 615
 			)
582 616
 		);
617
+		}
583 618
 
584 619
 		// Load the modSettings data...
585 620
 		$request = $smcFunc['db_query']('', '
@@ -590,11 +625,11 @@  discard block
 block discarded – undo
590 625
 			)
591 626
 		);
592 627
 		$modSettings = array();
593
-		while ($row = $smcFunc['db_fetch_assoc']($request))
594
-			$modSettings[$row['variable']] = $row['value'];
628
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
629
+					$modSettings[$row['variable']] = $row['value'];
630
+		}
595 631
 		$smcFunc['db_free_result']($request);
596
-	}
597
-	else
632
+	} else
598 633
 	{
599 634
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
600 635
 	}
@@ -608,9 +643,10 @@  discard block
 block discarded – undo
608 643
 		cleanRequest();
609 644
 	}
610 645
 
611
-	if (!isset($_GET['substep']))
612
-		$_GET['substep'] = 0;
613
-}
646
+	if (!isset($_GET['substep'])) {
647
+			$_GET['substep'] = 0;
648
+	}
649
+	}
614 650
 
615 651
 function initialize_inputs()
616 652
 {
@@ -640,8 +676,9 @@  discard block
 block discarded – undo
640 676
 		$dh = opendir(dirname(__FILE__));
641 677
 		while ($file = readdir($dh))
642 678
 		{
643
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
644
-				@unlink(dirname(__FILE__) . '/' . $file);
679
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
680
+							@unlink(dirname(__FILE__) . '/' . $file);
681
+			}
645 682
 		}
646 683
 		closedir($dh);
647 684
 
@@ -670,8 +707,9 @@  discard block
 block discarded – undo
670 707
 	$temp = 'upgrade_php?step';
671 708
 	while (strlen($temp) > 4)
672 709
 	{
673
-		if (isset($_GET[$temp]))
674
-			unset($_GET[$temp]);
710
+		if (isset($_GET[$temp])) {
711
+					unset($_GET[$temp]);
712
+		}
675 713
 		$temp = substr($temp, 1);
676 714
 	}
677 715
 
@@ -698,32 +736,39 @@  discard block
 block discarded – undo
698 736
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
699 737
 
700 738
 	// Need legacy scripts?
701
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
702
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
703
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
704
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
705
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
706
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
739
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
740
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
741
+	}
742
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
743
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
744
+	}
745
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
746
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
747
+	}
707 748
 
708 749
 	// We don't need "-utf8" files anymore...
709 750
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
710 751
 
711 752
 	// This needs to exist!
712
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
713
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
714
-	else
715
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
753
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
754
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
755
+	} else {
756
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
757
+	}
716 758
 
717
-	if (!$check)
718
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
759
+	if (!$check) {
760
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
719 761
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
762
+	}
720 763
 
721 764
 	// Do they meet the install requirements?
722
-	if (!php_version_check())
723
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
765
+	if (!php_version_check()) {
766
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
767
+	}
724 768
 
725
-	if (!db_version_check())
726
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
769
+	if (!db_version_check()) {
770
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
771
+	}
727 772
 
728 773
 	// Do some checks to make sure they have proper privileges
729 774
 	db_extend('packages');
@@ -738,14 +783,16 @@  discard block
 block discarded – undo
738 783
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
739 784
 
740 785
 	// Sorry... we need CREATE, ALTER and DROP
741
-	if (!$create || !$alter || !$drop)
742
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
786
+	if (!$create || !$alter || !$drop) {
787
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
788
+	}
743 789
 
744 790
 	// Do a quick version spot check.
745 791
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
746 792
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
747
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
748
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
793
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
794
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
795
+	}
749 796
 
750 797
 	// What absolutely needs to be writable?
751 798
 	$writable_files = array(
@@ -754,12 +801,13 @@  discard block
 block discarded – undo
754 801
 	);
755 802
 
756 803
 	// Only check for minified writable files if we have it enabled or not set.
757
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
758
-		$writable_files += array(
804
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
805
+			$writable_files += array(
759 806
 			$modSettings['theme_dir'] . '/css/minified.css',
760 807
 			$modSettings['theme_dir'] . '/scripts/minified.js',
761 808
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
762 809
 		);
810
+	}
763 811
 
764 812
 	// Do we need to add this setting?
765 813
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -771,12 +819,13 @@  discard block
 block discarded – undo
771 819
 	quickFileWritable($custom_av_dir);
772 820
 
773 821
 	// Are we good now?
774
-	if (!is_writable($custom_av_dir))
775
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
776
-	elseif ($need_settings_update)
822
+	if (!is_writable($custom_av_dir)) {
823
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
824
+	} elseif ($need_settings_update)
777 825
 	{
778
-		if (!function_exists('cache_put_data'))
779
-			require_once($sourcedir . '/Load.php');
826
+		if (!function_exists('cache_put_data')) {
827
+					require_once($sourcedir . '/Load.php');
828
+		}
780 829
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
781 830
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
782 831
 	}
@@ -785,28 +834,33 @@  discard block
 block discarded – undo
785 834
 
786 835
 	// Check the cache directory.
787 836
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
788
-	if (!file_exists($cachedir_temp))
789
-		@mkdir($cachedir_temp);
790
-	if (!file_exists($cachedir_temp))
791
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
792
-
793
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
794
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
795
-	elseif (!isset($_GET['skiplang']))
837
+	if (!file_exists($cachedir_temp)) {
838
+			@mkdir($cachedir_temp);
839
+	}
840
+	if (!file_exists($cachedir_temp)) {
841
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
842
+	}
843
+
844
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
845
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
846
+	} elseif (!isset($_GET['skiplang']))
796 847
 	{
797 848
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
798 849
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
799 850
 
800
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
801
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
851
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
852
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
853
+		}
802 854
 	}
803 855
 
804
-	if (!makeFilesWritable($writable_files))
805
-		return false;
856
+	if (!makeFilesWritable($writable_files)) {
857
+			return false;
858
+	}
806 859
 
807 860
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
808
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
809
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
861
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
862
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
863
+	}
810 864
 
811 865
 	// Upgrade the agreement.
812 866
 	elseif (isset($modSettings['agreement']))
@@ -817,8 +871,8 @@  discard block
 block discarded – undo
817 871
 	}
818 872
 
819 873
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
820
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
821
-		$upcontext['warning'] = '
874
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
875
+			$upcontext['warning'] = '
822 876
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
823 877
 			<ul>
824 878
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -826,19 +880,23 @@  discard block
 block discarded – undo
826 880
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
827 881
 			</ul>
828 882
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
883
+	}
829 884
 
830 885
 	// Confirm mbstring is loaded...
831
-	if (!extension_loaded('mbstring'))
832
-		return throw_error($txt['install_no_mbstring']);
886
+	if (!extension_loaded('mbstring')) {
887
+			return throw_error($txt['install_no_mbstring']);
888
+	}
833 889
 
834 890
 	// Check for https stream support.
835 891
 	$supported_streams = stream_get_wrappers();
836
-	if (!in_array('https', $supported_streams))
837
-		$upcontext['custom_warning'] = $txt['install_no_https'];
892
+	if (!in_array('https', $supported_streams)) {
893
+			$upcontext['custom_warning'] = $txt['install_no_https'];
894
+	}
838 895
 
839 896
 	// Either we're logged in or we're going to present the login.
840
-	if (checkLogin())
841
-		return true;
897
+	if (checkLogin()) {
898
+			return true;
899
+	}
842 900
 
843 901
 	$upcontext += createToken('login');
844 902
 
@@ -852,15 +910,17 @@  discard block
 block discarded – undo
852 910
 	global $smcFunc, $db_type, $support_js;
853 911
 
854 912
 	// Don't bother if the security is disabled.
855
-	if ($disable_security)
856
-		return true;
913
+	if ($disable_security) {
914
+			return true;
915
+	}
857 916
 
858 917
 	// Are we trying to login?
859 918
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
860 919
 	{
861 920
 		// If we've disabled security pick a suitable name!
862
-		if (empty($_POST['user']))
863
-			$_POST['user'] = 'Administrator';
921
+		if (empty($_POST['user'])) {
922
+					$_POST['user'] = 'Administrator';
923
+		}
864 924
 
865 925
 		// Before 2.0 these column names were different!
866 926
 		$oldDB = false;
@@ -875,16 +935,17 @@  discard block
 block discarded – undo
875 935
 					'db_error_skip' => true,
876 936
 				)
877 937
 			);
878
-			if ($smcFunc['db_num_rows']($request) != 0)
879
-				$oldDB = true;
938
+			if ($smcFunc['db_num_rows']($request) != 0) {
939
+							$oldDB = true;
940
+			}
880 941
 			$smcFunc['db_free_result']($request);
881 942
 		}
882 943
 
883 944
 		// Get what we believe to be their details.
884 945
 		if (!$disable_security)
885 946
 		{
886
-			if ($oldDB)
887
-				$request = $smcFunc['db_query']('', '
947
+			if ($oldDB) {
948
+							$request = $smcFunc['db_query']('', '
888 949
 					SELECT id_member, memberName AS member_name, passwd, id_group,
889 950
 					additionalGroups AS additional_groups, lngfile
890 951
 					FROM {db_prefix}members
@@ -894,8 +955,8 @@  discard block
 block discarded – undo
894 955
 						'db_error_skip' => true,
895 956
 					)
896 957
 				);
897
-			else
898
-				$request = $smcFunc['db_query']('', '
958
+			} else {
959
+							$request = $smcFunc['db_query']('', '
899 960
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
900 961
 					FROM {db_prefix}members
901 962
 					WHERE member_name = {string:member_name}',
@@ -904,6 +965,7 @@  discard block
 block discarded – undo
904 965
 						'db_error_skip' => true,
905 966
 					)
906 967
 				);
968
+			}
907 969
 			if ($smcFunc['db_num_rows']($request) != 0)
908 970
 			{
909 971
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -911,16 +973,17 @@  discard block
 block discarded – undo
911 973
 				$groups = explode(',', $addGroups);
912 974
 				$groups[] = $id_group;
913 975
 
914
-				foreach ($groups as $k => $v)
915
-					$groups[$k] = (int) $v;
976
+				foreach ($groups as $k => $v) {
977
+									$groups[$k] = (int) $v;
978
+				}
916 979
 
917 980
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
918 981
 
919 982
 				// We don't use "-utf8" anymore...
920 983
 				$user_language = str_ireplace('-utf8', '', $user_language);
984
+			} else {
985
+							$upcontext['username_incorrect'] = true;
921 986
 			}
922
-			else
923
-				$upcontext['username_incorrect'] = true;
924 987
 			$smcFunc['db_free_result']($request);
925 988
 		}
926 989
 		$upcontext['username'] = $_POST['user'];
@@ -930,13 +993,14 @@  discard block
 block discarded – undo
930 993
 		{
931 994
 			$upcontext['upgrade_status']['js'] = 1;
932 995
 			$support_js = 1;
996
+		} else {
997
+					$support_js = 0;
933 998
 		}
934
-		else
935
-			$support_js = 0;
936 999
 
937 1000
 		// Note down the version we are coming from.
938
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
939
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
1001
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
1002
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
1003
+		}
940 1004
 
941 1005
 		// Didn't get anywhere?
942 1006
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -970,15 +1034,15 @@  discard block
 block discarded – undo
970 1034
 							'db_error_skip' => true,
971 1035
 						)
972 1036
 					);
973
-					if ($smcFunc['db_num_rows']($request) == 0)
974
-						return throw_error('You need to be an admin to perform an upgrade!');
1037
+					if ($smcFunc['db_num_rows']($request) == 0) {
1038
+											return throw_error('You need to be an admin to perform an upgrade!');
1039
+					}
975 1040
 					$smcFunc['db_free_result']($request);
976 1041
 				}
977 1042
 
978 1043
 				$upcontext['user']['id'] = $id_member;
979 1044
 				$upcontext['user']['name'] = $name;
980
-			}
981
-			else
1045
+			} else
982 1046
 			{
983 1047
 				$upcontext['user']['id'] = 1;
984 1048
 				$upcontext['user']['name'] = 'Administrator';
@@ -994,11 +1058,11 @@  discard block
 block discarded – undo
994 1058
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
995 1059
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
996 1060
 
997
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
998
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
999
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
1000
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1001
-				else
1061
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1062
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1063
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1064
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1065
+				} else
1002 1066
 				{
1003 1067
 					// Set this as the new language.
1004 1068
 					$upcontext['language'] = $user_language;
@@ -1042,8 +1106,9 @@  discard block
 block discarded – undo
1042 1106
 	unset($member_columns);
1043 1107
 
1044 1108
 	// If we've not submitted then we're done.
1045
-	if (empty($_POST['upcont']))
1046
-		return false;
1109
+	if (empty($_POST['upcont'])) {
1110
+			return false;
1111
+	}
1047 1112
 
1048 1113
 	// Firstly, if they're enabling SM stat collection just do it.
1049 1114
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1063,16 +1128,17 @@  discard block
 block discarded – undo
1063 1128
 				fwrite($fp, $out);
1064 1129
 
1065 1130
 				$return_data = '';
1066
-				while (!feof($fp))
1067
-					$return_data .= fgets($fp, 128);
1131
+				while (!feof($fp)) {
1132
+									$return_data .= fgets($fp, 128);
1133
+				}
1068 1134
 
1069 1135
 				fclose($fp);
1070 1136
 
1071 1137
 				// Get the unique site ID.
1072 1138
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1073 1139
 
1074
-				if (!empty($ID[1]))
1075
-					$smcFunc['db_insert']('replace',
1140
+				if (!empty($ID[1])) {
1141
+									$smcFunc['db_insert']('replace',
1076 1142
 						$db_prefix . 'settings',
1077 1143
 						array('variable' => 'string', 'value' => 'string'),
1078 1144
 						array(
@@ -1081,9 +1147,9 @@  discard block
 block discarded – undo
1081 1147
 						),
1082 1148
 						array('variable')
1083 1149
 					);
1150
+				}
1084 1151
 			}
1085
-		}
1086
-		else
1152
+		} else
1087 1153
 		{
1088 1154
 			$smcFunc['db_insert']('replace',
1089 1155
 				$db_prefix . 'settings',
@@ -1094,8 +1160,8 @@  discard block
 block discarded – undo
1094 1160
 		}
1095 1161
 	}
1096 1162
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1097
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1098
-		$smcFunc['db_query']('', '
1163
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1164
+			$smcFunc['db_query']('', '
1099 1165
 			DELETE FROM {db_prefix}settings
1100 1166
 			WHERE variable = {string:enable_sm_stats}',
1101 1167
 			array(
@@ -1103,6 +1169,7 @@  discard block
 block discarded – undo
1103 1169
 				'db_error_skip' => true,
1104 1170
 			)
1105 1171
 		);
1172
+	}
1106 1173
 
1107 1174
 	// Deleting old karma stuff?
1108 1175
 	if (!empty($_POST['delete_karma']))
@@ -1117,20 +1184,22 @@  discard block
 block discarded – undo
1117 1184
 		);
1118 1185
 
1119 1186
 		// Cleaning up old karma member settings.
1120
-		if ($upcontext['karma_installed']['good'])
1121
-			$smcFunc['db_query']('', '
1187
+		if ($upcontext['karma_installed']['good']) {
1188
+					$smcFunc['db_query']('', '
1122 1189
 				ALTER TABLE {db_prefix}members
1123 1190
 				DROP karma_good',
1124 1191
 				array()
1125 1192
 			);
1193
+		}
1126 1194
 
1127 1195
 		// Does karma bad was enable?
1128
-		if ($upcontext['karma_installed']['bad'])
1129
-			$smcFunc['db_query']('', '
1196
+		if ($upcontext['karma_installed']['bad']) {
1197
+					$smcFunc['db_query']('', '
1130 1198
 				ALTER TABLE {db_prefix}members
1131 1199
 				DROP karma_bad',
1132 1200
 				array()
1133 1201
 			);
1202
+		}
1134 1203
 
1135 1204
 		// Cleaning up old karma permissions.
1136 1205
 		$smcFunc['db_query']('', '
@@ -1148,32 +1217,37 @@  discard block
 block discarded – undo
1148 1217
 	}
1149 1218
 
1150 1219
 	// Emptying the error log?
1151
-	if (!empty($_POST['empty_error']))
1152
-		$smcFunc['db_query']('truncate_table', '
1220
+	if (!empty($_POST['empty_error'])) {
1221
+			$smcFunc['db_query']('truncate_table', '
1153 1222
 			TRUNCATE {db_prefix}log_errors',
1154 1223
 			array(
1155 1224
 			)
1156 1225
 		);
1226
+	}
1157 1227
 
1158 1228
 	$changes = array();
1159 1229
 
1160 1230
 	// Add proxy settings.
1161
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1162
-		$changes += array(
1231
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1232
+			$changes += array(
1163 1233
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1164 1234
 			'image_proxy_maxsize' => 5190,
1165 1235
 			'image_proxy_enabled' => 0,
1166 1236
 		);
1237
+	}
1167 1238
 
1168 1239
 	// If $boardurl reflects https, set force_ssl
1169
-	if (!function_exists('cache_put_data'))
1170
-		require_once($sourcedir . '/Load.php');
1171
-	if (stripos($boardurl, 'https://') !== false)
1172
-		updateSettings(array('force_ssl' => '1'));
1240
+	if (!function_exists('cache_put_data')) {
1241
+			require_once($sourcedir . '/Load.php');
1242
+	}
1243
+	if (stripos($boardurl, 'https://') !== false) {
1244
+			updateSettings(array('force_ssl' => '1'));
1245
+	}
1173 1246
 
1174 1247
 	// If we're overriding the language follow it through.
1175
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1176
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1248
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1249
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1250
+	}
1177 1251
 
1178 1252
 	if (!empty($_POST['maint']))
1179 1253
 	{
@@ -1185,26 +1259,29 @@  discard block
 block discarded – undo
1185 1259
 		{
1186 1260
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1187 1261
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1188
-		}
1189
-		else
1262
+		} else
1190 1263
 		{
1191 1264
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1192 1265
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1193 1266
 		}
1194 1267
 	}
1195 1268
 
1196
-	if ($command_line)
1197
-		echo ' * Updating Settings.php...';
1269
+	if ($command_line) {
1270
+			echo ' * Updating Settings.php...';
1271
+	}
1198 1272
 
1199 1273
 	// Fix some old paths.
1200
-	if (substr($boarddir, 0, 1) == '.')
1201
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1274
+	if (substr($boarddir, 0, 1) == '.') {
1275
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1276
+	}
1202 1277
 
1203
-	if (substr($sourcedir, 0, 1) == '.')
1204
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1278
+	if (substr($sourcedir, 0, 1) == '.') {
1279
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1280
+	}
1205 1281
 
1206
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1207
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1282
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1283
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1284
+	}
1208 1285
 
1209 1286
 	// If they have a "host:port" setup for the host, split that into separate values
1210 1287
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1215,32 +1292,36 @@  discard block
 block discarded – undo
1215 1292
 		$changes['db_server'] = '\'' . $db_server . '\'';
1216 1293
 
1217 1294
 		// Only set this if we're not using the default port
1218
-		if ($db_port != ini_get('mysqli.default_port'))
1219
-			$changes['db_port'] = (int) $db_port;
1220
-	}
1221
-	elseif (!empty($db_port))
1295
+		if ($db_port != ini_get('mysqli.default_port')) {
1296
+					$changes['db_port'] = (int) $db_port;
1297
+		}
1298
+	} elseif (!empty($db_port))
1222 1299
 	{
1223 1300
 		// If db_port is set and is the same as the default, set it to ''
1224 1301
 		if ($db_type == 'mysql')
1225 1302
 		{
1226
-			if ($db_port == ini_get('mysqli.default_port'))
1227
-				$changes['db_port'] = '\'\'';
1228
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1229
-				$changes['db_port'] = '\'\'';
1303
+			if ($db_port == ini_get('mysqli.default_port')) {
1304
+							$changes['db_port'] = '\'\'';
1305
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1306
+							$changes['db_port'] = '\'\'';
1307
+			}
1230 1308
 		}
1231 1309
 	}
1232 1310
 
1233 1311
 	// Maybe we haven't had this option yet?
1234
-	if (empty($packagesdir))
1235
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1312
+	if (empty($packagesdir)) {
1313
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1314
+	}
1236 1315
 
1237 1316
 	// Add support for $tasksdir var.
1238
-	if (empty($tasksdir))
1239
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1317
+	if (empty($tasksdir)) {
1318
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1319
+	}
1240 1320
 
1241 1321
 	// Make sure we fix the language as well.
1242
-	if (stristr($language, '-utf8'))
1243
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1322
+	if (stristr($language, '-utf8')) {
1323
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1324
+	}
1244 1325
 
1245 1326
 	// @todo Maybe change the cookie name if going to 1.1, too?
1246 1327
 
@@ -1251,8 +1332,9 @@  discard block
 block discarded – undo
1251 1332
 	// Tell Settings.php to store db_last_error.php in the cache
1252 1333
 	move_db_last_error_to_cachedir();
1253 1334
 
1254
-	if ($command_line)
1255
-		echo ' Successful.' . "\n";
1335
+	if ($command_line) {
1336
+			echo ' Successful.' . "\n";
1337
+	}
1256 1338
 
1257 1339
 	// Are we doing debug?
1258 1340
 	if (isset($_POST['debug']))
@@ -1262,8 +1344,9 @@  discard block
 block discarded – undo
1262 1344
 	}
1263 1345
 
1264 1346
 	// If we're not backing up then jump one.
1265
-	if (empty($_POST['backup']))
1266
-		$upcontext['current_step']++;
1347
+	if (empty($_POST['backup'])) {
1348
+			$upcontext['current_step']++;
1349
+	}
1267 1350
 
1268 1351
 	// If we've got here then let's proceed to the next step!
1269 1352
 	return true;
@@ -1278,8 +1361,9 @@  discard block
 block discarded – undo
1278 1361
 	$upcontext['page_title'] = $txt['backup_database'];
1279 1362
 
1280 1363
 	// Done it already - js wise?
1281
-	if (!empty($_POST['backup_done']))
1282
-		return true;
1364
+	if (!empty($_POST['backup_done'])) {
1365
+			return true;
1366
+	}
1283 1367
 
1284 1368
 	// Some useful stuff here.
1285 1369
 	db_extend();
@@ -1293,9 +1377,10 @@  discard block
 block discarded – undo
1293 1377
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1294 1378
 
1295 1379
 	$table_names = array();
1296
-	foreach ($tables as $table)
1297
-		if (substr($table, 0, 7) !== 'backup_')
1380
+	foreach ($tables as $table) {
1381
+			if (substr($table, 0, 7) !== 'backup_')
1298 1382
 			$table_names[] = $table;
1383
+	}
1299 1384
 
1300 1385
 	$upcontext['table_count'] = count($table_names);
1301 1386
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1305,12 +1390,14 @@  discard block
 block discarded – undo
1305 1390
 	$file_steps = $upcontext['table_count'];
1306 1391
 
1307 1392
 	// What ones have we already done?
1308
-	foreach ($table_names as $id => $table)
1309
-		if ($id < $_GET['substep'])
1393
+	foreach ($table_names as $id => $table) {
1394
+			if ($id < $_GET['substep'])
1310 1395
 			$upcontext['previous_tables'][] = $table;
1396
+	}
1311 1397
 
1312
-	if ($command_line)
1313
-		echo 'Backing Up Tables.';
1398
+	if ($command_line) {
1399
+			echo 'Backing Up Tables.';
1400
+	}
1314 1401
 
1315 1402
 	// If we don't support javascript we backup here.
1316 1403
 	if (!$support_js || isset($_GET['xml']))
@@ -1329,8 +1416,9 @@  discard block
 block discarded – undo
1329 1416
 			backupTable($table_names[$substep]);
1330 1417
 
1331 1418
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1332
-			if (isset($_GET['xml']))
1333
-				return upgradeExit();
1419
+			if (isset($_GET['xml'])) {
1420
+							return upgradeExit();
1421
+			}
1334 1422
 		}
1335 1423
 
1336 1424
 		if ($command_line)
@@ -1363,9 +1451,10 @@  discard block
 block discarded – undo
1363 1451
 
1364 1452
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1365 1453
 
1366
-	if ($command_line)
1367
-		echo ' done.';
1368
-}
1454
+	if ($command_line) {
1455
+			echo ' done.';
1456
+	}
1457
+	}
1369 1458
 
1370 1459
 // Step 2: Everything.
1371 1460
 function DatabaseChanges()
@@ -1374,8 +1463,9 @@  discard block
 block discarded – undo
1374 1463
 	global $upcontext, $support_js, $db_type;
1375 1464
 
1376 1465
 	// Have we just completed this?
1377
-	if (!empty($_POST['database_done']))
1378
-		return true;
1466
+	if (!empty($_POST['database_done'])) {
1467
+			return true;
1468
+	}
1379 1469
 
1380 1470
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1381 1471
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1390,15 +1480,16 @@  discard block
 block discarded – undo
1390 1480
 	);
1391 1481
 
1392 1482
 	// How many files are there in total?
1393
-	if (isset($_GET['filecount']))
1394
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1395
-	else
1483
+	if (isset($_GET['filecount'])) {
1484
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1485
+	} else
1396 1486
 	{
1397 1487
 		$upcontext['file_count'] = 0;
1398 1488
 		foreach ($files as $file)
1399 1489
 		{
1400
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1401
-				$upcontext['file_count']++;
1490
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1491
+							$upcontext['file_count']++;
1492
+			}
1402 1493
 		}
1403 1494
 	}
1404 1495
 
@@ -1408,9 +1499,9 @@  discard block
 block discarded – undo
1408 1499
 	$upcontext['cur_file_num'] = 0;
1409 1500
 	foreach ($files as $file)
1410 1501
 	{
1411
-		if ($did_not_do)
1412
-			$did_not_do--;
1413
-		else
1502
+		if ($did_not_do) {
1503
+					$did_not_do--;
1504
+		} else
1414 1505
 		{
1415 1506
 			$upcontext['cur_file_num']++;
1416 1507
 			$upcontext['cur_file_name'] = $file[0];
@@ -1437,12 +1528,13 @@  discard block
 block discarded – undo
1437 1528
 					// Flag to move on to the next.
1438 1529
 					$upcontext['completed_step'] = true;
1439 1530
 					// Did we complete the whole file?
1440
-					if ($nextFile)
1441
-						$upcontext['current_debug_item_num'] = -1;
1531
+					if ($nextFile) {
1532
+											$upcontext['current_debug_item_num'] = -1;
1533
+					}
1442 1534
 					return upgradeExit();
1535
+				} elseif ($support_js) {
1536
+									break;
1443 1537
 				}
1444
-				elseif ($support_js)
1445
-					break;
1446 1538
 			}
1447 1539
 			// Set the progress bar to be right as if we had - even if we hadn't...
1448 1540
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1468,8 +1560,9 @@  discard block
 block discarded – undo
1468 1560
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt;
1469 1561
 
1470 1562
 	// Now it's nice to have some of the basic SMF source files.
1471
-	if (!isset($_GET['ssi']) && !$command_line)
1472
-		redirectLocation('&ssi=1');
1563
+	if (!isset($_GET['ssi']) && !$command_line) {
1564
+			redirectLocation('&ssi=1');
1565
+	}
1473 1566
 
1474 1567
 	$upcontext['sub_template'] = 'upgrade_complete';
1475 1568
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1485,14 +1578,16 @@  discard block
 block discarded – undo
1485 1578
 	// Are we in maintenance mode?
1486 1579
 	if (isset($upcontext['user']['main']))
1487 1580
 	{
1488
-		if ($command_line)
1489
-			echo ' * ';
1581
+		if ($command_line) {
1582
+					echo ' * ';
1583
+		}
1490 1584
 		$upcontext['removed_maintenance'] = true;
1491 1585
 		$changes['maintenance'] = $upcontext['user']['main'];
1492 1586
 	}
1493 1587
 	// Otherwise if somehow we are in 2 let's go to 1.
1494
-	elseif (!empty($maintenance) && $maintenance == 2)
1495
-		$changes['maintenance'] = 1;
1588
+	elseif (!empty($maintenance) && $maintenance == 2) {
1589
+			$changes['maintenance'] = 1;
1590
+	}
1496 1591
 
1497 1592
 	// Wipe this out...
1498 1593
 	$upcontext['user'] = array();
@@ -1507,9 +1602,9 @@  discard block
 block discarded – undo
1507 1602
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1508 1603
 
1509 1604
 	// Now is the perfect time to fetch the SM files.
1510
-	if ($command_line)
1511
-		cli_scheduled_fetchSMfiles();
1512
-	else
1605
+	if ($command_line) {
1606
+			cli_scheduled_fetchSMfiles();
1607
+	} else
1513 1608
 	{
1514 1609
 		require_once($sourcedir . '/ScheduledTasks.php');
1515 1610
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1517,8 +1612,9 @@  discard block
 block discarded – undo
1517 1612
 	}
1518 1613
 
1519 1614
 	// Log what we've done.
1520
-	if (empty($user_info['id']))
1521
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1615
+	if (empty($user_info['id'])) {
1616
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1617
+	}
1522 1618
 
1523 1619
 	// Log the action manually, so CLI still works.
1524 1620
 	$smcFunc['db_insert']('',
@@ -1537,8 +1633,9 @@  discard block
 block discarded – undo
1537 1633
 
1538 1634
 	// Save the current database version.
1539 1635
 	$server_version = $smcFunc['db_server_info']();
1540
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1541
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1636
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1637
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1638
+	}
1542 1639
 
1543 1640
 	if ($command_line)
1544 1641
 	{
@@ -1550,8 +1647,9 @@  discard block
 block discarded – undo
1550 1647
 
1551 1648
 	// Make sure it says we're done.
1552 1649
 	$upcontext['overall_percent'] = 100;
1553
-	if (isset($upcontext['step_progress']))
1554
-		unset($upcontext['step_progress']);
1650
+	if (isset($upcontext['step_progress'])) {
1651
+			unset($upcontext['step_progress']);
1652
+	}
1555 1653
 
1556 1654
 	$_GET['substep'] = 0;
1557 1655
 	return false;
@@ -1562,8 +1660,9 @@  discard block
 block discarded – undo
1562 1660
 {
1563 1661
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1564 1662
 
1565
-	if (empty($modSettings['time_format']))
1566
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1663
+	if (empty($modSettings['time_format'])) {
1664
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1665
+	}
1567 1666
 
1568 1667
 	// What files do we want to get
1569 1668
 	$request = $smcFunc['db_query']('', '
@@ -1597,8 +1696,9 @@  discard block
 block discarded – undo
1597 1696
 		$file_data = fetch_web_data($url);
1598 1697
 
1599 1698
 		// If we got an error - give up - the site might be down.
1600
-		if ($file_data === false)
1601
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1699
+		if ($file_data === false) {
1700
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1701
+		}
1602 1702
 
1603 1703
 		// Save the file to the database.
1604 1704
 		$smcFunc['db_query']('substring', '
@@ -1640,8 +1740,9 @@  discard block
 block discarded – undo
1640 1740
 	$themeData = array();
1641 1741
 	foreach ($values as $variable => $value)
1642 1742
 	{
1643
-		if (!isset($value) || $value === null)
1644
-			$value = 0;
1743
+		if (!isset($value) || $value === null) {
1744
+					$value = 0;
1745
+		}
1645 1746
 
1646 1747
 		$themeData[] = array(0, 1, $variable, $value);
1647 1748
 	}
@@ -1670,8 +1771,9 @@  discard block
 block discarded – undo
1670 1771
 
1671 1772
 	foreach ($values as $variable => $value)
1672 1773
 	{
1673
-		if (empty($modSettings[$value[0]]))
1674
-			continue;
1774
+		if (empty($modSettings[$value[0]])) {
1775
+					continue;
1776
+		}
1675 1777
 
1676 1778
 		$smcFunc['db_query']('', '
1677 1779
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1757,19 +1859,21 @@  discard block
 block discarded – undo
1757 1859
 	set_error_handler(
1758 1860
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1759 1861
 		{
1760
-			if ($support_js)
1761
-				return true;
1762
-			else
1763
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1862
+			if ($support_js) {
1863
+							return true;
1864
+			} else {
1865
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1866
+			}
1764 1867
 		}
1765 1868
 	);
1766 1869
 
1767 1870
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1768 1871
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1769
-	if ($db_type == 'mysql')
1770
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1771
-	else
1772
-		$db_collation = '';
1872
+	if ($db_type == 'mysql') {
1873
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1874
+	} else {
1875
+			$db_collation = '';
1876
+	}
1773 1877
 
1774 1878
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1775 1879
 
@@ -1781,8 +1885,9 @@  discard block
 block discarded – undo
1781 1885
 	$last_step = '';
1782 1886
 
1783 1887
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1784
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1785
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1888
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1889
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1890
+	}
1786 1891
 
1787 1892
 	// Count the total number of steps within this file - for progress.
1788 1893
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1802,15 +1907,18 @@  discard block
 block discarded – undo
1802 1907
 		$do_current = $substep >= $_GET['substep'];
1803 1908
 
1804 1909
 		// Get rid of any comments in the beginning of the line...
1805
-		if (substr(trim($line), 0, 2) === '/*')
1806
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1910
+		if (substr(trim($line), 0, 2) === '/*') {
1911
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1912
+		}
1807 1913
 
1808 1914
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1809
-		if ($is_debug && !$support_js && $command_line)
1810
-			flush();
1915
+		if ($is_debug && !$support_js && $command_line) {
1916
+					flush();
1917
+		}
1811 1918
 
1812
-		if (trim($line) === '')
1813
-			continue;
1919
+		if (trim($line) === '') {
1920
+					continue;
1921
+		}
1814 1922
 
1815 1923
 		if (trim(substr($line, 0, 3)) === '---')
1816 1924
 		{
@@ -1820,8 +1928,9 @@  discard block
 block discarded – undo
1820 1928
 			if (trim($current_data) != '' && $type !== '}')
1821 1929
 			{
1822 1930
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1823
-				if ($command_line)
1824
-					echo $upcontext['error_message'];
1931
+				if ($command_line) {
1932
+									echo $upcontext['error_message'];
1933
+				}
1825 1934
 			}
1826 1935
 
1827 1936
 			if ($type == ' ')
@@ -1839,17 +1948,18 @@  discard block
 block discarded – undo
1839 1948
 				if ($do_current)
1840 1949
 				{
1841 1950
 					$upcontext['actioned_items'][] = $last_step;
1842
-					if ($command_line)
1843
-						echo ' * ';
1951
+					if ($command_line) {
1952
+											echo ' * ';
1953
+					}
1844 1954
 				}
1845
-			}
1846
-			elseif ($type == '#')
1955
+			} elseif ($type == '#')
1847 1956
 			{
1848 1957
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1849 1958
 
1850 1959
 				$upcontext['current_debug_item_num']++;
1851
-				if (trim($line) != '---#')
1852
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1960
+				if (trim($line) != '---#') {
1961
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1962
+				}
1853 1963
 
1854 1964
 				// Have we already done something?
1855 1965
 				if (isset($_GET['xml']) && $done_something)
@@ -1860,34 +1970,36 @@  discard block
 block discarded – undo
1860 1970
 
1861 1971
 				if ($do_current)
1862 1972
 				{
1863
-					if (trim($line) == '---#' && $command_line)
1864
-						echo ' done.', $endl;
1865
-					elseif ($command_line)
1866
-						echo ' +++ ', rtrim(substr($line, 4));
1867
-					elseif (trim($line) != '---#')
1973
+					if (trim($line) == '---#' && $command_line) {
1974
+											echo ' done.', $endl;
1975
+					} elseif ($command_line) {
1976
+											echo ' +++ ', rtrim(substr($line, 4));
1977
+					} elseif (trim($line) != '---#')
1868 1978
 					{
1869
-						if ($is_debug)
1870
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1979
+						if ($is_debug) {
1980
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1981
+						}
1871 1982
 					}
1872 1983
 				}
1873 1984
 
1874 1985
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1875 1986
 				{
1876
-					if ($command_line)
1877
-						echo ' * ';
1878
-					else
1879
-						$upcontext['actioned_items'][] = $last_step;
1987
+					if ($command_line) {
1988
+											echo ' * ';
1989
+					} else {
1990
+											$upcontext['actioned_items'][] = $last_step;
1991
+					}
1880 1992
 				}
1881 1993
 
1882 1994
 				// Small step - only if we're actually doing stuff.
1883
-				if ($do_current)
1884
-					nextSubstep(++$substep);
1885
-				else
1886
-					$substep++;
1887
-			}
1888
-			elseif ($type == '{')
1889
-				$current_type = 'code';
1890
-			elseif ($type == '}')
1995
+				if ($do_current) {
1996
+									nextSubstep(++$substep);
1997
+				} else {
1998
+									$substep++;
1999
+				}
2000
+			} elseif ($type == '{') {
2001
+							$current_type = 'code';
2002
+			} elseif ($type == '}')
1891 2003
 			{
1892 2004
 				$current_type = 'sql';
1893 2005
 
@@ -1900,8 +2012,9 @@  discard block
 block discarded – undo
1900 2012
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1901 2013
 				{
1902 2014
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1903
-					if ($command_line)
1904
-						echo $upcontext['error_message'];
2015
+					if ($command_line) {
2016
+											echo $upcontext['error_message'];
2017
+					}
1905 2018
 				}
1906 2019
 
1907 2020
 				// Done with code!
@@ -1988,8 +2101,9 @@  discard block
 block discarded – undo
1988 2101
 	$db_unbuffered = false;
1989 2102
 
1990 2103
 	// Failure?!
1991
-	if ($result !== false)
1992
-		return $result;
2104
+	if ($result !== false) {
2105
+			return $result;
2106
+	}
1993 2107
 
1994 2108
 	$db_error_message = $smcFunc['db_error']($db_connection);
1995 2109
 	// If MySQL we do something more clever.
@@ -2017,54 +2131,61 @@  discard block
 block discarded – undo
2017 2131
 			{
2018 2132
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2019 2133
 				$result = mysqli_query($db_connection, $string);
2020
-				if ($result !== false)
2021
-					return $result;
2134
+				if ($result !== false) {
2135
+									return $result;
2136
+				}
2022 2137
 			}
2023
-		}
2024
-		elseif ($mysqli_errno == 2013)
2138
+		} elseif ($mysqli_errno == 2013)
2025 2139
 		{
2026 2140
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2027 2141
 			mysqli_select_db($db_connection, $db_name);
2028 2142
 			if ($db_connection)
2029 2143
 			{
2030 2144
 				$result = mysqli_query($db_connection, $string);
2031
-				if ($result !== false)
2032
-					return $result;
2145
+				if ($result !== false) {
2146
+									return $result;
2147
+				}
2033 2148
 			}
2034 2149
 		}
2035 2150
 		// Duplicate column name... should be okay ;).
2036
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2037
-			return false;
2151
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2152
+					return false;
2153
+		}
2038 2154
 		// Duplicate insert... make sure it's the proper type of query ;).
2039
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2040
-			return false;
2155
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2156
+					return false;
2157
+		}
2041 2158
 		// Creating an index on a non-existent column.
2042
-		elseif ($mysqli_errno == 1072)
2043
-			return false;
2044
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2045
-			return false;
2159
+		elseif ($mysqli_errno == 1072) {
2160
+					return false;
2161
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2162
+					return false;
2163
+		}
2046 2164
 	}
2047 2165
 	// If a table already exists don't go potty.
2048 2166
 	else
2049 2167
 	{
2050 2168
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2051 2169
 		{
2052
-			if (strpos($db_error_message, 'exist') !== false)
2053
-				return true;
2054
-		}
2055
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2170
+			if (strpos($db_error_message, 'exist') !== false) {
2171
+							return true;
2172
+			}
2173
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2056 2174
 		{
2057
-			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error)
2058
-				return true;
2175
+			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) {
2176
+							return true;
2177
+			}
2059 2178
 		}
2060 2179
 	}
2061 2180
 
2062 2181
 	// Get the query string so we pass everything.
2063 2182
 	$query_string = '';
2064
-	foreach ($_GET as $k => $v)
2065
-		$query_string .= ';' . $k . '=' . $v;
2066
-	if (strlen($query_string) != 0)
2067
-		$query_string = '?' . substr($query_string, 1);
2183
+	foreach ($_GET as $k => $v) {
2184
+			$query_string .= ';' . $k . '=' . $v;
2185
+	}
2186
+	if (strlen($query_string) != 0) {
2187
+			$query_string = '?' . substr($query_string, 1);
2188
+	}
2068 2189
 
2069 2190
 	if ($command_line)
2070 2191
 	{
@@ -2119,16 +2240,18 @@  discard block
 block discarded – undo
2119 2240
 			{
2120 2241
 				$found |= 1;
2121 2242
 				// Do some checks on the data if we have it set.
2122
-				if (isset($change['col_type']))
2123
-					$found &= $change['col_type'] === $column['type'];
2124
-				if (isset($change['null_allowed']))
2125
-					$found &= $column['null'] == $change['null_allowed'];
2126
-				if (isset($change['default']))
2127
-					$found &= $change['default'] === $column['default'];
2243
+				if (isset($change['col_type'])) {
2244
+									$found &= $change['col_type'] === $column['type'];
2245
+				}
2246
+				if (isset($change['null_allowed'])) {
2247
+									$found &= $column['null'] == $change['null_allowed'];
2248
+				}
2249
+				if (isset($change['default'])) {
2250
+									$found &= $change['default'] === $column['default'];
2251
+				}
2128 2252
 			}
2129 2253
 		}
2130
-	}
2131
-	elseif ($change['type'] === 'index')
2254
+	} elseif ($change['type'] === 'index')
2132 2255
 	{
2133 2256
 		$request = upgrade_query('
2134 2257
 			SHOW INDEX
@@ -2137,9 +2260,10 @@  discard block
 block discarded – undo
2137 2260
 		{
2138 2261
 			$cur_index = array();
2139 2262
 
2140
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2141
-				if ($row['Key_name'] === $change['name'])
2263
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2264
+							if ($row['Key_name'] === $change['name'])
2142 2265
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2266
+			}
2143 2267
 
2144 2268
 			ksort($cur_index, SORT_NUMERIC);
2145 2269
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2149,14 +2273,17 @@  discard block
 block discarded – undo
2149 2273
 	}
2150 2274
 
2151 2275
 	// If we're trying to add and it's added, we're done.
2152
-	if ($found && in_array($change['method'], array('add', 'change')))
2153
-		return true;
2276
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2277
+			return true;
2278
+	}
2154 2279
 	// Otherwise if we're removing and it wasn't found we're also done.
2155
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2156
-		return true;
2280
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2281
+			return true;
2282
+	}
2157 2283
 	// Otherwise is it just a test?
2158
-	elseif ($is_test)
2159
-		return false;
2284
+	elseif ($is_test) {
2285
+			return false;
2286
+	}
2160 2287
 
2161 2288
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2162 2289
 	$running = false;
@@ -2167,8 +2294,9 @@  discard block
 block discarded – undo
2167 2294
 			SHOW FULL PROCESSLIST');
2168 2295
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2169 2296
 		{
2170
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2171
-				$found = true;
2297
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2298
+							$found = true;
2299
+			}
2172 2300
 		}
2173 2301
 
2174 2302
 		// Can't find it? Then we need to run it fools!
@@ -2180,8 +2308,9 @@  discard block
 block discarded – undo
2180 2308
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2181 2309
 				' . $change['text'], true) !== false;
2182 2310
 
2183
-			if (!$success)
2184
-				return false;
2311
+			if (!$success) {
2312
+							return false;
2313
+			}
2185 2314
 
2186 2315
 			// Return
2187 2316
 			$running = true;
@@ -2223,8 +2352,9 @@  discard block
 block discarded – undo
2223 2352
 			'db_error_skip' => true,
2224 2353
 		)
2225 2354
 	);
2226
-	if ($smcFunc['db_num_rows']($request) === 0)
2227
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2355
+	if ($smcFunc['db_num_rows']($request) === 0) {
2356
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2357
+	}
2228 2358
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2229 2359
 	$smcFunc['db_free_result']($request);
2230 2360
 
@@ -2246,18 +2376,19 @@  discard block
 block discarded – undo
2246 2376
 			)
2247 2377
 		);
2248 2378
 		// No results? Just forget it all together.
2249
-		if ($smcFunc['db_num_rows']($request) === 0)
2250
-			unset($table_row['Collation']);
2251
-		else
2252
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2379
+		if ($smcFunc['db_num_rows']($request) === 0) {
2380
+					unset($table_row['Collation']);
2381
+		} else {
2382
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2383
+		}
2253 2384
 		$smcFunc['db_free_result']($request);
2254 2385
 	}
2255 2386
 
2256 2387
 	if ($column_fix)
2257 2388
 	{
2258 2389
 		// Make sure there are no NULL's left.
2259
-		if ($null_fix)
2260
-			$smcFunc['db_query']('', '
2390
+		if ($null_fix) {
2391
+					$smcFunc['db_query']('', '
2261 2392
 				UPDATE {db_prefix}' . $change['table'] . '
2262 2393
 				SET ' . $change['column'] . ' = {string:default}
2263 2394
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2266,6 +2397,7 @@  discard block
 block discarded – undo
2266 2397
 					'db_error_skip' => true,
2267 2398
 				)
2268 2399
 			);
2400
+		}
2269 2401
 
2270 2402
 		// Do the actual alteration.
2271 2403
 		$smcFunc['db_query']('', '
@@ -2294,8 +2426,9 @@  discard block
 block discarded – undo
2294 2426
 	}
2295 2427
 
2296 2428
 	// Not a column we need to check on?
2297
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2298
-		return;
2429
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2430
+			return;
2431
+	}
2299 2432
 
2300 2433
 	// Break it up you (six|seven).
2301 2434
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2314,13 +2447,13 @@  discard block
 block discarded – undo
2314 2447
 				'new_name' => $temp[2],
2315 2448
 		));
2316 2449
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2317
-		if ($smcFunc['db_num_rows'] != 1)
2318
-			return;
2450
+		if ($smcFunc['db_num_rows'] != 1) {
2451
+					return;
2452
+		}
2319 2453
 
2320 2454
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2321 2455
 		$smcFunc['db_free_result']($request);
2322
-	}
2323
-	else
2456
+	} else
2324 2457
 	{
2325 2458
 		// Do this the old fashion, sure method way.
2326 2459
 		$request = $smcFunc['db_query']('', '
@@ -2331,21 +2464,24 @@  discard block
 block discarded – undo
2331 2464
 		));
2332 2465
 		// Mayday!
2333 2466
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2334
-		if ($smcFunc['db_num_rows'] == 0)
2335
-			return;
2467
+		if ($smcFunc['db_num_rows'] == 0) {
2468
+					return;
2469
+		}
2336 2470
 
2337 2471
 		// Oh where, oh where has my little field gone. Oh where can it be...
2338
-		while ($row = $smcFunc['db_query']($request))
2339
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2472
+		while ($row = $smcFunc['db_query']($request)) {
2473
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2340 2474
 			{
2341 2475
 				$current_type = $row['Type'];
2476
+		}
2342 2477
 				break;
2343 2478
 			}
2344 2479
 	}
2345 2480
 
2346 2481
 	// If this doesn't match, the column may of been altered for a reason.
2347
-	if (trim($current_type) != trim($temp[3]))
2348
-		$temp[3] = $current_type;
2482
+	if (trim($current_type) != trim($temp[3])) {
2483
+			$temp[3] = $current_type;
2484
+	}
2349 2485
 
2350 2486
 	// Piece this back together.
2351 2487
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2357,8 +2493,9 @@  discard block
 block discarded – undo
2357 2493
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2358 2494
 	global $step_progress, $is_debug, $upcontext;
2359 2495
 
2360
-	if ($_GET['substep'] < $substep)
2361
-		$_GET['substep'] = $substep;
2496
+	if ($_GET['substep'] < $substep) {
2497
+			$_GET['substep'] = $substep;
2498
+	}
2362 2499
 
2363 2500
 	if ($command_line)
2364 2501
 	{
@@ -2371,29 +2508,33 @@  discard block
 block discarded – undo
2371 2508
 	}
2372 2509
 
2373 2510
 	@set_time_limit(300);
2374
-	if (function_exists('apache_reset_timeout'))
2375
-		@apache_reset_timeout();
2511
+	if (function_exists('apache_reset_timeout')) {
2512
+			@apache_reset_timeout();
2513
+	}
2376 2514
 
2377
-	if (time() - $start_time <= $timeLimitThreshold)
2378
-		return;
2515
+	if (time() - $start_time <= $timeLimitThreshold) {
2516
+			return;
2517
+	}
2379 2518
 
2380 2519
 	// Do we have some custom step progress stuff?
2381 2520
 	if (!empty($step_progress))
2382 2521
 	{
2383 2522
 		$upcontext['substep_progress'] = 0;
2384 2523
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2385
-		if ($step_progress['current'] > $step_progress['total'])
2386
-			$upcontext['substep_progress'] = 99.9;
2387
-		else
2388
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2524
+		if ($step_progress['current'] > $step_progress['total']) {
2525
+					$upcontext['substep_progress'] = 99.9;
2526
+		} else {
2527
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2528
+		}
2389 2529
 
2390 2530
 		// Make it nicely rounded.
2391 2531
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2392 2532
 	}
2393 2533
 
2394 2534
 	// If this is XML we just exit right away!
2395
-	if (isset($_GET['xml']))
2396
-		return upgradeExit();
2535
+	if (isset($_GET['xml'])) {
2536
+			return upgradeExit();
2537
+	}
2397 2538
 
2398 2539
 	// We're going to pause after this!
2399 2540
 	$upcontext['pause'] = true;
@@ -2401,13 +2542,15 @@  discard block
 block discarded – undo
2401 2542
 	$upcontext['query_string'] = '';
2402 2543
 	foreach ($_GET as $k => $v)
2403 2544
 	{
2404
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2405
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2545
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2546
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2547
+		}
2406 2548
 	}
2407 2549
 
2408 2550
 	// Custom warning?
2409
-	if (!empty($custom_warning))
2410
-		$upcontext['custom_warning'] = $custom_warning;
2551
+	if (!empty($custom_warning)) {
2552
+			$upcontext['custom_warning'] = $custom_warning;
2553
+	}
2411 2554
 
2412 2555
 	upgradeExit();
2413 2556
 }
@@ -2422,25 +2565,26 @@  discard block
 block discarded – undo
2422 2565
 	ob_implicit_flush(true);
2423 2566
 	@set_time_limit(600);
2424 2567
 
2425
-	if (!isset($_SERVER['argv']))
2426
-		$_SERVER['argv'] = array();
2568
+	if (!isset($_SERVER['argv'])) {
2569
+			$_SERVER['argv'] = array();
2570
+	}
2427 2571
 	$_GET['maint'] = 1;
2428 2572
 
2429 2573
 	foreach ($_SERVER['argv'] as $i => $arg)
2430 2574
 	{
2431
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2432
-			$_GET['lang'] = $match[1];
2433
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2434
-			continue;
2435
-		elseif ($arg == '--no-maintenance')
2436
-			$_GET['maint'] = 0;
2437
-		elseif ($arg == '--debug')
2438
-			$is_debug = true;
2439
-		elseif ($arg == '--backup')
2440
-			$_POST['backup'] = 1;
2441
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2442
-			$_GET['conv'] = 1;
2443
-		elseif ($i != 0)
2575
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2576
+					$_GET['lang'] = $match[1];
2577
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2578
+					continue;
2579
+		} elseif ($arg == '--no-maintenance') {
2580
+					$_GET['maint'] = 0;
2581
+		} elseif ($arg == '--debug') {
2582
+					$is_debug = true;
2583
+		} elseif ($arg == '--backup') {
2584
+					$_POST['backup'] = 1;
2585
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2586
+					$_GET['conv'] = 1;
2587
+		} elseif ($i != 0)
2444 2588
 		{
2445 2589
 			echo 'SMF Command-line Upgrader
2446 2590
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2454,10 +2598,12 @@  discard block
 block discarded – undo
2454 2598
 		}
2455 2599
 	}
2456 2600
 
2457
-	if (!php_version_check())
2458
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2459
-	if (!db_version_check())
2460
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2601
+	if (!php_version_check()) {
2602
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2603
+	}
2604
+	if (!db_version_check()) {
2605
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2606
+	}
2461 2607
 
2462 2608
 	// Do some checks to make sure they have proper privileges
2463 2609
 	db_extend('packages');
@@ -2472,34 +2618,39 @@  discard block
 block discarded – undo
2472 2618
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2473 2619
 
2474 2620
 	// Sorry... we need CREATE, ALTER and DROP
2475
-	if (!$create || !$alter || !$drop)
2476
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2621
+	if (!$create || !$alter || !$drop) {
2622
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2623
+	}
2477 2624
 
2478 2625
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2479 2626
 		&& @file_exists($sourcedir . '/QueryString.php')
2480 2627
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2481
-	if (!$check && !isset($modSettings['smfVersion']))
2482
-		print_error('Error: Some files are missing or out-of-date.', true);
2628
+	if (!$check && !isset($modSettings['smfVersion'])) {
2629
+			print_error('Error: Some files are missing or out-of-date.', true);
2630
+	}
2483 2631
 
2484 2632
 	// Do a quick version spot check.
2485 2633
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2486 2634
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2487
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2488
-		print_error('Error: Some files have not yet been updated properly.');
2635
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2636
+			print_error('Error: Some files have not yet been updated properly.');
2637
+	}
2489 2638
 
2490 2639
 	// Make sure Settings.php is writable.
2491 2640
 	quickFileWritable($boarddir . '/Settings.php');
2492
-	if (!is_writable($boarddir . '/Settings.php'))
2493
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2641
+	if (!is_writable($boarddir . '/Settings.php')) {
2642
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2643
+	}
2494 2644
 
2495 2645
 	// Make sure Settings_bak.php is writable.
2496 2646
 	quickFileWritable($boarddir . '/Settings_bak.php');
2497
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2498
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2647
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2648
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2649
+	}
2499 2650
 
2500
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2501
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2502
-	elseif (isset($modSettings['agreement']))
2651
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2652
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2653
+	} elseif (isset($modSettings['agreement']))
2503 2654
 	{
2504 2655
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2505 2656
 		fwrite($fp, $modSettings['agreement']);
@@ -2509,36 +2660,42 @@  discard block
 block discarded – undo
2509 2660
 	// Make sure Themes is writable.
2510 2661
 	quickFileWritable($modSettings['theme_dir']);
2511 2662
 
2512
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2513
-		print_error('Error: Unable to obtain write access to "Themes".');
2663
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2664
+			print_error('Error: Unable to obtain write access to "Themes".');
2665
+	}
2514 2666
 
2515 2667
 	// Make sure cache directory exists and is writable!
2516 2668
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2517
-	if (!file_exists($cachedir_temp))
2518
-		@mkdir($cachedir_temp);
2669
+	if (!file_exists($cachedir_temp)) {
2670
+			@mkdir($cachedir_temp);
2671
+	}
2519 2672
 
2520 2673
 	// Make sure the cache temp dir is writable.
2521 2674
 	quickFileWritable($cachedir_temp);
2522 2675
 
2523
-	if (!is_writable($cachedir_temp))
2524
-		print_error('Error: Unable to obtain write access to "cache".', true);
2676
+	if (!is_writable($cachedir_temp)) {
2677
+			print_error('Error: Unable to obtain write access to "cache".', true);
2678
+	}
2525 2679
 
2526 2680
 	// Make sure db_last_error.php is writable.
2527 2681
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2528
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2529
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2682
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2683
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2684
+	}
2530 2685
 
2531
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2532
-		print_error('Error: Unable to find language files!', true);
2533
-	else
2686
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2687
+			print_error('Error: Unable to find language files!', true);
2688
+	} else
2534 2689
 	{
2535 2690
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2536 2691
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2537 2692
 
2538
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2539
-			print_error('Error: Language files out of date.', true);
2540
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2541
-			print_error('Error: Install language is missing for selected language.', true);
2693
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2694
+					print_error('Error: Language files out of date.', true);
2695
+		}
2696
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2697
+					print_error('Error: Install language is missing for selected language.', true);
2698
+		}
2542 2699
 
2543 2700
 		// Otherwise include it!
2544 2701
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2558,8 +2715,9 @@  discard block
 block discarded – undo
2558 2715
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2559 2716
 
2560 2717
 	// Done it already?
2561
-	if (!empty($_POST['utf8_done']))
2562
-		return true;
2718
+	if (!empty($_POST['utf8_done'])) {
2719
+			return true;
2720
+	}
2563 2721
 
2564 2722
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2565 2723
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2572,8 +2730,7 @@  discard block
 block discarded – undo
2572 2730
 		);
2573 2731
 
2574 2732
 		return true;
2575
-	}
2576
-	else
2733
+	} else
2577 2734
 	{
2578 2735
 		$upcontext['page_title'] = $txt['converting_utf8'];
2579 2736
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2617,8 +2774,9 @@  discard block
 block discarded – undo
2617 2774
 			)
2618 2775
 		);
2619 2776
 		$db_charsets = array();
2620
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2621
-			$db_charsets[] = $row['Charset'];
2777
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2778
+					$db_charsets[] = $row['Charset'];
2779
+		}
2622 2780
 
2623 2781
 		$smcFunc['db_free_result']($request);
2624 2782
 
@@ -2654,13 +2812,15 @@  discard block
 block discarded – undo
2654 2812
 		// If there's a fulltext index, we need to drop it first...
2655 2813
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2656 2814
 		{
2657
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2658
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2815
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2816
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2659 2817
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2818
+			}
2660 2819
 			$smcFunc['db_free_result']($request);
2661 2820
 
2662
-			if (isset($upcontext['fulltext_index']))
2663
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2821
+			if (isset($upcontext['fulltext_index'])) {
2822
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2823
+			}
2664 2824
 		}
2665 2825
 
2666 2826
 		// Drop it and make a note...
@@ -2850,8 +3010,9 @@  discard block
 block discarded – undo
2850 3010
 			$replace = '%field%';
2851 3011
 
2852 3012
 			// Build a huge REPLACE statement...
2853
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2854
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3013
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3014
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3015
+			}
2855 3016
 		}
2856 3017
 
2857 3018
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2861,9 +3022,10 @@  discard block
 block discarded – undo
2861 3022
 		$upcontext['table_count'] = count($queryTables);
2862 3023
 
2863 3024
 		// What ones have we already done?
2864
-		foreach ($queryTables as $id => $table)
2865
-			if ($id < $_GET['substep'])
3025
+		foreach ($queryTables as $id => $table) {
3026
+					if ($id < $_GET['substep'])
2866 3027
 				$upcontext['previous_tables'][] = $table;
3028
+		}
2867 3029
 
2868 3030
 		$upcontext['cur_table_num'] = $_GET['substep'];
2869 3031
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2900,8 +3062,9 @@  discard block
 block discarded – undo
2900 3062
 			nextSubstep($substep);
2901 3063
 
2902 3064
 			// Just to make sure it doesn't time out.
2903
-			if (function_exists('apache_reset_timeout'))
2904
-				@apache_reset_timeout();
3065
+			if (function_exists('apache_reset_timeout')) {
3066
+							@apache_reset_timeout();
3067
+			}
2905 3068
 
2906 3069
 			$table_charsets = array();
2907 3070
 
@@ -2924,8 +3087,9 @@  discard block
 block discarded – undo
2924 3087
 
2925 3088
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2926 3089
 						if ($charset != 'utf8') {
2927
-							if (!isset($table_charsets[$charset]))
2928
-								$table_charsets[$charset] = array();
3090
+							if (!isset($table_charsets[$charset])) {
3091
+															$table_charsets[$charset] = array();
3092
+							}
2929 3093
 
2930 3094
 							$table_charsets[$charset][] = $column_info;
2931 3095
 						}
@@ -2966,10 +3130,11 @@  discard block
 block discarded – undo
2966 3130
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2967 3131
 				{
2968 3132
 					$update = '';
2969
-					foreach ($table_charsets as $charset => $columns)
2970
-						foreach ($columns as $column)
3133
+					foreach ($table_charsets as $charset => $columns) {
3134
+											foreach ($columns as $column)
2971 3135
 							$update .= '
2972 3136
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3137
+					}
2973 3138
 
2974 3139
 					$smcFunc['db_query']('', '
2975 3140
 						UPDATE {raw:table_name}
@@ -2994,8 +3159,9 @@  discard block
 block discarded – undo
2994 3159
 			// Now do the actual conversion (if still needed).
2995 3160
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2996 3161
 			{
2997
-				if ($command_line)
2998
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3162
+				if ($command_line) {
3163
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3164
+				}
2999 3165
 
3000 3166
 				$smcFunc['db_query']('', '
3001 3167
 					ALTER TABLE {raw:table_name}
@@ -3005,12 +3171,14 @@  discard block
 block discarded – undo
3005 3171
 					)
3006 3172
 				);
3007 3173
 
3008
-				if ($command_line)
3009
-					echo " done.\n";
3174
+				if ($command_line) {
3175
+									echo " done.\n";
3176
+				}
3010 3177
 			}
3011 3178
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3012
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
3013
-				return upgradeExit();
3179
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3180
+							return upgradeExit();
3181
+			}
3014 3182
 		}
3015 3183
 
3016 3184
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3039,8 +3207,8 @@  discard block
 block discarded – undo
3039 3207
 		);
3040 3208
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3041 3209
 		{
3042
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
3043
-				$smcFunc['db_query']('', '
3210
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3211
+							$smcFunc['db_query']('', '
3044 3212
 					UPDATE {db_prefix}log_actions
3045 3213
 					SET extra = {string:extra}
3046 3214
 					WHERE id_action = {int:current_action}',
@@ -3049,6 +3217,7 @@  discard block
 block discarded – undo
3049 3217
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3050 3218
 					)
3051 3219
 				);
3220
+			}
3052 3221
 		}
3053 3222
 		$smcFunc['db_free_result']($request);
3054 3223
 
@@ -3070,15 +3239,17 @@  discard block
 block discarded – undo
3070 3239
 	// First thing's first - did we already do this?
3071 3240
 	if (!empty($modSettings['json_done']))
3072 3241
 	{
3073
-		if ($command_line)
3074
-			return DeleteUpgrade();
3075
-		else
3076
-			return true;
3242
+		if ($command_line) {
3243
+					return DeleteUpgrade();
3244
+		} else {
3245
+					return true;
3246
+		}
3077 3247
 	}
3078 3248
 
3079 3249
 	// Done it already - js wise?
3080
-	if (!empty($_POST['json_done']))
3081
-		return true;
3250
+	if (!empty($_POST['json_done'])) {
3251
+			return true;
3252
+	}
3082 3253
 
3083 3254
 	// List of tables affected by this function
3084 3255
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3110,12 +3281,14 @@  discard block
 block discarded – undo
3110 3281
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3111 3282
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3112 3283
 
3113
-	foreach ($keys as $id => $table)
3114
-		if ($id < $_GET['substep'])
3284
+	foreach ($keys as $id => $table) {
3285
+			if ($id < $_GET['substep'])
3115 3286
 			$upcontext['previous_tables'][] = $table;
3287
+	}
3116 3288
 
3117
-	if ($command_line)
3118
-		echo 'Converting data from serialize() to json_encode().';
3289
+	if ($command_line) {
3290
+			echo 'Converting data from serialize() to json_encode().';
3291
+	}
3119 3292
 
3120 3293
 	if (!$support_js || isset($_GET['xml']))
3121 3294
 	{
@@ -3155,8 +3328,9 @@  discard block
 block discarded – undo
3155 3328
 
3156 3329
 				// Loop through and fix these...
3157 3330
 				$new_settings = array();
3158
-				if ($command_line)
3159
-					echo "\n" . 'Fixing some settings...';
3331
+				if ($command_line) {
3332
+									echo "\n" . 'Fixing some settings...';
3333
+				}
3160 3334
 
3161 3335
 				foreach ($serialized_settings as $var)
3162 3336
 				{
@@ -3164,22 +3338,24 @@  discard block
 block discarded – undo
3164 3338
 					{
3165 3339
 						// Attempt to unserialize the setting
3166 3340
 						$temp = @safe_unserialize($modSettings[$var]);
3167
-						if (!$temp && $command_line)
3168
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3169
-						elseif ($temp !== false)
3170
-							$new_settings[$var] = json_encode($temp);
3341
+						if (!$temp && $command_line) {
3342
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3343
+						} elseif ($temp !== false) {
3344
+													$new_settings[$var] = json_encode($temp);
3345
+						}
3171 3346
 					}
3172 3347
 				}
3173 3348
 
3174 3349
 				// Update everything at once
3175
-				if (!function_exists('cache_put_data'))
3176
-					require_once($sourcedir . '/Load.php');
3350
+				if (!function_exists('cache_put_data')) {
3351
+									require_once($sourcedir . '/Load.php');
3352
+				}
3177 3353
 				updateSettings($new_settings, true);
3178 3354
 
3179
-				if ($command_line)
3180
-					echo ' done.';
3181
-			}
3182
-			elseif ($table == 'themes')
3355
+				if ($command_line) {
3356
+									echo ' done.';
3357
+				}
3358
+			} elseif ($table == 'themes')
3183 3359
 			{
3184 3360
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3185 3361
 				$query = $smcFunc['db_query']('', '
@@ -3198,10 +3374,11 @@  discard block
 block discarded – undo
3198 3374
 
3199 3375
 						if ($command_line)
3200 3376
 						{
3201
-							if ($temp === false)
3202
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3203
-							else
3204
-								echo "\n" . 'Fixing admin preferences...';
3377
+							if ($temp === false) {
3378
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3379
+							} else {
3380
+															echo "\n" . 'Fixing admin preferences...';
3381
+							}
3205 3382
 						}
3206 3383
 
3207 3384
 						if ($temp !== false)
@@ -3223,15 +3400,15 @@  discard block
 block discarded – undo
3223 3400
 								)
3224 3401
 							);
3225 3402
 
3226
-							if ($command_line)
3227
-								echo ' done.';
3403
+							if ($command_line) {
3404
+															echo ' done.';
3405
+							}
3228 3406
 						}
3229 3407
 					}
3230 3408
 
3231 3409
 					$smcFunc['db_free_result']($query);
3232 3410
 				}
3233
-			}
3234
-			else
3411
+			} else
3235 3412
 			{
3236 3413
 				// First item is always the key...
3237 3414
 				$key = $info[0];
@@ -3242,8 +3419,7 @@  discard block
 block discarded – undo
3242 3419
 				{
3243 3420
 					$col_select = $info[1];
3244 3421
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3245
-				}
3246
-				else
3422
+				} else
3247 3423
 				{
3248 3424
 					$col_select = implode(', ', $info);
3249 3425
 				}
@@ -3276,8 +3452,7 @@  discard block
 block discarded – undo
3276 3452
 								if ($temp === false && $command_line)
3277 3453
 								{
3278 3454
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3279
-								}
3280
-								else
3455
+								} else
3281 3456
 								{
3282 3457
 									$row[$col] = json_encode($temp);
3283 3458
 
@@ -3302,16 +3477,18 @@  discard block
 block discarded – undo
3302 3477
 						}
3303 3478
 					}
3304 3479
 
3305
-					if ($command_line)
3306
-						echo ' done.';
3480
+					if ($command_line) {
3481
+											echo ' done.';
3482
+					}
3307 3483
 
3308 3484
 					// Free up some memory...
3309 3485
 					$smcFunc['db_free_result']($query);
3310 3486
 				}
3311 3487
 			}
3312 3488
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3313
-			if (isset($_GET['xml']))
3314
-				return upgradeExit();
3489
+			if (isset($_GET['xml'])) {
3490
+							return upgradeExit();
3491
+			}
3315 3492
 		}
3316 3493
 
3317 3494
 		if ($command_line)
@@ -3326,8 +3503,9 @@  discard block
 block discarded – undo
3326 3503
 
3327 3504
 		$_GET['substep'] = 0;
3328 3505
 		// Make sure we move on!
3329
-		if ($command_line)
3330
-			return DeleteUpgrade();
3506
+		if ($command_line) {
3507
+					return DeleteUpgrade();
3508
+		}
3331 3509
 
3332 3510
 		return true;
3333 3511
 	}
@@ -3384,14 +3562,16 @@  discard block
 block discarded – undo
3384 3562
 	global $upcontext, $txt, $settings;
3385 3563
 
3386 3564
 	// Don't call me twice!
3387
-	if (!empty($upcontext['chmod_called']))
3388
-		return;
3565
+	if (!empty($upcontext['chmod_called'])) {
3566
+			return;
3567
+	}
3389 3568
 
3390 3569
 	$upcontext['chmod_called'] = true;
3391 3570
 
3392 3571
 	// Nothing?
3393
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3394
-		return;
3572
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3573
+			return;
3574
+	}
3395 3575
 
3396 3576
 	// Was it a problem with Windows?
3397 3577
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3423,11 +3603,12 @@  discard block
 block discarded – undo
3423 3603
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3424 3604
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3425 3605
 
3426
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3427
-		echo '
3606
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3607
+			echo '
3428 3608
 					content.write(\'<hr>\n\t\t\t\');
3429 3609
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3430 3610
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3611
+	}
3431 3612
 
3432 3613
 	echo '
3433 3614
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3435,17 +3616,19 @@  discard block
 block discarded – undo
3435 3616
 				}
3436 3617
 			</script>';
3437 3618
 
3438
-	if (!empty($upcontext['chmod']['ftp_error']))
3439
-		echo '
3619
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3620
+			echo '
3440 3621
 			<div class="error_message red">
3441 3622
 				', $txt['upgrade_ftp_error'], '<br><br>
3442 3623
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3443 3624
 			</div>
3444 3625
 			<br>';
3626
+	}
3445 3627
 
3446
-	if (empty($upcontext['chmod_in_form']))
3447
-		echo '
3628
+	if (empty($upcontext['chmod_in_form'])) {
3629
+			echo '
3448 3630
 	<form action="', $upcontext['form_url'], '" method="post">';
3631
+	}
3449 3632
 
3450 3633
 	echo '
3451 3634
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3480,10 +3663,11 @@  discard block
 block discarded – undo
3480 3663
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3481 3664
 	</div>';
3482 3665
 
3483
-	if (empty($upcontext['chmod_in_form']))
3484
-		echo '
3666
+	if (empty($upcontext['chmod_in_form'])) {
3667
+			echo '
3485 3668
 	</form>';
3486
-}
3669
+	}
3670
+	}
3487 3671
 
3488 3672
 function template_upgrade_above()
3489 3673
 {
@@ -3543,9 +3727,10 @@  discard block
 block discarded – undo
3543 3727
 				<h2>', $txt['upgrade_progress'], '</h2>
3544 3728
 				<ul>';
3545 3729
 
3546
-	foreach ($upcontext['steps'] as $num => $step)
3547
-		echo '
3730
+	foreach ($upcontext['steps'] as $num => $step) {
3731
+			echo '
3548 3732
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3733
+	}
3549 3734
 
3550 3735
 	echo '
3551 3736
 					</ul>
@@ -3558,8 +3743,8 @@  discard block
 block discarded – undo
3558 3743
 				</div>
3559 3744
 			</div>';
3560 3745
 
3561
-	if (isset($upcontext['step_progress']))
3562
-		echo '
3746
+	if (isset($upcontext['step_progress'])) {
3747
+			echo '
3563 3748
 				<br>
3564 3749
 				<br>
3565 3750
 				<div id="progress_bar_step">
@@ -3568,6 +3753,7 @@  discard block
 block discarded – undo
3568 3753
 						<span>', $txt['upgrade_step_progress'], '</span>
3569 3754
 					</div>
3570 3755
 				</div>';
3756
+	}
3571 3757
 
3572 3758
 	echo '
3573 3759
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3598,32 +3784,36 @@  discard block
 block discarded – undo
3598 3784
 {
3599 3785
 	global $upcontext, $txt;
3600 3786
 
3601
-	if (!empty($upcontext['pause']))
3602
-		echo '
3787
+	if (!empty($upcontext['pause'])) {
3788
+			echo '
3603 3789
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3604 3790
 
3605 3791
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3606 3792
 								<h3>
3607 3793
 									', $txt['upgrade_paused_overload'], '
3608 3794
 								</h3>';
3795
+	}
3609 3796
 
3610
-	if (!empty($upcontext['custom_warning']))
3611
-		echo '
3797
+	if (!empty($upcontext['custom_warning'])) {
3798
+			echo '
3612 3799
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3613 3800
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3614 3801
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3615 3802
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3616 3803
 								</div>';
3804
+	}
3617 3805
 
3618 3806
 	echo '
3619 3807
 								<div class="righttext" style="margin: 1ex;">';
3620 3808
 
3621
-	if (!empty($upcontext['continue']))
3622
-		echo '
3809
+	if (!empty($upcontext['continue'])) {
3810
+			echo '
3623 3811
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3624
-	if (!empty($upcontext['skip']))
3625
-		echo '
3812
+	}
3813
+	if (!empty($upcontext['skip'])) {
3814
+			echo '
3626 3815
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3816
+	}
3627 3817
 
3628 3818
 	echo '
3629 3819
 								</div>
@@ -3673,11 +3863,12 @@  discard block
 block discarded – undo
3673 3863
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3674 3864
 	<smf>';
3675 3865
 
3676
-	if (!empty($upcontext['get_data']))
3677
-		foreach ($upcontext['get_data'] as $k => $v)
3866
+	if (!empty($upcontext['get_data'])) {
3867
+			foreach ($upcontext['get_data'] as $k => $v)
3678 3868
 			echo '
3679 3869
 		<get key="', $k, '">', $v, '</get>';
3680
-}
3870
+	}
3871
+	}
3681 3872
 
3682 3873
 function template_xml_below()
3683 3874
 {
@@ -3718,8 +3909,8 @@  discard block
 block discarded – undo
3718 3909
 	template_chmod();
3719 3910
 
3720 3911
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3721
-	if ($upcontext['is_large_forum'])
3722
-		echo '
3912
+	if ($upcontext['is_large_forum']) {
3913
+			echo '
3723 3914
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3724 3915
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3725 3916
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3727,10 +3918,11 @@  discard block
 block discarded – undo
3727 3918
 				', $txt['upgrade_warning_lots_data'], '
3728 3919
 			</div>
3729 3920
 		</div>';
3921
+	}
3730 3922
 
3731 3923
 	// A warning message?
3732
-	if (!empty($upcontext['warning']))
3733
-		echo '
3924
+	if (!empty($upcontext['warning'])) {
3925
+			echo '
3734 3926
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3735 3927
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3736 3928
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3738,6 +3930,7 @@  discard block
 block discarded – undo
3738 3930
 				', $upcontext['warning'], '
3739 3931
 			</div>
3740 3932
 		</div>';
3933
+	}
3741 3934
 
3742 3935
 	// Paths are incorrect?
3743 3936
 	echo '
@@ -3753,20 +3946,22 @@  discard block
 block discarded – undo
3753 3946
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3754 3947
 	{
3755 3948
 		$ago = time() - $upcontext['started'];
3756
-		if ($ago < 60)
3757
-			$ago = $ago . ' seconds';
3758
-		elseif ($ago < 3600)
3759
-			$ago = (int) ($ago / 60) . ' minutes';
3760
-		else
3761
-			$ago = (int) ($ago / 3600) . ' hours';
3949
+		if ($ago < 60) {
3950
+					$ago = $ago . ' seconds';
3951
+		} elseif ($ago < 3600) {
3952
+					$ago = (int) ($ago / 60) . ' minutes';
3953
+		} else {
3954
+					$ago = (int) ($ago / 3600) . ' hours';
3955
+		}
3762 3956
 
3763 3957
 		$active = time() - $upcontext['updated'];
3764
-		if ($active < 60)
3765
-			$updated = $active . ' seconds';
3766
-		elseif ($active < 3600)
3767
-			$updated = (int) ($active / 60) . ' minutes';
3768
-		else
3769
-			$updated = (int) ($active / 3600) . ' hours';
3958
+		if ($active < 60) {
3959
+					$updated = $active . ' seconds';
3960
+		} elseif ($active < 3600) {
3961
+					$updated = (int) ($active / 60) . ' minutes';
3962
+		} else {
3963
+					$updated = (int) ($active / 3600) . ' hours';
3964
+		}
3770 3965
 
3771 3966
 		echo '
3772 3967
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3775,16 +3970,18 @@  discard block
 block discarded – undo
3775 3970
 			<div style="padding-left: 6ex;">
3776 3971
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3777 3972
 
3778
-		if ($active < 600)
3779
-			echo '
3973
+		if ($active < 600) {
3974
+					echo '
3780 3975
 				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '';
3976
+		}
3781 3977
 
3782
-		if ($active > $upcontext['inactive_timeout'])
3783
-			echo '
3978
+		if ($active > $upcontext['inactive_timeout']) {
3979
+					echo '
3784 3980
 				<br><br>',$txt['upgrade_run'], '';
3785
-		else
3786
-			echo '
3981
+		} else {
3982
+					echo '
3787 3983
 				<br><br>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3984
+		}
3788 3985
 
3789 3986
 		echo '
3790 3987
 			</div>
@@ -3800,9 +3997,10 @@  discard block
 block discarded – undo
3800 3997
 					<td>
3801 3998
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3802 3999
 
3803
-	if (!empty($upcontext['username_incorrect']))
3804
-		echo '
4000
+	if (!empty($upcontext['username_incorrect'])) {
4001
+			echo '
3805 4002
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>';
4003
+	}
3806 4004
 
3807 4005
 	echo '
3808 4006
 					</td>
@@ -3813,9 +4011,10 @@  discard block
 block discarded – undo
3813 4011
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3814 4012
 						<input type="hidden" name="hash_passwrd" value="">';
3815 4013
 
3816
-	if (!empty($upcontext['password_failed']))
3817
-		echo '
4014
+	if (!empty($upcontext['password_failed'])) {
4015
+			echo '
3818 4016
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>';
4017
+	}
3819 4018
 
3820 4019
 	echo '
3821 4020
 					</td>
@@ -3886,8 +4085,8 @@  discard block
 block discarded – undo
3886 4085
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3887 4086
 
3888 4087
 	// Warning message?
3889
-	if (!empty($upcontext['upgrade_options_warning']))
3890
-		echo '
4088
+	if (!empty($upcontext['upgrade_options_warning'])) {
4089
+			echo '
3891 4090
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3892 4091
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3893 4092
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3895,6 +4094,7 @@  discard block
 block discarded – undo
3895 4094
 				', $upcontext['upgrade_options_warning'], '
3896 4095
 			</div>
3897 4096
 		</div>';
4097
+	}
3898 4098
 
3899 4099
 	echo '
3900 4100
 				<table>
@@ -3937,8 +4137,8 @@  discard block
 block discarded – undo
3937 4137
 						</td>
3938 4138
 					</tr>';
3939 4139
 
3940
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3941
-		echo '
4140
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4141
+			echo '
3942 4142
 					<tr valign="top">
3943 4143
 						<td width="2%">
3944 4144
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3947,6 +4147,7 @@  discard block
 block discarded – undo
3947 4147
 							<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3948 4148
 						</td>
3949 4149
 					</tr>';
4150
+	}
3950 4151
 
3951 4152
 	echo '
3952 4153
 					<tr valign="top">
@@ -3984,10 +4185,11 @@  discard block
 block discarded – undo
3984 4185
 			</div>';
3985 4186
 
3986 4187
 	// Dont any tables so far?
3987
-	if (!empty($upcontext['previous_tables']))
3988
-		foreach ($upcontext['previous_tables'] as $table)
4188
+	if (!empty($upcontext['previous_tables'])) {
4189
+			foreach ($upcontext['previous_tables'] as $table)
3989 4190
 			echo '
3990 4191
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4192
+	}
3991 4193
 
3992 4194
 	echo '
3993 4195
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4024,12 +4226,13 @@  discard block
 block discarded – undo
4024 4226
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4025 4227
 
4026 4228
 		// If debug flood the screen.
4027
-		if ($is_debug)
4028
-			echo '
4229
+		if ($is_debug) {
4230
+					echo '
4029 4231
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4030 4232
 
4031 4233
 				if (document.getElementById(\'debug_section\').scrollHeight)
4032 4234
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4235
+		}
4033 4236
 
4034 4237
 		echo '
4035 4238
 				// Get the next update...
@@ -4062,8 +4265,9 @@  discard block
 block discarded – undo
4062 4265
 {
4063 4266
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4064 4267
 
4065
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4066
-		$is_debug = true;
4268
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4269
+			$is_debug = true;
4270
+	}
4067 4271
 
4068 4272
 	echo '
4069 4273
 		<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4078,8 +4282,9 @@  discard block
 block discarded – undo
4078 4282
 	{
4079 4283
 		foreach ($upcontext['actioned_items'] as $num => $item)
4080 4284
 		{
4081
-			if ($num != 0)
4082
-				echo ' Successful!';
4285
+			if ($num != 0) {
4286
+							echo ' Successful!';
4287
+			}
4083 4288
 			echo '<br>' . $item;
4084 4289
 		}
4085 4290
 		if (!empty($upcontext['changes_complete']))
@@ -4092,28 +4297,32 @@  discard block
 block discarded – undo
4092 4297
 				$seconds = intval($active % 60);
4093 4298
 
4094 4299
 				$totalTime = '';
4095
-				if ($hours > 0)
4096
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4097
-				if ($minutes > 0)
4098
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4099
-				if ($seconds > 0)
4100
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4300
+				if ($hours > 0) {
4301
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4302
+				}
4303
+				if ($minutes > 0) {
4304
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4305
+				}
4306
+				if ($seconds > 0) {
4307
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4308
+				}
4101 4309
 			}
4102 4310
 
4103
-			if ($is_debug && !empty($totalTime))
4104
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4105
-			else
4106
-				echo ' Successful!<br><br>';
4311
+			if ($is_debug && !empty($totalTime)) {
4312
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4313
+			} else {
4314
+							echo ' Successful!<br><br>';
4315
+			}
4107 4316
 
4108 4317
 			echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>';
4109 4318
 		}
4110
-	}
4111
-	else
4319
+	} else
4112 4320
 	{
4113 4321
 		// Tell them how many files we have in total.
4114
-		if ($upcontext['file_count'] > 1)
4115
-			echo '
4322
+		if ($upcontext['file_count'] > 1) {
4323
+					echo '
4116 4324
 		<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4325
+		}
4117 4326
 
4118 4327
 		echo '
4119 4328
 		<h3 id="info2"><strong>', $txt['upgrade_executing'], '</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> ', $txt['upgrade_of'], ' <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -4129,19 +4338,23 @@  discard block
 block discarded – undo
4129 4338
 				$seconds = intval($active % 60);
4130 4339
 
4131 4340
 				$totalTime = '';
4132
-				if ($hours > 0)
4133
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4134
-				if ($minutes > 0)
4135
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4136
-				if ($seconds > 0)
4137
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4341
+				if ($hours > 0) {
4342
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4343
+				}
4344
+				if ($minutes > 0) {
4345
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4346
+				}
4347
+				if ($seconds > 0) {
4348
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4349
+				}
4138 4350
 			}
4139 4351
 
4140 4352
 			echo '
4141 4353
 			<br><span id="upgradeCompleted">';
4142 4354
 
4143
-			if (!empty($totalTime))
4144
-				echo 'Completed in ', $totalTime, '<br>';
4355
+			if (!empty($totalTime)) {
4356
+							echo 'Completed in ', $totalTime, '<br>';
4357
+			}
4145 4358
 
4146 4359
 			echo '</span>
4147 4360
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4178,9 +4391,10 @@  discard block
 block discarded – undo
4178 4391
 			var getData = "";
4179 4392
 			var debugItems = ', $upcontext['debug_items'], ';';
4180 4393
 
4181
-		if ($is_debug)
4182
-			echo '
4394
+		if ($is_debug) {
4395
+					echo '
4183 4396
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4397
+		}
4184 4398
 
4185 4399
 		echo '
4186 4400
 			function getNextItem()
@@ -4220,9 +4434,10 @@  discard block
 block discarded – undo
4220 4434
 						document.getElementById("error_block").style.display = "";
4221 4435
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4222 4436
 
4223
-	if ($is_debug)
4224
-		echo '
4437
+	if ($is_debug) {
4438
+			echo '
4225 4439
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4440
+	}
4226 4441
 
4227 4442
 	echo '
4228 4443
 					}
@@ -4243,9 +4458,10 @@  discard block
 block discarded – undo
4243 4458
 						document.getElementById("error_block").style.display = "";
4244 4459
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4245 4460
 
4246
-	if ($is_debug)
4247
-		echo '
4461
+	if ($is_debug) {
4462
+			echo '
4248 4463
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4464
+	}
4249 4465
 
4250 4466
 	echo '
4251 4467
 					}
@@ -4304,8 +4520,8 @@  discard block
 block discarded – undo
4304 4520
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4305 4521
 				{';
4306 4522
 
4307
-		if ($is_debug)
4308
-			echo '
4523
+		if ($is_debug) {
4524
+					echo '
4309 4525
 					document.getElementById(\'debug_section\').style.display = "none";
4310 4526
 
4311 4527
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4323,6 +4539,7 @@  discard block
 block discarded – undo
4323 4539
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4324 4540
 
4325 4541
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4542
+		}
4326 4543
 
4327 4544
 		echo '
4328 4545
 
@@ -4330,9 +4547,10 @@  discard block
 block discarded – undo
4330 4547
 					document.getElementById(\'contbutt\').disabled = 0;
4331 4548
 					document.getElementById(\'database_done\').value = 1;';
4332 4549
 
4333
-		if ($upcontext['file_count'] > 1)
4334
-			echo '
4550
+		if ($upcontext['file_count'] > 1) {
4551
+					echo '
4335 4552
 					document.getElementById(\'info1\').style.display = "none";';
4553
+		}
4336 4554
 
4337 4555
 		echo '
4338 4556
 					document.getElementById(\'info2\').style.display = "none";
@@ -4345,9 +4563,10 @@  discard block
 block discarded – undo
4345 4563
 					lastItem = 0;
4346 4564
 					prevFile = curFile;';
4347 4565
 
4348
-		if ($is_debug)
4349
-			echo '
4566
+		if ($is_debug) {
4567
+					echo '
4350 4568
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4569
+		}
4351 4570
 
4352 4571
 		echo '
4353 4572
 					getNextItem();
@@ -4355,8 +4574,8 @@  discard block
 block discarded – undo
4355 4574
 				}';
4356 4575
 
4357 4576
 		// If debug scroll the screen.
4358
-		if ($is_debug)
4359
-			echo '
4577
+		if ($is_debug) {
4578
+					echo '
4360 4579
 				if (iLastSubStepProgress == -1)
4361 4580
 				{
4362 4581
 					// Give it consistent dots.
@@ -4375,6 +4594,7 @@  discard block
 block discarded – undo
4375 4594
 
4376 4595
 				if (document.getElementById(\'debug_section\').scrollHeight)
4377 4596
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4597
+		}
4378 4598
 
4379 4599
 		echo '
4380 4600
 				// Update the page.
@@ -4435,9 +4655,10 @@  discard block
 block discarded – undo
4435 4655
 			}';
4436 4656
 
4437 4657
 		// Start things off assuming we've not errored.
4438
-		if (empty($upcontext['error_message']))
4439
-			echo '
4658
+		if (empty($upcontext['error_message'])) {
4659
+					echo '
4440 4660
 			getNextItem();';
4661
+		}
4441 4662
 
4442 4663
 		echo '
4443 4664
 		//# sourceURL=dynamicScript-dbch.js
@@ -4455,18 +4676,21 @@  discard block
 block discarded – undo
4455 4676
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4456 4677
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4457 4678
 
4458
-	if (!empty($upcontext['error_message']))
4459
-		echo '
4679
+	if (!empty($upcontext['error_message'])) {
4680
+			echo '
4460 4681
 	<error>', $upcontext['error_message'], '</error>';
4682
+	}
4461 4683
 
4462
-	if (!empty($upcontext['error_string']))
4463
-		echo '
4684
+	if (!empty($upcontext['error_string'])) {
4685
+			echo '
4464 4686
 	<sql>', $upcontext['error_string'], '</sql>';
4687
+	}
4465 4688
 
4466
-	if ($is_debug)
4467
-		echo '
4689
+	if ($is_debug) {
4690
+			echo '
4468 4691
 	<curtime>', time(), '</curtime>';
4469
-}
4692
+	}
4693
+	}
4470 4694
 
4471 4695
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4472 4696
 function template_convert_utf8()
@@ -4485,18 +4709,20 @@  discard block
 block discarded – undo
4485 4709
 			</div>';
4486 4710
 
4487 4711
 	// Done any tables so far?
4488
-	if (!empty($upcontext['previous_tables']))
4489
-		foreach ($upcontext['previous_tables'] as $table)
4712
+	if (!empty($upcontext['previous_tables'])) {
4713
+			foreach ($upcontext['previous_tables'] as $table)
4490 4714
 			echo '
4491 4715
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4716
+	}
4492 4717
 
4493 4718
 	echo '
4494 4719
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4495 4720
 
4496 4721
 	// If we dropped their index, let's let them know
4497
-	if ($upcontext['dropping_index'])
4498
-		echo '
4722
+	if ($upcontext['dropping_index']) {
4723
+			echo '
4499 4724
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</span>';
4725
+	}
4500 4726
 
4501 4727
 	// Completion notification
4502 4728
 	echo '
@@ -4533,12 +4759,13 @@  discard block
 block discarded – undo
4533 4759
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4534 4760
 
4535 4761
 		// If debug flood the screen.
4536
-		if ($is_debug)
4537
-			echo '
4762
+		if ($is_debug) {
4763
+					echo '
4538 4764
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4539 4765
 
4540 4766
 				if (document.getElementById(\'debug_section\').scrollHeight)
4541 4767
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4768
+		}
4542 4769
 
4543 4770
 		echo '
4544 4771
 				// Get the next update...
@@ -4586,19 +4813,21 @@  discard block
 block discarded – undo
4586 4813
 			</div>';
4587 4814
 
4588 4815
 	// Dont any tables so far?
4589
-	if (!empty($upcontext['previous_tables']))
4590
-		foreach ($upcontext['previous_tables'] as $table)
4816
+	if (!empty($upcontext['previous_tables'])) {
4817
+			foreach ($upcontext['previous_tables'] as $table)
4591 4818
 			echo '
4592 4819
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4820
+	}
4593 4821
 
4594 4822
 	echo '
4595 4823
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4596 4824
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>';
4597 4825
 
4598 4826
 	// Try to make sure substep was reset.
4599
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4600
-		echo '
4827
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4828
+			echo '
4601 4829
 			<input type="hidden" name="substep" id="substep" value="0">';
4830
+	}
4602 4831
 
4603 4832
 	// Continue please!
4604 4833
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4631,12 +4860,13 @@  discard block
 block discarded – undo
4631 4860
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4632 4861
 
4633 4862
 		// If debug flood the screen.
4634
-		if ($is_debug)
4635
-			echo '
4863
+		if ($is_debug) {
4864
+					echo '
4636 4865
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4637 4866
 
4638 4867
 				if (document.getElementById(\'debug_section\').scrollHeight)
4639 4868
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4869
+		}
4640 4870
 
4641 4871
 		echo '
4642 4872
 				// Get the next update...
@@ -4672,8 +4902,8 @@  discard block
 block discarded – undo
4672 4902
 	<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4673 4903
 	<form action="', $boardurl, '/index.php">';
4674 4904
 
4675
-	if (!empty($upcontext['can_delete_script']))
4676
-		echo '
4905
+	if (!empty($upcontext['can_delete_script'])) {
4906
+			echo '
4677 4907
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> <em>', $txt['upgrade_delete_server'], '</em>
4678 4908
 			<script>
4679 4909
 				function doTheDelete(theCheck)
@@ -4685,6 +4915,7 @@  discard block
 block discarded – undo
4685 4915
 				}
4686 4916
 			</script>
4687 4917
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4918
+	}
4688 4919
 
4689 4920
 	$active = time() - $upcontext['started'];
4690 4921
 	$hours = floor($active / 3600);
@@ -4694,16 +4925,20 @@  discard block
 block discarded – undo
4694 4925
 	if ($is_debug)
4695 4926
 	{
4696 4927
 		$totalTime = '';
4697
-		if ($hours > 0)
4698
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4699
-		if ($minutes > 0)
4700
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4701
-		if ($seconds > 0)
4702
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4928
+		if ($hours > 0) {
4929
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4930
+		}
4931
+		if ($minutes > 0) {
4932
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4933
+		}
4934
+		if ($seconds > 0) {
4935
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4936
+		}
4703 4937
 	}
4704 4938
 
4705
-	if ($is_debug && !empty($totalTime))
4706
-		echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4939
+	if ($is_debug && !empty($totalTime)) {
4940
+			echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4941
+	}
4707 4942
 
4708 4943
 	echo '<br>
4709 4944
 			', sprintf($txt['upgrade_problems'], 'http://simplemachines.org'), '<br>
@@ -4730,8 +4965,9 @@  discard block
 block discarded – undo
4730 4965
 
4731 4966
 	$current_substep = $_GET['substep'];
4732 4967
 
4733
-	if (empty($_GET['a']))
4734
-		$_GET['a'] = 0;
4968
+	if (empty($_GET['a'])) {
4969
+			$_GET['a'] = 0;
4970
+	}
4735 4971
 	$step_progress['name'] = 'Converting ips';
4736 4972
 	$step_progress['current'] = $_GET['a'];
4737 4973
 
@@ -4774,16 +5010,19 @@  discard block
 block discarded – undo
4774 5010
 				'empty' => '',
4775 5011
 				'limit' => $limit,
4776 5012
 		));
4777
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4778
-			$arIp[] = $row[$oldCol];
5013
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5014
+					$arIp[] = $row[$oldCol];
5015
+		}
4779 5016
 		$smcFunc['db_free_result']($request);
4780 5017
 
4781 5018
 		// Special case, null ip could keep us in a loop.
4782
-		if (is_null($arIp[0]))
4783
-			unset($arIp[0]);
5019
+		if (is_null($arIp[0])) {
5020
+					unset($arIp[0]);
5021
+		}
4784 5022
 
4785
-		if (empty($arIp))
4786
-			$is_done = true;
5023
+		if (empty($arIp)) {
5024
+					$is_done = true;
5025
+		}
4787 5026
 
4788 5027
 		$updates = array();
4789 5028
 		$cases = array();
@@ -4792,16 +5031,18 @@  discard block
 block discarded – undo
4792 5031
 		{
4793 5032
 			$arIp[$i] = trim($arIp[$i]);
4794 5033
 
4795
-			if (empty($arIp[$i]))
4796
-				continue;
5034
+			if (empty($arIp[$i])) {
5035
+							continue;
5036
+			}
4797 5037
 
4798 5038
 			$updates['ip' . $i] = $arIp[$i];
4799 5039
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4800 5040
 
4801 5041
 			if ($setSize > 0 && $i % $setSize === 0)
4802 5042
 			{
4803
-				if (count($updates) == 1)
4804
-					continue;
5043
+				if (count($updates) == 1) {
5044
+									continue;
5045
+				}
4805 5046
 
4806 5047
 				$updates['whereSet'] = array_values($updates);
4807 5048
 				$smcFunc['db_query']('', '
@@ -4835,8 +5076,7 @@  discard block
 block discarded – undo
4835 5076
 							'ip' => $ip
4836 5077
 					));
4837 5078
 				}
4838
-			}
4839
-			else
5079
+			} else
4840 5080
 			{
4841 5081
 				$updates['whereSet'] = array_values($updates);
4842 5082
 				$smcFunc['db_query']('', '
@@ -4850,9 +5090,9 @@  discard block
 block discarded – undo
4850 5090
 					$updates
4851 5091
 				);
4852 5092
 			}
5093
+		} else {
5094
+					$is_done = true;
4853 5095
 		}
4854
-		else
4855
-			$is_done = true;
4856 5096
 
4857 5097
 		$_GET['a'] += $limit;
4858 5098
 		$step_progress['current'] = $_GET['a'];
@@ -4878,10 +5118,11 @@  discard block
 block discarded – undo
4878 5118
 
4879 5119
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4880 5120
 
4881
-	if (isset($columns[$column]))
4882
-		return $columns[$column];
4883
-	else
4884
-		return null;
4885
-}
5121
+	if (isset($columns[$column])) {
5122
+			return $columns[$column];
5123
+	} else {
5124
+			return null;
5125
+	}
5126
+	}
4886 5127
 
4887 5128
 ?>
4888 5129
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +232 added lines, -171 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query'					=> 'smf_db_query',
40 41
 			'db_quote'					=> 'smf_db_quote',
41 42
 			'db_insert'					=> 'smf_db_insert',
@@ -65,11 +66,13 @@  discard block
 block discarded – undo
65 66
 			'db_custom_order'			=> 'smf_db_custom_order',
66 67
 			'db_native_replace'			=> 'smf_db_native_replace',
67 68
 		);
69
+	}
68 70
 
69
-	if (!empty($db_options['persist']))
70
-		$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
71
-	else
72
-		$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
71
+	if (!empty($db_options['persist'])) {
72
+			$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
73
+	} else {
74
+			$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
75
+	}
73 76
 
74 77
 	// Something's wrong, show an error if its fatal (which we assume it is)
75 78
 	if (!$connection)
@@ -77,8 +80,7 @@  discard block
 block discarded – undo
77 80
 		if (!empty($db_options['non_fatal']))
78 81
 		{
79 82
 			return null;
80
-		}
81
-		else
83
+		} else
82 84
 		{
83 85
 			display_db_error();
84 86
 		}
@@ -129,31 +131,38 @@  discard block
 block discarded – undo
129 131
 
130 132
 	list ($values, $connection) = $db_callback;
131 133
 
132
-	if ($matches[1] === 'db_prefix')
133
-		return $db_prefix;
134
+	if ($matches[1] === 'db_prefix') {
135
+			return $db_prefix;
136
+	}
134 137
 
135
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
136
-		return $user_info[$matches[1]];
138
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
139
+			return $user_info[$matches[1]];
140
+	}
137 141
 
138
-	if ($matches[1] === 'empty')
139
-		return '\'\'';
142
+	if ($matches[1] === 'empty') {
143
+			return '\'\'';
144
+	}
140 145
 
141
-	if (!isset($matches[2]))
142
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
146
+	if (!isset($matches[2])) {
147
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
148
+	}
143 149
 
144
-	if ($matches[1] === 'literal')
145
-		return '\'' . pg_escape_string($matches[2]) . '\'';
150
+	if ($matches[1] === 'literal') {
151
+			return '\'' . pg_escape_string($matches[2]) . '\'';
152
+	}
146 153
 
147
-	if (!isset($values[$matches[2]]))
148
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
154
+	if (!isset($values[$matches[2]])) {
155
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
156
+	}
149 157
 
150 158
 	$replacement = $values[$matches[2]];
151 159
 
152 160
 	switch ($matches[1])
153 161
 	{
154 162
 		case 'int':
155
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
156
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
163
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
164
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
165
+			}
157 166
 			return (string) (int) $replacement;
158 167
 		break;
159 168
 
@@ -165,65 +174,73 @@  discard block
 block discarded – undo
165 174
 		case 'array_int':
166 175
 			if (is_array($replacement))
167 176
 			{
168
-				if (empty($replacement))
169
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177
+				if (empty($replacement)) {
178
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179
+				}
170 180
 
171 181
 				foreach ($replacement as $key => $value)
172 182
 				{
173
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
174
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
184
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
185
+					}
175 186
 
176 187
 					$replacement[$key] = (string) (int) $value;
177 188
 				}
178 189
 
179 190
 				return implode(', ', $replacement);
191
+			} else {
192
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
180 193
 			}
181
-			else
182
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183 194
 
184 195
 		break;
185 196
 
186 197
 		case 'array_string':
187 198
 			if (is_array($replacement))
188 199
 			{
189
-				if (empty($replacement))
190
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
200
+				if (empty($replacement)) {
201
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
202
+				}
191 203
 
192
-				foreach ($replacement as $key => $value)
193
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
204
+				foreach ($replacement as $key => $value) {
205
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
206
+				}
194 207
 
195 208
 				return implode(', ', $replacement);
209
+			} else {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196 211
 			}
197
-			else
198
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
199 212
 		break;
200 213
 
201 214
 		case 'date':
202
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
203
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
204
-			else
205
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
215
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
216
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
217
+			} else {
218
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
219
+			}
206 220
 		break;
207 221
 
208 222
 		case 'time':
209
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
210
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
211
-			else
212
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
224
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
225
+			} else {
226
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+			}
213 228
 		break;
214 229
 
215 230
 		case 'datetime':
216
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
217
-				return 'to_timestamp('.
231
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
232
+							return 'to_timestamp('.
218 233
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
219 234
 					',\'YYYY-MM-DD HH24:MI:SS\')';
220
-			else
221
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
222 238
 		break;
223 239
 
224 240
 		case 'float':
225
-			if (!is_numeric($replacement))
226
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			if (!is_numeric($replacement)) {
242
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+			}
227 244
 			return (string) (float) $replacement;
228 245
 		break;
229 246
 
@@ -236,31 +253,36 @@  discard block
 block discarded – undo
236 253
 		break;
237 254
 
238 255
 		case 'inet':
239
-			if ($replacement == 'null' || $replacement == '')
240
-				return 'null';
241
-			if (inet_pton($replacement) === false)
242
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
256
+			if ($replacement == 'null' || $replacement == '') {
257
+							return 'null';
258
+			}
259
+			if (inet_pton($replacement) === false) {
260
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261
+			}
243 262
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
244 263
 
245 264
 		case 'array_inet':
246 265
 			if (is_array($replacement))
247 266
 			{
248
-				if (empty($replacement))
249
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+				if (empty($replacement)) {
268
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+				}
250 270
 
251 271
 				foreach ($replacement as $key => $value)
252 272
 				{
253
-					if ($replacement == 'null' || $replacement == '')
254
-						$replacement[$key] = 'null';
255
-					if (!isValidIP($value))
256
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
273
+					if ($replacement == 'null' || $replacement == '') {
274
+											$replacement[$key] = 'null';
275
+					}
276
+					if (!isValidIP($value)) {
277
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+					}
257 279
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
258 280
 				}
259 281
 
260 282
 				return implode(', ', $replacement);
283
+			} else {
284
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261 285
 			}
262
-			else
263
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
264 286
 		break;
265 287
 
266 288
 		default:
@@ -348,14 +370,16 @@  discard block
 block discarded – undo
348 370
 		),
349 371
 	);
350 372
 
351
-	if (isset($replacements[$identifier]))
352
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
373
+	if (isset($replacements[$identifier])) {
374
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
375
+	}
353 376
 
354 377
 	// Limits need to be a little different.
355 378
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
356 379
 
357
-	if (trim($db_string) == '')
358
-		return false;
380
+	if (trim($db_string) == '') {
381
+			return false;
382
+	}
359 383
 
360 384
 	// Comments that are allowed in a query are preg_removed.
361 385
 	static $allowed_comments_from = array(
@@ -375,8 +399,9 @@  discard block
 block discarded – undo
375 399
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
376 400
 	$db_replace_result = 0;
377 401
 
378
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
379
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
402
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
403
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
404
+	}
380 405
 
381 406
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
382 407
 	{
@@ -401,17 +426,18 @@  discard block
 block discarded – undo
401 426
 		while (true)
402 427
 		{
403 428
 			$pos = strpos($db_string_1, '\'', $pos + 1);
404
-			if ($pos === false)
405
-				break;
429
+			if ($pos === false) {
430
+							break;
431
+			}
406 432
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
407 433
 
408 434
 			while (true)
409 435
 			{
410 436
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
411 437
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
412
-				if ($pos1 === false)
413
-					break;
414
-				elseif ($pos2 === false || $pos2 > $pos1)
438
+				if ($pos1 === false) {
439
+									break;
440
+				} elseif ($pos2 === false || $pos2 > $pos1)
415 441
 				{
416 442
 					$pos = $pos1;
417 443
 					break;
@@ -427,16 +453,19 @@  discard block
 block discarded – undo
427 453
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
428 454
 
429 455
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
430
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
431
-			$fail = true;
456
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
457
+					$fail = true;
458
+		}
432 459
 		// Trying to change passwords, slow us down, or something?
433
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
434
-			$fail = true;
435
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
436
-			$fail = true;
460
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
461
+					$fail = true;
462
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
463
+					$fail = true;
464
+		}
437 465
 
438
-		if (!empty($fail) && function_exists('log_error'))
439
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
466
+		if (!empty($fail) && function_exists('log_error')) {
467
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
468
+		}
440 469
 	}
441 470
 
442 471
 	// Set optimize stuff
@@ -463,8 +492,9 @@  discard block
 block discarded – undo
463 492
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
464 493
 
465 494
 		// Initialize $db_cache if not already initialized.
466
-		if (!isset($db_cache))
467
-			$db_cache = array();
495
+		if (!isset($db_cache)) {
496
+					$db_cache = array();
497
+		}
468 498
 
469 499
 		if (!empty($_SESSION['debug_redirect']))
470 500
 		{
@@ -482,12 +512,14 @@  discard block
 block discarded – undo
482 512
 
483 513
 	$db_last_result = @pg_query($connection, $db_string);
484 514
 
485
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
486
-		$db_last_result = smf_db_error($db_string, $connection);
515
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
516
+			$db_last_result = smf_db_error($db_string, $connection);
517
+	}
487 518
 
488 519
 	// Debugging.
489
-	if (isset($db_show_debug) && $db_show_debug === true)
490
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
520
+	if (isset($db_show_debug) && $db_show_debug === true) {
521
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
522
+	}
491 523
 
492 524
 	return $db_last_result;
493 525
 }
@@ -504,10 +536,11 @@  discard block
 block discarded – undo
504 536
 {
505 537
 	global $db_last_result, $db_replace_result;
506 538
 
507
-	if ($db_replace_result)
508
-		return $db_replace_result;
509
-	elseif ($result === null && !$db_last_result)
510
-		return 0;
539
+	if ($db_replace_result) {
540
+			return $db_replace_result;
541
+	} elseif ($result === null && !$db_last_result) {
542
+			return 0;
543
+	}
511 544
 
512 545
 	return pg_affected_rows($result === null ? $db_last_result : $result);
513 546
 }
@@ -531,8 +564,9 @@  discard block
 block discarded – undo
531 564
 		array(
532 565
 		)
533 566
 	);
534
-	if (!$request)
535
-		return false;
567
+	if (!$request) {
568
+			return false;
569
+	}
536 570
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
537 571
 	$smcFunc['db_free_result']($request);
538 572
 
@@ -553,12 +587,13 @@  discard block
 block discarded – undo
553 587
 	// Decide which connection to use
554 588
 	$connection = $connection === null ? $db_connection : $connection;
555 589
 
556
-	if ($type == 'begin')
557
-		return @pg_query($connection, 'BEGIN');
558
-	elseif ($type == 'rollback')
559
-		return @pg_query($connection, 'ROLLBACK');
560
-	elseif ($type == 'commit')
561
-		return @pg_query($connection, 'COMMIT');
590
+	if ($type == 'begin') {
591
+			return @pg_query($connection, 'BEGIN');
592
+	} elseif ($type == 'rollback') {
593
+			return @pg_query($connection, 'ROLLBACK');
594
+	} elseif ($type == 'commit') {
595
+			return @pg_query($connection, 'COMMIT');
596
+	}
562 597
 
563 598
 	return false;
564 599
 }
@@ -586,19 +621,22 @@  discard block
 block discarded – undo
586 621
 	$query_error = @pg_last_error($connection);
587 622
 
588 623
 	// Log the error.
589
-	if (function_exists('log_error'))
590
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
624
+	if (function_exists('log_error')) {
625
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
626
+	}
591 627
 
592 628
 	// Nothing's defined yet... just die with it.
593
-	if (empty($context) || empty($txt))
594
-		die($query_error);
629
+	if (empty($context) || empty($txt)) {
630
+			die($query_error);
631
+	}
595 632
 
596 633
 	// Show an error message, if possible.
597 634
 	$context['error_title'] = $txt['database_error'];
598
-	if (allowedTo('admin_forum'))
599
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
600
-	else
601
-		$context['error_message'] = $txt['try_again'];
635
+	if (allowedTo('admin_forum')) {
636
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
637
+	} else {
638
+			$context['error_message'] = $txt['try_again'];
639
+	}
602 640
 
603 641
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
604 642
 	{
@@ -620,12 +658,14 @@  discard block
 block discarded – undo
620 658
 {
621 659
 	global $db_row_count;
622 660
 
623
-	if ($counter !== false)
624
-		return pg_fetch_row($request, $counter);
661
+	if ($counter !== false) {
662
+			return pg_fetch_row($request, $counter);
663
+	}
625 664
 
626 665
 	// Reset the row counter...
627
-	if (!isset($db_row_count[(int) $request]))
628
-		$db_row_count[(int) $request] = 0;
666
+	if (!isset($db_row_count[(int) $request])) {
667
+			$db_row_count[(int) $request] = 0;
668
+	}
629 669
 
630 670
 	// Return the right row.
631 671
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -642,12 +682,14 @@  discard block
 block discarded – undo
642 682
 {
643 683
 	global $db_row_count;
644 684
 
645
-	if ($counter !== false)
646
-		return pg_fetch_assoc($request, $counter);
685
+	if ($counter !== false) {
686
+			return pg_fetch_assoc($request, $counter);
687
+	}
647 688
 
648 689
 	// Reset the row counter...
649
-	if (!isset($db_row_count[(int) $request]))
650
-		$db_row_count[(int) $request] = 0;
690
+	if (!isset($db_row_count[(int) $request])) {
691
+			$db_row_count[(int) $request] = 0;
692
+	}
651 693
 
652 694
 	// Return the right row.
653 695
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -700,11 +742,13 @@  discard block
 block discarded – undo
700 742
 
701 743
 	$replace = '';
702 744
 
703
-	if (empty($data))
704
-		return;
745
+	if (empty($data)) {
746
+			return;
747
+	}
705 748
 
706
-	if (!is_array($data[array_rand($data)]))
707
-		$data = array($data);
749
+	if (!is_array($data[array_rand($data)])) {
750
+			$data = array($data);
751
+	}
708 752
 
709 753
 	// Replace the prefix holder with the actual prefix.
710 754
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -730,32 +774,35 @@  discard block
 block discarded – undo
730 774
 					$key_str .= ($count_pk > 0 ? ',' : '');
731 775
 					$key_str .= $columnName;
732 776
 					$count_pk++;
733
-				}
734
-				else if ($method == 'replace') //normal field
777
+				} else if ($method == 'replace') {
778
+					//normal field
735 779
 				{
736 780
 					$col_str .= ($count > 0 ? ',' : '');
781
+				}
737 782
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
738 783
 					$count++;
739 784
 				}
740 785
 			}
741
-			if ($method == 'replace')
742
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
743
-			else
744
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
745
-		}
746
-		else if ($method == 'replace')
786
+			if ($method == 'replace') {
787
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
788
+			} else {
789
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
790
+			}
791
+		} else if ($method == 'replace')
747 792
 		{
748 793
 			foreach ($columns as $columnName => $type)
749 794
 			{
750 795
 				// Are we restricting the length?
751
-				if (strpos($type, 'string-') !== false)
752
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
753
-				else
754
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
796
+				if (strpos($type, 'string-') !== false) {
797
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
798
+				} else {
799
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
800
+				}
755 801
 
756 802
 				// A key? That's what we were looking for.
757
-				if (in_array($columnName, $keys))
758
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
803
+				if (in_array($columnName, $keys)) {
804
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
805
+				}
759 806
 				$count++;
760 807
 			}
761 808
 
@@ -791,10 +838,11 @@  discard block
 block discarded – undo
791 838
 		foreach ($columns as $columnName => $type)
792 839
 		{
793 840
 			// Are we restricting the length?
794
-			if (strpos($type, 'string-') !== false)
795
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
796
-			else
797
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
841
+			if (strpos($type, 'string-') !== false) {
842
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
843
+			} else {
844
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
845
+			}
798 846
 		}
799 847
 		$insertData = substr($insertData, 0, -2) . ')';
800 848
 
@@ -803,8 +851,9 @@  discard block
 block discarded – undo
803 851
 
804 852
 		// Here's where the variables are injected to the query.
805 853
 		$insertRows = array();
806
-		foreach ($data as $dataRow)
807
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
854
+		foreach ($data as $dataRow) {
855
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
856
+		}
808 857
 
809 858
 		// Do the insert.
810 859
 		$request = $smcFunc['db_query']('', '
@@ -821,19 +870,21 @@  discard block
 block discarded – undo
821 870
 
822 871
 		if ($with_returning && $request !== false)
823 872
 		{
824
-			if ($returnmode === 2)
825
-				$return_var = array();
873
+			if ($returnmode === 2) {
874
+							$return_var = array();
875
+			}
826 876
 
827 877
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
828 878
 			{
829
-				if (is_numeric($row[0])) // try to emulate mysql limitation
879
+				if (is_numeric($row[0])) {
880
+					// try to emulate mysql limitation
830 881
 				{
831 882
 					if ($returnmode === 1)
832 883
 						$return_var = $row[0];
833
-					elseif ($returnmode === 2)
834
-						$return_var[] = $row[0];
835
-				}
836
-				else
884
+				} elseif ($returnmode === 2) {
885
+											$return_var[] = $row[0];
886
+					}
887
+				} else
837 888
 				{
838 889
 					$with_returning = false;
839 890
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -842,9 +893,10 @@  discard block
 block discarded – undo
842 893
 		}
843 894
 	}
844 895
 
845
-	if ($with_returning && !empty($return_var))
846
-		return $return_var;
847
-}
896
+	if ($with_returning && !empty($return_var)) {
897
+			return $return_var;
898
+	}
899
+	}
848 900
 
849 901
 /**
850 902
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -881,8 +933,9 @@  discard block
 block discarded – undo
881 933
  */
882 934
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
883 935
 {
884
-	if (empty($log_message))
885
-		$log_message = $error_message;
936
+	if (empty($log_message)) {
937
+			$log_message = $error_message;
938
+	}
886 939
 
887 940
 	foreach (debug_backtrace() as $step)
888 941
 	{
@@ -901,12 +954,14 @@  discard block
 block discarded – undo
901 954
 	}
902 955
 
903 956
 	// A special case - we want the file and line numbers for debugging.
904
-	if ($error_type == 'return')
905
-		return array($file, $line);
957
+	if ($error_type == 'return') {
958
+			return array($file, $line);
959
+	}
906 960
 
907 961
 	// Is always a critical error.
908
-	if (function_exists('log_error'))
909
-		log_error($log_message, 'critical', $file, $line);
962
+	if (function_exists('log_error')) {
963
+			log_error($log_message, 'critical', $file, $line);
964
+	}
910 965
 
911 966
 	if (function_exists('fatal_error'))
912 967
 	{
@@ -914,12 +969,12 @@  discard block
 block discarded – undo
914 969
 
915 970
 		// Cannot continue...
916 971
 		exit;
972
+	} elseif ($error_type) {
973
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
974
+	} else {
975
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
976
+	}
917 977
 	}
918
-	elseif ($error_type)
919
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
920
-	else
921
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
922
-}
923 978
 
924 979
 /**
925 980
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -936,10 +991,11 @@  discard block
 block discarded – undo
936 991
 		'\\' => '\\\\',
937 992
 	);
938 993
 
939
-	if ($translate_human_wildcards)
940
-		$replacements += array(
994
+	if ($translate_human_wildcards) {
995
+			$replacements += array(
941 996
 			'*' => '%',
942 997
 		);
998
+	}
943 999
 
944 1000
 	return strtr($string, $replacements);
945 1001
 }
@@ -968,14 +1024,16 @@  discard block
 block discarded – undo
968 1024
 	static $pg_error_data_prep;
969 1025
 
970 1026
 	// without database we can't do anything
971
-	if (empty($db_connection))
972
-		return;
1027
+	if (empty($db_connection)) {
1028
+			return;
1029
+	}
973 1030
 
974
-	if (empty($pg_error_data_prep))
975
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1031
+	if (empty($pg_error_data_prep)) {
1032
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
976 1033
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
977 1034
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9)'
978 1035
 			);
1036
+	}
979 1037
 
980 1038
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
981 1039
 }
@@ -995,8 +1053,9 @@  discard block
 block discarded – undo
995 1053
 	$count = count($array_values);
996 1054
 	$then = ($desc ? ' THEN -' : ' THEN ');
997 1055
 
998
-	for ($i = 0; $i < $count; $i++)
999
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1056
+	for ($i = 0; $i < $count; $i++) {
1057
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1058
+	}
1000 1059
 
1001 1060
 	$return .= 'END';
1002 1061
 	return $return;
@@ -1019,11 +1078,13 @@  discard block
 block discarded – undo
1019 1078
 		//pg 9.5 got replace support
1020 1079
 		$pg_version = $smcFunc['db_get_version']();
1021 1080
 		// if we got a Beta Version
1022
-		if (stripos($pg_version, 'beta') !== false)
1023
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1081
+		if (stripos($pg_version, 'beta') !== false) {
1082
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1083
+		}
1024 1084
 		// or RC
1025
-		if (stripos($pg_version, 'rc') !== false)
1026
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1085
+		if (stripos($pg_version, 'rc') !== false) {
1086
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1087
+		}
1027 1088
 
1028 1089
 		$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
1029 1090
 	}
Please login to merge, or discard this patch.