Completed
Push — release-2.1 ( 463323...efea19 )
by Michael
09:50
created
other/upgrade.php 1 patch
Braces   +875 added lines, -643 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
 
@@ -100,11 +101,14 @@  discard block
 block discarded – undo
100 101
 	ini_set('default_socket_timeout', 900);
101 102
 }
102 103
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
104
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
105
+	for ($i = 1;
106
+}
107
+$i < $_SERVER['argc']; $i++)
105 108
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
109
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
110
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
111
+		}
108 112
 	}
109 113
 
110 114
 // Are we from the client?
@@ -112,16 +116,17 @@  discard block
 block discarded – undo
112 116
 {
113 117
 	$command_line = true;
114 118
 	$disable_security = true;
115
-}
116
-else
119
+} else {
117 120
 	$command_line = false;
121
+}
118 122
 
119 123
 // Load this now just because we can.
120 124
 require_once($upgrade_path . '/Settings.php');
121 125
 
122 126
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
123
-if (isset($language))
127
+if (isset($language)) {
124 128
 	$language = str_ireplace('-utf8', '', $language);
129
+}
125 130
 
126 131
 // Are we logged in?
127 132
 if (isset($upgradeData))
@@ -129,10 +134,12 @@  discard block
 block discarded – undo
129 134
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
130 135
 
131 136
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
137
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
138
+			$upcontext['user']['started'] = time();
139
+	}
140
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
141
+			$upcontext['user']['updated'] = 0;
142
+	}
136 143
 
137 144
 	$upcontext['started'] = $upcontext['user']['started'];
138 145
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -190,8 +197,9 @@  discard block
 block discarded – undo
190 197
 			'db_error_skip' => true,
191 198
 		)
192 199
 	);
193
-	while ($row = $smcFunc['db_fetch_assoc']($request))
194
-		$modSettings[$row['variable']] = $row['value'];
200
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
201
+			$modSettings[$row['variable']] = $row['value'];
202
+	}
195 203
 	$smcFunc['db_free_result']($request);
196 204
 }
197 205
 
@@ -201,10 +209,12 @@  discard block
 block discarded – undo
201 209
 	$modSettings['theme_url'] = 'Themes/default';
202 210
 	$modSettings['images_url'] = 'Themes/default/images';
203 211
 }
204
-if (!isset($settings['default_theme_url']))
212
+if (!isset($settings['default_theme_url'])) {
205 213
 	$settings['default_theme_url'] = $modSettings['theme_url'];
206
-if (!isset($settings['default_theme_dir']))
214
+}
215
+if (!isset($settings['default_theme_dir'])) {
207 216
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
217
+}
208 218
 
209 219
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
210 220
 // Default title...
@@ -222,13 +232,15 @@  discard block
 block discarded – undo
222 232
 	$support_js = $upcontext['upgrade_status']['js'];
223 233
 
224 234
 	// Only set this if the upgrader status says so.
225
-	if (empty($is_debug))
226
-		$is_debug = $upcontext['upgrade_status']['debug'];
235
+	if (empty($is_debug)) {
236
+			$is_debug = $upcontext['upgrade_status']['debug'];
237
+	}
227 238
 
228 239
 	// Load the language.
229
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
230
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
231
-}
240
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
241
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
+	}
243
+	}
232 244
 // Set the defaults.
233 245
 else
234 246
 {
@@ -246,15 +258,18 @@  discard block
 block discarded – undo
246 258
 }
247 259
 
248 260
 // If this isn't the first stage see whether they are logging in and resuming.
249
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
261
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
250 262
 	checkLogin();
263
+}
251 264
 
252
-if ($command_line)
265
+if ($command_line) {
253 266
 	cmdStep0();
267
+}
254 268
 
255 269
 // Don't error if we're using xml.
256
-if (isset($_GET['xml']))
270
+if (isset($_GET['xml'])) {
257 271
 	$upcontext['return_error'] = true;
272
+}
258 273
 
259 274
 // Loop through all the steps doing each one as required.
260 275
 $upcontext['overall_percent'] = 0;
@@ -275,9 +290,9 @@  discard block
 block discarded – undo
275 290
 		}
276 291
 
277 292
 		// Call the step and if it returns false that means pause!
278
-		if (function_exists($step[2]) && $step[2]() === false)
279
-			break;
280
-		elseif (function_exists($step[2])) {
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
281 296
 			//Start each new step with this unset, so the 'normal' template is called first
282 297
 			unset($_GET['xml']);
283 298
 			//Clear out warnings at the start of each step
@@ -323,17 +338,18 @@  discard block
 block discarded – undo
323 338
 		// This should not happen my dear... HELP ME DEVELOPERS!!
324 339
 		if (!empty($command_line))
325 340
 		{
326
-			if (function_exists('debug_print_backtrace'))
327
-				debug_print_backtrace();
341
+			if (function_exists('debug_print_backtrace')) {
342
+							debug_print_backtrace();
343
+			}
328 344
 
329 345
 			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.';
330 346
 			flush();
331 347
 			die();
332 348
 		}
333 349
 
334
-		if (!isset($_GET['xml']))
335
-			template_upgrade_above();
336
-		else
350
+		if (!isset($_GET['xml'])) {
351
+					template_upgrade_above();
352
+		} else
337 353
 		{
338 354
 			header('Content-Type: text/xml; charset=UTF-8');
339 355
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -355,25 +371,29 @@  discard block
 block discarded – undo
355 371
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
356 372
 
357 373
 			// Custom stuff to pass back?
358
-			if (!empty($upcontext['query_string']))
359
-				$upcontext['form_url'] .= $upcontext['query_string'];
374
+			if (!empty($upcontext['query_string'])) {
375
+							$upcontext['form_url'] .= $upcontext['query_string'];
376
+			}
360 377
 
361 378
 			// Call the appropriate subtemplate
362
-			if (is_callable('template_' . $upcontext['sub_template']))
363
-				call_user_func('template_' . $upcontext['sub_template']);
364
-			else
365
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
379
+			if (is_callable('template_' . $upcontext['sub_template'])) {
380
+							call_user_func('template_' . $upcontext['sub_template']);
381
+			} else {
382
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
383
+			}
366 384
 		}
367 385
 
368 386
 		// Was there an error?
369
-		if (!empty($upcontext['forced_error_message']))
370
-			echo $upcontext['forced_error_message'];
387
+		if (!empty($upcontext['forced_error_message'])) {
388
+					echo $upcontext['forced_error_message'];
389
+		}
371 390
 
372 391
 		// Show the footer.
373
-		if (!isset($_GET['xml']))
374
-			template_upgrade_below();
375
-		else
376
-			template_xml_below();
392
+		if (!isset($_GET['xml'])) {
393
+					template_upgrade_below();
394
+		} else {
395
+					template_xml_below();
396
+		}
377 397
 	}
378 398
 
379 399
 
@@ -385,15 +405,19 @@  discard block
 block discarded – undo
385 405
 		$seconds = intval($active % 60);
386 406
 
387 407
 		$totalTime = '';
388
-		if ($hours > 0)
389
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
390
-		if ($minutes > 0)
391
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
392
-		if ($seconds > 0)
393
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
408
+		if ($hours > 0) {
409
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
410
+		}
411
+		if ($minutes > 0) {
412
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
413
+		}
414
+		if ($seconds > 0) {
415
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
416
+		}
394 417
 
395
-		if (!empty($totalTime))
396
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
418
+		if (!empty($totalTime)) {
419
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
420
+		}
397 421
 	}
398 422
 
399 423
 	// Bang - gone!
@@ -406,8 +430,9 @@  discard block
 block discarded – undo
406 430
 	global $upgradeurl, $upcontext, $command_line;
407 431
 
408 432
 	// Command line users can't be redirected.
409
-	if ($command_line)
410
-		upgradeExit(true);
433
+	if ($command_line) {
434
+			upgradeExit(true);
435
+	}
411 436
 
412 437
 	// Are we providing the core info?
413 438
 	if ($addForm)
@@ -433,12 +458,14 @@  discard block
 block discarded – undo
433 458
 	define('SMF', 1);
434 459
 
435 460
 	// Start the session.
436
-	if (@ini_get('session.save_handler') == 'user')
437
-		@ini_set('session.save_handler', 'files');
461
+	if (@ini_get('session.save_handler') == 'user') {
462
+			@ini_set('session.save_handler', 'files');
463
+	}
438 464
 	@session_start();
439 465
 
440
-	if (empty($smcFunc))
441
-		$smcFunc = array();
466
+	if (empty($smcFunc)) {
467
+			$smcFunc = array();
468
+	}
442 469
 
443 470
 	// We need this for authentication and some upgrade code
444 471
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -465,24 +492,27 @@  discard block
 block discarded – undo
465 492
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
466 493
 
467 494
 		// Make the connection...
468
-		if (empty($db_connection))
469
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
470
-		else
471
-			// If we've returned here, ping/reconnect to be safe
495
+		if (empty($db_connection)) {
496
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
497
+		} else {
498
+					// If we've returned here, ping/reconnect to be safe
472 499
 			$smcFunc['db_ping']($db_connection);
500
+		}
473 501
 
474 502
 		// Oh dear god!!
475
-		if ($db_connection === null)
476
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
503
+		if ($db_connection === null) {
504
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
505
+		}
477 506
 
478
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
479
-			$smcFunc['db_query']('', '
507
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
508
+					$smcFunc['db_query']('', '
480 509
 			SET NAMES {string:db_character_set}',
481 510
 			array(
482 511
 				'db_error_skip' => true,
483 512
 				'db_character_set' => $db_character_set,
484 513
 			)
485 514
 		);
515
+		}
486 516
 
487 517
 		// Load the modSettings data...
488 518
 		$request = $smcFunc['db_query']('', '
@@ -493,11 +523,11 @@  discard block
 block discarded – undo
493 523
 			)
494 524
 		);
495 525
 		$modSettings = array();
496
-		while ($row = $smcFunc['db_fetch_assoc']($request))
497
-			$modSettings[$row['variable']] = $row['value'];
526
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
527
+					$modSettings[$row['variable']] = $row['value'];
528
+		}
498 529
 		$smcFunc['db_free_result']($request);
499
-	}
500
-	else
530
+	} else
501 531
 	{
502 532
 		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.');
503 533
 	}
@@ -511,9 +541,10 @@  discard block
 block discarded – undo
511 541
 		cleanRequest();
512 542
 	}
513 543
 
514
-	if (!isset($_GET['substep']))
515
-		$_GET['substep'] = 0;
516
-}
544
+	if (!isset($_GET['substep'])) {
545
+			$_GET['substep'] = 0;
546
+	}
547
+	}
517 548
 
518 549
 function initialize_inputs()
519 550
 {
@@ -543,8 +574,9 @@  discard block
 block discarded – undo
543 574
 		$dh = opendir(dirname(__FILE__));
544 575
 		while ($file = readdir($dh))
545 576
 		{
546
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
547
-				@unlink(dirname(__FILE__) . '/' . $file);
577
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
578
+							@unlink(dirname(__FILE__) . '/' . $file);
579
+			}
548 580
 		}
549 581
 		closedir($dh);
550 582
 
@@ -573,8 +605,9 @@  discard block
 block discarded – undo
573 605
 	$temp = 'upgrade_php?step';
574 606
 	while (strlen($temp) > 4)
575 607
 	{
576
-		if (isset($_GET[$temp]))
577
-			unset($_GET[$temp]);
608
+		if (isset($_GET[$temp])) {
609
+					unset($_GET[$temp]);
610
+		}
578 611
 		$temp = substr($temp, 1);
579 612
 	}
580 613
 
@@ -601,32 +634,39 @@  discard block
 block discarded – undo
601 634
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
602 635
 
603 636
 	// Need legacy scripts?
604
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
605
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
606
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
607
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
608
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
609
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
637
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
638
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
639
+	}
640
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
641
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
642
+	}
643
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
644
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
645
+	}
610 646
 
611 647
 	// We don't need "-utf8" files anymore...
612 648
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
613 649
 
614 650
 	// This needs to exist!
615
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
616
-		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>]');
617
-	else
618
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
651
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
652
+			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>]');
653
+	} else {
654
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
655
+	}
619 656
 
620
-	if (!$check)
621
-		// 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.
657
+	if (!$check) {
658
+			// 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.
622 659
 		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.');
660
+	}
623 661
 
624 662
 	// Do they meet the install requirements?
625
-	if (!php_version_check())
626
-		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.');
663
+	if (!php_version_check()) {
664
+			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.');
665
+	}
627 666
 
628
-	if (!db_version_check())
629
-		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.');
667
+	if (!db_version_check()) {
668
+			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.');
669
+	}
630 670
 
631 671
 	// Do some checks to make sure they have proper privileges
632 672
 	db_extend('packages');
@@ -641,14 +681,16 @@  discard block
 block discarded – undo
641 681
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
642 682
 
643 683
 	// Sorry... we need CREATE, ALTER and DROP
644
-	if (!$create || !$alter || !$drop)
645
-		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.');
684
+	if (!$create || !$alter || !$drop) {
685
+			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.');
686
+	}
646 687
 
647 688
 	// Do a quick version spot check.
648 689
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
649 690
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
650
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
651
-		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.');
691
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
692
+			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.');
693
+	}
652 694
 
653 695
 	// What absolutely needs to be writable?
654 696
 	$writable_files = array(
@@ -670,12 +712,13 @@  discard block
 block discarded – undo
670 712
 	quickFileWritable($custom_av_dir);
671 713
 
672 714
 	// Are we good now?
673
-	if (!is_writable($custom_av_dir))
674
-		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));
675
-	elseif ($need_settings_update)
715
+	if (!is_writable($custom_av_dir)) {
716
+			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));
717
+	} elseif ($need_settings_update)
676 718
 	{
677
-		if (!function_exists('cache_put_data'))
678
-			require_once($sourcedir . '/Load.php');
719
+		if (!function_exists('cache_put_data')) {
720
+					require_once($sourcedir . '/Load.php');
721
+		}
679 722
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
680 723
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
681 724
 	}
@@ -684,28 +727,33 @@  discard block
 block discarded – undo
684 727
 
685 728
 	// Check the cache directory.
686 729
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
687
-	if (!file_exists($cachedir_temp))
688
-		@mkdir($cachedir_temp);
689
-	if (!file_exists($cachedir_temp))
690
-		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.');
691
-
692
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
693
-		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>.');
694
-	elseif (!isset($_GET['skiplang']))
730
+	if (!file_exists($cachedir_temp)) {
731
+			@mkdir($cachedir_temp);
732
+	}
733
+	if (!file_exists($cachedir_temp)) {
734
+			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.');
735
+	}
736
+
737
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
738
+			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>.');
739
+	} elseif (!isset($_GET['skiplang']))
695 740
 	{
696 741
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
697 742
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
698 743
 
699
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
700
-			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>]');
744
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
745
+					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>]');
746
+		}
701 747
 	}
702 748
 
703
-	if (!makeFilesWritable($writable_files))
704
-		return false;
749
+	if (!makeFilesWritable($writable_files)) {
750
+			return false;
751
+	}
705 752
 
706 753
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
707
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
708
-		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.');
754
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
755
+			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.');
756
+	}
709 757
 
710 758
 	// Upgrade the agreement.
711 759
 	elseif (isset($modSettings['agreement']))
@@ -716,8 +764,8 @@  discard block
 block discarded – undo
716 764
 	}
717 765
 
718 766
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
719
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
720
-		$upcontext['warning'] = '
767
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
768
+			$upcontext['warning'] = '
721 769
 			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>
722 770
 			<ul>
723 771
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -725,19 +773,23 @@  discard block
 block discarded – undo
725 773
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
726 774
 			</ul>
727 775
 			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.';
776
+	}
728 777
 
729 778
 	// Confirm mbstring is loaded...
730
-	if (!extension_loaded('mbstring'))
731
-		return throw_error($txt['install_no_mbstring']);
779
+	if (!extension_loaded('mbstring')) {
780
+			return throw_error($txt['install_no_mbstring']);
781
+	}
732 782
 
733 783
 	// Check for https stream support.
734 784
 	$supported_streams = stream_get_wrappers();
735
-	if (!in_array('https', $supported_streams))
736
-		$upcontext['custom_warning'] = $txt['install_no_https'];
785
+	if (!in_array('https', $supported_streams)) {
786
+			$upcontext['custom_warning'] = $txt['install_no_https'];
787
+	}
737 788
 
738 789
 	// Either we're logged in or we're going to present the login.
739
-	if (checkLogin())
740
-		return true;
790
+	if (checkLogin()) {
791
+			return true;
792
+	}
741 793
 
742 794
 	$upcontext += createToken('login');
743 795
 
@@ -751,15 +803,17 @@  discard block
 block discarded – undo
751 803
 	global $smcFunc, $db_type, $support_js;
752 804
 
753 805
 	// Don't bother if the security is disabled.
754
-	if ($disable_security)
755
-		return true;
806
+	if ($disable_security) {
807
+			return true;
808
+	}
756 809
 
757 810
 	// Are we trying to login?
758 811
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
759 812
 	{
760 813
 		// If we've disabled security pick a suitable name!
761
-		if (empty($_POST['user']))
762
-			$_POST['user'] = 'Administrator';
814
+		if (empty($_POST['user'])) {
815
+					$_POST['user'] = 'Administrator';
816
+		}
763 817
 
764 818
 		// Before 2.0 these column names were different!
765 819
 		$oldDB = false;
@@ -774,16 +828,17 @@  discard block
 block discarded – undo
774 828
 					'db_error_skip' => true,
775 829
 				)
776 830
 			);
777
-			if ($smcFunc['db_num_rows']($request) != 0)
778
-				$oldDB = true;
831
+			if ($smcFunc['db_num_rows']($request) != 0) {
832
+							$oldDB = true;
833
+			}
779 834
 			$smcFunc['db_free_result']($request);
780 835
 		}
781 836
 
782 837
 		// Get what we believe to be their details.
783 838
 		if (!$disable_security)
784 839
 		{
785
-			if ($oldDB)
786
-				$request = $smcFunc['db_query']('', '
840
+			if ($oldDB) {
841
+							$request = $smcFunc['db_query']('', '
787 842
 					SELECT id_member, memberName AS member_name, passwd, id_group,
788 843
 					additionalGroups AS additional_groups, lngfile
789 844
 					FROM {db_prefix}members
@@ -793,8 +848,8 @@  discard block
 block discarded – undo
793 848
 						'db_error_skip' => true,
794 849
 					)
795 850
 				);
796
-			else
797
-				$request = $smcFunc['db_query']('', '
851
+			} else {
852
+							$request = $smcFunc['db_query']('', '
798 853
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
799 854
 					FROM {db_prefix}members
800 855
 					WHERE member_name = {string:member_name}',
@@ -803,6 +858,7 @@  discard block
 block discarded – undo
803 858
 						'db_error_skip' => true,
804 859
 					)
805 860
 				);
861
+			}
806 862
 			if ($smcFunc['db_num_rows']($request) != 0)
807 863
 			{
808 864
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -810,16 +866,17 @@  discard block
 block discarded – undo
810 866
 				$groups = explode(',', $addGroups);
811 867
 				$groups[] = $id_group;
812 868
 
813
-				foreach ($groups as $k => $v)
814
-					$groups[$k] = (int) $v;
869
+				foreach ($groups as $k => $v) {
870
+									$groups[$k] = (int) $v;
871
+				}
815 872
 
816 873
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
817 874
 
818 875
 				// We don't use "-utf8" anymore...
819 876
 				$user_language = str_ireplace('-utf8', '', $user_language);
877
+			} else {
878
+							$upcontext['username_incorrect'] = true;
820 879
 			}
821
-			else
822
-				$upcontext['username_incorrect'] = true;
823 880
 			$smcFunc['db_free_result']($request);
824 881
 		}
825 882
 		$upcontext['username'] = $_POST['user'];
@@ -829,13 +886,14 @@  discard block
 block discarded – undo
829 886
 		{
830 887
 			$upcontext['upgrade_status']['js'] = 1;
831 888
 			$support_js = 1;
889
+		} else {
890
+					$support_js = 0;
832 891
 		}
833
-		else
834
-			$support_js = 0;
835 892
 
836 893
 		// Note down the version we are coming from.
837
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
838
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
894
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
895
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
896
+		}
839 897
 
840 898
 		// Didn't get anywhere?
841 899
 		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']))
@@ -869,15 +927,15 @@  discard block
 block discarded – undo
869 927
 							'db_error_skip' => true,
870 928
 						)
871 929
 					);
872
-					if ($smcFunc['db_num_rows']($request) == 0)
873
-						return throw_error('You need to be an admin to perform an upgrade!');
930
+					if ($smcFunc['db_num_rows']($request) == 0) {
931
+											return throw_error('You need to be an admin to perform an upgrade!');
932
+					}
874 933
 					$smcFunc['db_free_result']($request);
875 934
 				}
876 935
 
877 936
 				$upcontext['user']['id'] = $id_member;
878 937
 				$upcontext['user']['name'] = $name;
879
-			}
880
-			else
938
+			} else
881 939
 			{
882 940
 				$upcontext['user']['id'] = 1;
883 941
 				$upcontext['user']['name'] = 'Administrator';
@@ -893,11 +951,11 @@  discard block
 block discarded – undo
893 951
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
894 952
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
895 953
 
896
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
897
-					$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'] . '.';
898
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
899
-					$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'] . '.';
900
-				else
954
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
955
+									$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'] . '.';
956
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
957
+									$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'] . '.';
958
+				} else
901 959
 				{
902 960
 					// Set this as the new language.
903 961
 					$upcontext['language'] = $user_language;
@@ -941,8 +999,9 @@  discard block
 block discarded – undo
941 999
 	unset($member_columns);
942 1000
 
943 1001
 	// If we've not submitted then we're done.
944
-	if (empty($_POST['upcont']))
945
-		return false;
1002
+	if (empty($_POST['upcont'])) {
1003
+			return false;
1004
+	}
946 1005
 
947 1006
 	// Firstly, if they're enabling SM stat collection just do it.
948 1007
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -962,16 +1021,17 @@  discard block
 block discarded – undo
962 1021
 				fwrite($fp, $out);
963 1022
 
964 1023
 				$return_data = '';
965
-				while (!feof($fp))
966
-					$return_data .= fgets($fp, 128);
1024
+				while (!feof($fp)) {
1025
+									$return_data .= fgets($fp, 128);
1026
+				}
967 1027
 
968 1028
 				fclose($fp);
969 1029
 
970 1030
 				// Get the unique site ID.
971 1031
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
972 1032
 
973
-				if (!empty($ID[1]))
974
-					$smcFunc['db_insert']('replace',
1033
+				if (!empty($ID[1])) {
1034
+									$smcFunc['db_insert']('replace',
975 1035
 						$db_prefix . 'settings',
976 1036
 						array('variable' => 'string', 'value' => 'string'),
977 1037
 						array(
@@ -980,9 +1040,9 @@  discard block
 block discarded – undo
980 1040
 						),
981 1041
 						array('variable')
982 1042
 					);
1043
+				}
983 1044
 			}
984
-		}
985
-		else
1045
+		} else
986 1046
 		{
987 1047
 			$smcFunc['db_insert']('replace',
988 1048
 				$db_prefix . 'settings',
@@ -993,8 +1053,8 @@  discard block
 block discarded – undo
993 1053
 		}
994 1054
 	}
995 1055
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
996
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
997
-		$smcFunc['db_query']('', '
1056
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1057
+			$smcFunc['db_query']('', '
998 1058
 			DELETE FROM {db_prefix}settings
999 1059
 			WHERE variable = {string:enable_sm_stats}',
1000 1060
 			array(
@@ -1002,6 +1062,7 @@  discard block
 block discarded – undo
1002 1062
 				'db_error_skip' => true,
1003 1063
 			)
1004 1064
 		);
1065
+	}
1005 1066
 
1006 1067
 	// Deleting old karma stuff?
1007 1068
 	if (!empty($_POST['delete_karma']))
@@ -1016,20 +1077,22 @@  discard block
 block discarded – undo
1016 1077
 		);
1017 1078
 
1018 1079
 		// Cleaning up old karma member settings.
1019
-		if ($upcontext['karma_installed']['good'])
1020
-			$smcFunc['db_query']('', '
1080
+		if ($upcontext['karma_installed']['good']) {
1081
+					$smcFunc['db_query']('', '
1021 1082
 				ALTER TABLE {db_prefix}members
1022 1083
 				DROP karma_good',
1023 1084
 				array()
1024 1085
 			);
1086
+		}
1025 1087
 
1026 1088
 		// Does karma bad was enable?
1027
-		if ($upcontext['karma_installed']['bad'])
1028
-			$smcFunc['db_query']('', '
1089
+		if ($upcontext['karma_installed']['bad']) {
1090
+					$smcFunc['db_query']('', '
1029 1091
 				ALTER TABLE {db_prefix}members
1030 1092
 				DROP karma_bad',
1031 1093
 				array()
1032 1094
 			);
1095
+		}
1033 1096
 
1034 1097
 		// Cleaning up old karma permissions.
1035 1098
 		$smcFunc['db_query']('', '
@@ -1042,26 +1105,29 @@  discard block
 block discarded – undo
1042 1105
 	}
1043 1106
 
1044 1107
 	// Emptying the error log?
1045
-	if (!empty($_POST['empty_error']))
1046
-		$smcFunc['db_query']('truncate_table', '
1108
+	if (!empty($_POST['empty_error'])) {
1109
+			$smcFunc['db_query']('truncate_table', '
1047 1110
 			TRUNCATE {db_prefix}log_errors',
1048 1111
 			array(
1049 1112
 			)
1050 1113
 		);
1114
+	}
1051 1115
 
1052 1116
 	$changes = array();
1053 1117
 
1054 1118
 	// Add proxy settings.
1055
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1056
-		$changes += array(
1119
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1120
+			$changes += array(
1057 1121
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1058 1122
 			'image_proxy_maxsize' => 5190,
1059 1123
 			'image_proxy_enabled' => 0,
1060 1124
 		);
1125
+	}
1061 1126
 
1062 1127
 	// If we're overriding the language follow it through.
1063
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1064
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1128
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1129
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1130
+	}
1065 1131
 
1066 1132
 	if (!empty($_POST['maint']))
1067 1133
 	{
@@ -1073,26 +1139,29 @@  discard block
 block discarded – undo
1073 1139
 		{
1074 1140
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1075 1141
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1076
-		}
1077
-		else
1142
+		} else
1078 1143
 		{
1079 1144
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1080 1145
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1081 1146
 		}
1082 1147
 	}
1083 1148
 
1084
-	if ($command_line)
1085
-		echo ' * Updating Settings.php...';
1149
+	if ($command_line) {
1150
+			echo ' * Updating Settings.php...';
1151
+	}
1086 1152
 
1087 1153
 	// Fix some old paths.
1088
-	if (substr($boarddir, 0, 1) == '.')
1089
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1154
+	if (substr($boarddir, 0, 1) == '.') {
1155
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1156
+	}
1090 1157
 
1091
-	if (substr($sourcedir, 0, 1) == '.')
1092
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1158
+	if (substr($sourcedir, 0, 1) == '.') {
1159
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1160
+	}
1093 1161
 
1094
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1095
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1162
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1163
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1164
+	}
1096 1165
 
1097 1166
 	// If they have a "host:port" setup for the host, split that into separate values
1098 1167
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1103,32 +1172,36 @@  discard block
 block discarded – undo
1103 1172
 		$changes['db_server'] = '\'' . $db_server . '\'';
1104 1173
 
1105 1174
 		// Only set this if we're not using the default port
1106
-		if ($db_port != ini_get('mysqli.default_port'))
1107
-			$changes['db_port'] = (int) $db_port;
1108
-	}
1109
-	elseif (!empty($db_port))
1175
+		if ($db_port != ini_get('mysqli.default_port')) {
1176
+					$changes['db_port'] = (int) $db_port;
1177
+		}
1178
+	} elseif (!empty($db_port))
1110 1179
 	{
1111 1180
 		// If db_port is set and is the same as the default, set it to ''
1112 1181
 		if ($db_type == 'mysql')
1113 1182
 		{
1114
-			if ($db_port == ini_get('mysqli.default_port'))
1115
-				$changes['db_port'] = '\'\'';
1116
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1117
-				$changes['db_port'] = '\'\'';
1183
+			if ($db_port == ini_get('mysqli.default_port')) {
1184
+							$changes['db_port'] = '\'\'';
1185
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1186
+							$changes['db_port'] = '\'\'';
1187
+			}
1118 1188
 		}
1119 1189
 	}
1120 1190
 
1121 1191
 	// Maybe we haven't had this option yet?
1122
-	if (empty($packagesdir))
1123
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1192
+	if (empty($packagesdir)) {
1193
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1194
+	}
1124 1195
 
1125 1196
 	// Add support for $tasksdir var.
1126
-	if (empty($tasksdir))
1127
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1197
+	if (empty($tasksdir)) {
1198
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1199
+	}
1128 1200
 
1129 1201
 	// Make sure we fix the language as well.
1130
-	if (stristr($language, '-utf8'))
1131
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1202
+	if (stristr($language, '-utf8')) {
1203
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1204
+	}
1132 1205
 
1133 1206
 	// @todo Maybe change the cookie name if going to 1.1, too?
1134 1207
 
@@ -1136,8 +1209,9 @@  discard block
 block discarded – undo
1136 1209
 	require_once($sourcedir . '/Subs-Admin.php');
1137 1210
 	updateSettingsFile($changes);
1138 1211
 
1139
-	if ($command_line)
1140
-		echo ' Successful.' . "\n";
1212
+	if ($command_line) {
1213
+			echo ' Successful.' . "\n";
1214
+	}
1141 1215
 
1142 1216
 	// Are we doing debug?
1143 1217
 	if (isset($_POST['debug']))
@@ -1147,8 +1221,9 @@  discard block
 block discarded – undo
1147 1221
 	}
1148 1222
 
1149 1223
 	// If we're not backing up then jump one.
1150
-	if (empty($_POST['backup']))
1151
-		$upcontext['current_step']++;
1224
+	if (empty($_POST['backup'])) {
1225
+			$upcontext['current_step']++;
1226
+	}
1152 1227
 
1153 1228
 	// If we've got here then let's proceed to the next step!
1154 1229
 	return true;
@@ -1163,8 +1238,9 @@  discard block
 block discarded – undo
1163 1238
 	$upcontext['page_title'] = 'Backup Database';
1164 1239
 
1165 1240
 	// Done it already - js wise?
1166
-	if (!empty($_POST['backup_done']))
1167
-		return true;
1241
+	if (!empty($_POST['backup_done'])) {
1242
+			return true;
1243
+	}
1168 1244
 
1169 1245
 	// Some useful stuff here.
1170 1246
 	db_extend();
@@ -1178,9 +1254,10 @@  discard block
 block discarded – undo
1178 1254
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1179 1255
 
1180 1256
 	$table_names = array();
1181
-	foreach ($tables as $table)
1182
-		if (substr($table, 0, 7) !== 'backup_')
1257
+	foreach ($tables as $table) {
1258
+			if (substr($table, 0, 7) !== 'backup_')
1183 1259
 			$table_names[] = $table;
1260
+	}
1184 1261
 
1185 1262
 	$upcontext['table_count'] = count($table_names);
1186 1263
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1190,12 +1267,14 @@  discard block
 block discarded – undo
1190 1267
 	$file_steps = $upcontext['table_count'];
1191 1268
 
1192 1269
 	// What ones have we already done?
1193
-	foreach ($table_names as $id => $table)
1194
-		if ($id < $_GET['substep'])
1270
+	foreach ($table_names as $id => $table) {
1271
+			if ($id < $_GET['substep'])
1195 1272
 			$upcontext['previous_tables'][] = $table;
1273
+	}
1196 1274
 
1197
-	if ($command_line)
1198
-		echo 'Backing Up Tables.';
1275
+	if ($command_line) {
1276
+			echo 'Backing Up Tables.';
1277
+	}
1199 1278
 
1200 1279
 	// If we don't support javascript we backup here.
1201 1280
 	if (!$support_js || isset($_GET['xml']))
@@ -1214,8 +1293,9 @@  discard block
 block discarded – undo
1214 1293
 			backupTable($table_names[$substep]);
1215 1294
 
1216 1295
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1217
-			if (isset($_GET['xml']))
1218
-				return upgradeExit();
1296
+			if (isset($_GET['xml'])) {
1297
+							return upgradeExit();
1298
+			}
1219 1299
 		}
1220 1300
 
1221 1301
 		if ($command_line)
@@ -1248,9 +1328,10 @@  discard block
 block discarded – undo
1248 1328
 
1249 1329
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1250 1330
 
1251
-	if ($command_line)
1252
-		echo ' done.';
1253
-}
1331
+	if ($command_line) {
1332
+			echo ' done.';
1333
+	}
1334
+	}
1254 1335
 
1255 1336
 // Step 2: Everything.
1256 1337
 function DatabaseChanges()
@@ -1259,8 +1340,9 @@  discard block
 block discarded – undo
1259 1340
 	global $upcontext, $support_js, $db_type;
1260 1341
 
1261 1342
 	// Have we just completed this?
1262
-	if (!empty($_POST['database_done']))
1263
-		return true;
1343
+	if (!empty($_POST['database_done'])) {
1344
+			return true;
1345
+	}
1264 1346
 
1265 1347
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1266 1348
 	$upcontext['page_title'] = 'Database Changes';
@@ -1275,15 +1357,16 @@  discard block
 block discarded – undo
1275 1357
 	);
1276 1358
 
1277 1359
 	// How many files are there in total?
1278
-	if (isset($_GET['filecount']))
1279
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1280
-	else
1360
+	if (isset($_GET['filecount'])) {
1361
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1362
+	} else
1281 1363
 	{
1282 1364
 		$upcontext['file_count'] = 0;
1283 1365
 		foreach ($files as $file)
1284 1366
 		{
1285
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1286
-				$upcontext['file_count']++;
1367
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1368
+							$upcontext['file_count']++;
1369
+			}
1287 1370
 		}
1288 1371
 	}
1289 1372
 
@@ -1293,9 +1376,9 @@  discard block
 block discarded – undo
1293 1376
 	$upcontext['cur_file_num'] = 0;
1294 1377
 	foreach ($files as $file)
1295 1378
 	{
1296
-		if ($did_not_do)
1297
-			$did_not_do--;
1298
-		else
1379
+		if ($did_not_do) {
1380
+					$did_not_do--;
1381
+		} else
1299 1382
 		{
1300 1383
 			$upcontext['cur_file_num']++;
1301 1384
 			$upcontext['cur_file_name'] = $file[0];
@@ -1322,12 +1405,13 @@  discard block
 block discarded – undo
1322 1405
 					// Flag to move on to the next.
1323 1406
 					$upcontext['completed_step'] = true;
1324 1407
 					// Did we complete the whole file?
1325
-					if ($nextFile)
1326
-						$upcontext['current_debug_item_num'] = -1;
1408
+					if ($nextFile) {
1409
+											$upcontext['current_debug_item_num'] = -1;
1410
+					}
1327 1411
 					return upgradeExit();
1412
+				} elseif ($support_js) {
1413
+									break;
1328 1414
 				}
1329
-				elseif ($support_js)
1330
-					break;
1331 1415
 			}
1332 1416
 			// Set the progress bar to be right as if we had - even if we hadn't...
1333 1417
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1352,8 +1436,9 @@  discard block
 block discarded – undo
1352 1436
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1353 1437
 
1354 1438
 	// Now it's nice to have some of the basic SMF source files.
1355
-	if (!isset($_GET['ssi']) && !$command_line)
1356
-		redirectLocation('&ssi=1');
1439
+	if (!isset($_GET['ssi']) && !$command_line) {
1440
+			redirectLocation('&ssi=1');
1441
+	}
1357 1442
 
1358 1443
 	$upcontext['sub_template'] = 'upgrade_complete';
1359 1444
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1369,14 +1454,16 @@  discard block
 block discarded – undo
1369 1454
 	// Are we in maintenance mode?
1370 1455
 	if (isset($upcontext['user']['main']))
1371 1456
 	{
1372
-		if ($command_line)
1373
-			echo ' * ';
1457
+		if ($command_line) {
1458
+					echo ' * ';
1459
+		}
1374 1460
 		$upcontext['removed_maintenance'] = true;
1375 1461
 		$changes['maintenance'] = $upcontext['user']['main'];
1376 1462
 	}
1377 1463
 	// Otherwise if somehow we are in 2 let's go to 1.
1378
-	elseif (!empty($maintenance) && $maintenance == 2)
1379
-		$changes['maintenance'] = 1;
1464
+	elseif (!empty($maintenance) && $maintenance == 2) {
1465
+			$changes['maintenance'] = 1;
1466
+	}
1380 1467
 
1381 1468
 	// Wipe this out...
1382 1469
 	$upcontext['user'] = array();
@@ -1391,9 +1478,9 @@  discard block
 block discarded – undo
1391 1478
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1392 1479
 
1393 1480
 	// Now is the perfect time to fetch the SM files.
1394
-	if ($command_line)
1395
-		cli_scheduled_fetchSMfiles();
1396
-	else
1481
+	if ($command_line) {
1482
+			cli_scheduled_fetchSMfiles();
1483
+	} else
1397 1484
 	{
1398 1485
 		require_once($sourcedir . '/ScheduledTasks.php');
1399 1486
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1401,8 +1488,9 @@  discard block
 block discarded – undo
1401 1488
 	}
1402 1489
 
1403 1490
 	// Log what we've done.
1404
-	if (empty($user_info['id']))
1405
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1491
+	if (empty($user_info['id'])) {
1492
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1493
+	}
1406 1494
 
1407 1495
 	// Log the action manually, so CLI still works.
1408 1496
 	$smcFunc['db_insert']('',
@@ -1421,8 +1509,9 @@  discard block
 block discarded – undo
1421 1509
 
1422 1510
 	// Save the current database version.
1423 1511
 	$server_version = $smcFunc['db_server_info']();
1424
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1425
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1512
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1513
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1514
+	}
1426 1515
 
1427 1516
 	if ($command_line)
1428 1517
 	{
@@ -1434,8 +1523,9 @@  discard block
 block discarded – undo
1434 1523
 
1435 1524
 	// Make sure it says we're done.
1436 1525
 	$upcontext['overall_percent'] = 100;
1437
-	if (isset($upcontext['step_progress']))
1438
-		unset($upcontext['step_progress']);
1526
+	if (isset($upcontext['step_progress'])) {
1527
+			unset($upcontext['step_progress']);
1528
+	}
1439 1529
 
1440 1530
 	$_GET['substep'] = 0;
1441 1531
 	return false;
@@ -1446,8 +1536,9 @@  discard block
 block discarded – undo
1446 1536
 {
1447 1537
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1448 1538
 
1449
-	if (empty($modSettings['time_format']))
1450
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1539
+	if (empty($modSettings['time_format'])) {
1540
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1541
+	}
1451 1542
 
1452 1543
 	// What files do we want to get
1453 1544
 	$request = $smcFunc['db_query']('', '
@@ -1481,8 +1572,9 @@  discard block
 block discarded – undo
1481 1572
 		$file_data = fetch_web_data($url);
1482 1573
 
1483 1574
 		// If we got an error - give up - the site might be down.
1484
-		if ($file_data === false)
1485
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1575
+		if ($file_data === false) {
1576
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1577
+		}
1486 1578
 
1487 1579
 		// Save the file to the database.
1488 1580
 		$smcFunc['db_query']('substring', '
@@ -1524,8 +1616,9 @@  discard block
 block discarded – undo
1524 1616
 	$themeData = array();
1525 1617
 	foreach ($values as $variable => $value)
1526 1618
 	{
1527
-		if (!isset($value) || $value === null)
1528
-			$value = 0;
1619
+		if (!isset($value) || $value === null) {
1620
+					$value = 0;
1621
+		}
1529 1622
 
1530 1623
 		$themeData[] = array(0, 1, $variable, $value);
1531 1624
 	}
@@ -1554,8 +1647,9 @@  discard block
 block discarded – undo
1554 1647
 
1555 1648
 	foreach ($values as $variable => $value)
1556 1649
 	{
1557
-		if (empty($modSettings[$value[0]]))
1558
-			continue;
1650
+		if (empty($modSettings[$value[0]])) {
1651
+					continue;
1652
+		}
1559 1653
 
1560 1654
 		$smcFunc['db_query']('', '
1561 1655
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1641,19 +1735,21 @@  discard block
 block discarded – undo
1641 1735
 	set_error_handler(
1642 1736
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1643 1737
 		{
1644
-			if ($support_js)
1645
-				return true;
1646
-			else
1647
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1738
+			if ($support_js) {
1739
+							return true;
1740
+			} else {
1741
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1742
+			}
1648 1743
 		}
1649 1744
 	);
1650 1745
 
1651 1746
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1652 1747
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1653
-	if ($db_type == 'mysql')
1654
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1655
-	else
1656
-		$db_collation = '';
1748
+	if ($db_type == 'mysql') {
1749
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1750
+	} else {
1751
+			$db_collation = '';
1752
+	}
1657 1753
 
1658 1754
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1659 1755
 
@@ -1665,8 +1761,9 @@  discard block
 block discarded – undo
1665 1761
 	$last_step = '';
1666 1762
 
1667 1763
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1668
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1669
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1764
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1765
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1766
+	}
1670 1767
 
1671 1768
 	// Count the total number of steps within this file - for progress.
1672 1769
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1686,15 +1783,18 @@  discard block
 block discarded – undo
1686 1783
 		$do_current = $substep >= $_GET['substep'];
1687 1784
 
1688 1785
 		// Get rid of any comments in the beginning of the line...
1689
-		if (substr(trim($line), 0, 2) === '/*')
1690
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1786
+		if (substr(trim($line), 0, 2) === '/*') {
1787
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1788
+		}
1691 1789
 
1692 1790
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1693
-		if ($is_debug && !$support_js && $command_line)
1694
-			flush();
1791
+		if ($is_debug && !$support_js && $command_line) {
1792
+					flush();
1793
+		}
1695 1794
 
1696
-		if (trim($line) === '')
1697
-			continue;
1795
+		if (trim($line) === '') {
1796
+					continue;
1797
+		}
1698 1798
 
1699 1799
 		if (trim(substr($line, 0, 3)) === '---')
1700 1800
 		{
@@ -1704,8 +1804,9 @@  discard block
 block discarded – undo
1704 1804
 			if (trim($current_data) != '' && $type !== '}')
1705 1805
 			{
1706 1806
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1707
-				if ($command_line)
1708
-					echo $upcontext['error_message'];
1807
+				if ($command_line) {
1808
+									echo $upcontext['error_message'];
1809
+				}
1709 1810
 			}
1710 1811
 
1711 1812
 			if ($type == ' ')
@@ -1723,17 +1824,18 @@  discard block
 block discarded – undo
1723 1824
 				if ($do_current)
1724 1825
 				{
1725 1826
 					$upcontext['actioned_items'][] = $last_step;
1726
-					if ($command_line)
1727
-						echo ' * ';
1827
+					if ($command_line) {
1828
+											echo ' * ';
1829
+					}
1728 1830
 				}
1729
-			}
1730
-			elseif ($type == '#')
1831
+			} elseif ($type == '#')
1731 1832
 			{
1732 1833
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1733 1834
 
1734 1835
 				$upcontext['current_debug_item_num']++;
1735
-				if (trim($line) != '---#')
1736
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1836
+				if (trim($line) != '---#') {
1837
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1838
+				}
1737 1839
 
1738 1840
 				// Have we already done something?
1739 1841
 				if (isset($_GET['xml']) && $done_something)
@@ -1744,34 +1846,36 @@  discard block
 block discarded – undo
1744 1846
 
1745 1847
 				if ($do_current)
1746 1848
 				{
1747
-					if (trim($line) == '---#' && $command_line)
1748
-						echo ' done.', $endl;
1749
-					elseif ($command_line)
1750
-						echo ' +++ ', rtrim(substr($line, 4));
1751
-					elseif (trim($line) != '---#')
1849
+					if (trim($line) == '---#' && $command_line) {
1850
+											echo ' done.', $endl;
1851
+					} elseif ($command_line) {
1852
+											echo ' +++ ', rtrim(substr($line, 4));
1853
+					} elseif (trim($line) != '---#')
1752 1854
 					{
1753
-						if ($is_debug)
1754
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1855
+						if ($is_debug) {
1856
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1857
+						}
1755 1858
 					}
1756 1859
 				}
1757 1860
 
1758 1861
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1759 1862
 				{
1760
-					if ($command_line)
1761
-						echo ' * ';
1762
-					else
1763
-						$upcontext['actioned_items'][] = $last_step;
1863
+					if ($command_line) {
1864
+											echo ' * ';
1865
+					} else {
1866
+											$upcontext['actioned_items'][] = $last_step;
1867
+					}
1764 1868
 				}
1765 1869
 
1766 1870
 				// Small step - only if we're actually doing stuff.
1767
-				if ($do_current)
1768
-					nextSubstep(++$substep);
1769
-				else
1770
-					$substep++;
1771
-			}
1772
-			elseif ($type == '{')
1773
-				$current_type = 'code';
1774
-			elseif ($type == '}')
1871
+				if ($do_current) {
1872
+									nextSubstep(++$substep);
1873
+				} else {
1874
+									$substep++;
1875
+				}
1876
+			} elseif ($type == '{') {
1877
+							$current_type = 'code';
1878
+			} elseif ($type == '}')
1775 1879
 			{
1776 1880
 				$current_type = 'sql';
1777 1881
 
@@ -1784,8 +1888,9 @@  discard block
 block discarded – undo
1784 1888
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1785 1889
 				{
1786 1890
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1787
-					if ($command_line)
1788
-						echo $upcontext['error_message'];
1891
+					if ($command_line) {
1892
+											echo $upcontext['error_message'];
1893
+					}
1789 1894
 				}
1790 1895
 
1791 1896
 				// Done with code!
@@ -1865,8 +1970,9 @@  discard block
 block discarded – undo
1865 1970
 	$db_unbuffered = false;
1866 1971
 
1867 1972
 	// Failure?!
1868
-	if ($result !== false)
1869
-		return $result;
1973
+	if ($result !== false) {
1974
+			return $result;
1975
+	}
1870 1976
 
1871 1977
 	$db_error_message = $smcFunc['db_error']($db_connection);
1872 1978
 	// If MySQL we do something more clever.
@@ -1894,54 +2000,61 @@  discard block
 block discarded – undo
1894 2000
 			{
1895 2001
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1896 2002
 				$result = mysqli_query($db_connection, $string);
1897
-				if ($result !== false)
1898
-					return $result;
2003
+				if ($result !== false) {
2004
+									return $result;
2005
+				}
1899 2006
 			}
1900
-		}
1901
-		elseif ($mysqli_errno == 2013)
2007
+		} elseif ($mysqli_errno == 2013)
1902 2008
 		{
1903 2009
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1904 2010
 			mysqli_select_db($db_connection, $db_name);
1905 2011
 			if ($db_connection)
1906 2012
 			{
1907 2013
 				$result = mysqli_query($db_connection, $string);
1908
-				if ($result !== false)
1909
-					return $result;
2014
+				if ($result !== false) {
2015
+									return $result;
2016
+				}
1910 2017
 			}
1911 2018
 		}
1912 2019
 		// Duplicate column name... should be okay ;).
1913
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1914
-			return false;
2020
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2021
+					return false;
2022
+		}
1915 2023
 		// Duplicate insert... make sure it's the proper type of query ;).
1916
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1917
-			return false;
2024
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2025
+					return false;
2026
+		}
1918 2027
 		// Creating an index on a non-existent column.
1919
-		elseif ($mysqli_errno == 1072)
1920
-			return false;
1921
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1922
-			return false;
2028
+		elseif ($mysqli_errno == 1072) {
2029
+					return false;
2030
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2031
+					return false;
2032
+		}
1923 2033
 	}
1924 2034
 	// If a table already exists don't go potty.
1925 2035
 	else
1926 2036
 	{
1927 2037
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1928 2038
 		{
1929
-			if (strpos($db_error_message, 'exist') !== false)
1930
-				return true;
1931
-		}
1932
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2039
+			if (strpos($db_error_message, 'exist') !== false) {
2040
+							return true;
2041
+			}
2042
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1933 2043
 		{
1934
-			if (strpos($db_error_message, 'duplicate') !== false)
1935
-				return true;
2044
+			if (strpos($db_error_message, 'duplicate') !== false) {
2045
+							return true;
2046
+			}
1936 2047
 		}
1937 2048
 	}
1938 2049
 
1939 2050
 	// Get the query string so we pass everything.
1940 2051
 	$query_string = '';
1941
-	foreach ($_GET as $k => $v)
1942
-		$query_string .= ';' . $k . '=' . $v;
1943
-	if (strlen($query_string) != 0)
1944
-		$query_string = '?' . substr($query_string, 1);
2052
+	foreach ($_GET as $k => $v) {
2053
+			$query_string .= ';' . $k . '=' . $v;
2054
+	}
2055
+	if (strlen($query_string) != 0) {
2056
+			$query_string = '?' . substr($query_string, 1);
2057
+	}
1945 2058
 
1946 2059
 	if ($command_line)
1947 2060
 	{
@@ -1996,16 +2109,18 @@  discard block
 block discarded – undo
1996 2109
 			{
1997 2110
 				$found |= 1;
1998 2111
 				// Do some checks on the data if we have it set.
1999
-				if (isset($change['col_type']))
2000
-					$found &= $change['col_type'] === $column['type'];
2001
-				if (isset($change['null_allowed']))
2002
-					$found &= $column['null'] == $change['null_allowed'];
2003
-				if (isset($change['default']))
2004
-					$found &= $change['default'] === $column['default'];
2112
+				if (isset($change['col_type'])) {
2113
+									$found &= $change['col_type'] === $column['type'];
2114
+				}
2115
+				if (isset($change['null_allowed'])) {
2116
+									$found &= $column['null'] == $change['null_allowed'];
2117
+				}
2118
+				if (isset($change['default'])) {
2119
+									$found &= $change['default'] === $column['default'];
2120
+				}
2005 2121
 			}
2006 2122
 		}
2007
-	}
2008
-	elseif ($change['type'] === 'index')
2123
+	} elseif ($change['type'] === 'index')
2009 2124
 	{
2010 2125
 		$request = upgrade_query('
2011 2126
 			SHOW INDEX
@@ -2014,9 +2129,10 @@  discard block
 block discarded – undo
2014 2129
 		{
2015 2130
 			$cur_index = array();
2016 2131
 
2017
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2018
-				if ($row['Key_name'] === $change['name'])
2132
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2133
+							if ($row['Key_name'] === $change['name'])
2019 2134
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2135
+			}
2020 2136
 
2021 2137
 			ksort($cur_index, SORT_NUMERIC);
2022 2138
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2026,14 +2142,17 @@  discard block
 block discarded – undo
2026 2142
 	}
2027 2143
 
2028 2144
 	// If we're trying to add and it's added, we're done.
2029
-	if ($found && in_array($change['method'], array('add', 'change')))
2030
-		return true;
2145
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2146
+			return true;
2147
+	}
2031 2148
 	// Otherwise if we're removing and it wasn't found we're also done.
2032
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2033
-		return true;
2149
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2150
+			return true;
2151
+	}
2034 2152
 	// Otherwise is it just a test?
2035
-	elseif ($is_test)
2036
-		return false;
2153
+	elseif ($is_test) {
2154
+			return false;
2155
+	}
2037 2156
 
2038 2157
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2039 2158
 	$running = false;
@@ -2044,8 +2163,9 @@  discard block
 block discarded – undo
2044 2163
 			SHOW FULL PROCESSLIST');
2045 2164
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2046 2165
 		{
2047
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2048
-				$found = true;
2166
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2167
+							$found = true;
2168
+			}
2049 2169
 		}
2050 2170
 
2051 2171
 		// Can't find it? Then we need to run it fools!
@@ -2057,8 +2177,9 @@  discard block
 block discarded – undo
2057 2177
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2058 2178
 				' . $change['text'], true) !== false;
2059 2179
 
2060
-			if (!$success)
2061
-				return false;
2180
+			if (!$success) {
2181
+							return false;
2182
+			}
2062 2183
 
2063 2184
 			// Return
2064 2185
 			$running = true;
@@ -2100,8 +2221,9 @@  discard block
 block discarded – undo
2100 2221
 			'db_error_skip' => true,
2101 2222
 		)
2102 2223
 	);
2103
-	if ($smcFunc['db_num_rows']($request) === 0)
2104
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2224
+	if ($smcFunc['db_num_rows']($request) === 0) {
2225
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2226
+	}
2105 2227
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2106 2228
 	$smcFunc['db_free_result']($request);
2107 2229
 
@@ -2123,18 +2245,19 @@  discard block
 block discarded – undo
2123 2245
 			)
2124 2246
 		);
2125 2247
 		// No results? Just forget it all together.
2126
-		if ($smcFunc['db_num_rows']($request) === 0)
2127
-			unset($table_row['Collation']);
2128
-		else
2129
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2248
+		if ($smcFunc['db_num_rows']($request) === 0) {
2249
+					unset($table_row['Collation']);
2250
+		} else {
2251
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2252
+		}
2130 2253
 		$smcFunc['db_free_result']($request);
2131 2254
 	}
2132 2255
 
2133 2256
 	if ($column_fix)
2134 2257
 	{
2135 2258
 		// Make sure there are no NULL's left.
2136
-		if ($null_fix)
2137
-			$smcFunc['db_query']('', '
2259
+		if ($null_fix) {
2260
+					$smcFunc['db_query']('', '
2138 2261
 				UPDATE {db_prefix}' . $change['table'] . '
2139 2262
 				SET ' . $change['column'] . ' = {string:default}
2140 2263
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2143,6 +2266,7 @@  discard block
 block discarded – undo
2143 2266
 					'db_error_skip' => true,
2144 2267
 				)
2145 2268
 			);
2269
+		}
2146 2270
 
2147 2271
 		// Do the actual alteration.
2148 2272
 		$smcFunc['db_query']('', '
@@ -2171,8 +2295,9 @@  discard block
 block discarded – undo
2171 2295
 	}
2172 2296
 
2173 2297
 	// Not a column we need to check on?
2174
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2175
-		return;
2298
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2299
+			return;
2300
+	}
2176 2301
 
2177 2302
 	// Break it up you (six|seven).
2178 2303
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2191,13 +2316,13 @@  discard block
 block discarded – undo
2191 2316
 				'new_name' => $temp[2],
2192 2317
 		));
2193 2318
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2194
-		if ($smcFunc['db_num_rows'] != 1)
2195
-			return;
2319
+		if ($smcFunc['db_num_rows'] != 1) {
2320
+					return;
2321
+		}
2196 2322
 
2197 2323
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2198 2324
 		$smcFunc['db_free_result']($request);
2199
-	}
2200
-	else
2325
+	} else
2201 2326
 	{
2202 2327
 		// Do this the old fashion, sure method way.
2203 2328
 		$request = $smcFunc['db_query']('', '
@@ -2208,21 +2333,24 @@  discard block
 block discarded – undo
2208 2333
 		));
2209 2334
 		// Mayday!
2210 2335
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2211
-		if ($smcFunc['db_num_rows'] == 0)
2212
-			return;
2336
+		if ($smcFunc['db_num_rows'] == 0) {
2337
+					return;
2338
+		}
2213 2339
 
2214 2340
 		// Oh where, oh where has my little field gone. Oh where can it be...
2215
-		while ($row = $smcFunc['db_query']($request))
2216
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2341
+		while ($row = $smcFunc['db_query']($request)) {
2342
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2217 2343
 			{
2218 2344
 				$current_type = $row['Type'];
2345
+		}
2219 2346
 				break;
2220 2347
 			}
2221 2348
 	}
2222 2349
 
2223 2350
 	// If this doesn't match, the column may of been altered for a reason.
2224
-	if (trim($current_type) != trim($temp[3]))
2225
-		$temp[3] = $current_type;
2351
+	if (trim($current_type) != trim($temp[3])) {
2352
+			$temp[3] = $current_type;
2353
+	}
2226 2354
 
2227 2355
 	// Piece this back together.
2228 2356
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2234,8 +2362,9 @@  discard block
 block discarded – undo
2234 2362
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2235 2363
 	global $step_progress, $is_debug, $upcontext;
2236 2364
 
2237
-	if ($_GET['substep'] < $substep)
2238
-		$_GET['substep'] = $substep;
2365
+	if ($_GET['substep'] < $substep) {
2366
+			$_GET['substep'] = $substep;
2367
+	}
2239 2368
 
2240 2369
 	if ($command_line)
2241 2370
 	{
@@ -2248,29 +2377,33 @@  discard block
 block discarded – undo
2248 2377
 	}
2249 2378
 
2250 2379
 	@set_time_limit(300);
2251
-	if (function_exists('apache_reset_timeout'))
2252
-		@apache_reset_timeout();
2380
+	if (function_exists('apache_reset_timeout')) {
2381
+			@apache_reset_timeout();
2382
+	}
2253 2383
 
2254
-	if (time() - $start_time <= $timeLimitThreshold)
2255
-		return;
2384
+	if (time() - $start_time <= $timeLimitThreshold) {
2385
+			return;
2386
+	}
2256 2387
 
2257 2388
 	// Do we have some custom step progress stuff?
2258 2389
 	if (!empty($step_progress))
2259 2390
 	{
2260 2391
 		$upcontext['substep_progress'] = 0;
2261 2392
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2262
-		if ($step_progress['current'] > $step_progress['total'])
2263
-			$upcontext['substep_progress'] = 99.9;
2264
-		else
2265
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2393
+		if ($step_progress['current'] > $step_progress['total']) {
2394
+					$upcontext['substep_progress'] = 99.9;
2395
+		} else {
2396
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2397
+		}
2266 2398
 
2267 2399
 		// Make it nicely rounded.
2268 2400
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2269 2401
 	}
2270 2402
 
2271 2403
 	// If this is XML we just exit right away!
2272
-	if (isset($_GET['xml']))
2273
-		return upgradeExit();
2404
+	if (isset($_GET['xml'])) {
2405
+			return upgradeExit();
2406
+	}
2274 2407
 
2275 2408
 	// We're going to pause after this!
2276 2409
 	$upcontext['pause'] = true;
@@ -2278,13 +2411,15 @@  discard block
 block discarded – undo
2278 2411
 	$upcontext['query_string'] = '';
2279 2412
 	foreach ($_GET as $k => $v)
2280 2413
 	{
2281
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2282
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2414
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2415
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2416
+		}
2283 2417
 	}
2284 2418
 
2285 2419
 	// Custom warning?
2286
-	if (!empty($custom_warning))
2287
-		$upcontext['custom_warning'] = $custom_warning;
2420
+	if (!empty($custom_warning)) {
2421
+			$upcontext['custom_warning'] = $custom_warning;
2422
+	}
2288 2423
 
2289 2424
 	upgradeExit();
2290 2425
 }
@@ -2299,25 +2434,26 @@  discard block
 block discarded – undo
2299 2434
 	ob_implicit_flush(true);
2300 2435
 	@set_time_limit(600);
2301 2436
 
2302
-	if (!isset($_SERVER['argv']))
2303
-		$_SERVER['argv'] = array();
2437
+	if (!isset($_SERVER['argv'])) {
2438
+			$_SERVER['argv'] = array();
2439
+	}
2304 2440
 	$_GET['maint'] = 1;
2305 2441
 
2306 2442
 	foreach ($_SERVER['argv'] as $i => $arg)
2307 2443
 	{
2308
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2309
-			$_GET['lang'] = $match[1];
2310
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2311
-			continue;
2312
-		elseif ($arg == '--no-maintenance')
2313
-			$_GET['maint'] = 0;
2314
-		elseif ($arg == '--debug')
2315
-			$is_debug = true;
2316
-		elseif ($arg == '--backup')
2317
-			$_POST['backup'] = 1;
2318
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2319
-			$_GET['conv'] = 1;
2320
-		elseif ($i != 0)
2444
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2445
+					$_GET['lang'] = $match[1];
2446
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2447
+					continue;
2448
+		} elseif ($arg == '--no-maintenance') {
2449
+					$_GET['maint'] = 0;
2450
+		} elseif ($arg == '--debug') {
2451
+					$is_debug = true;
2452
+		} elseif ($arg == '--backup') {
2453
+					$_POST['backup'] = 1;
2454
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2455
+					$_GET['conv'] = 1;
2456
+		} elseif ($i != 0)
2321 2457
 		{
2322 2458
 			echo 'SMF Command-line Upgrader
2323 2459
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2331,10 +2467,12 @@  discard block
 block discarded – undo
2331 2467
 		}
2332 2468
 	}
2333 2469
 
2334
-	if (!php_version_check())
2335
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2336
-	if (!db_version_check())
2337
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2470
+	if (!php_version_check()) {
2471
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2472
+	}
2473
+	if (!db_version_check()) {
2474
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2475
+	}
2338 2476
 
2339 2477
 	// Do some checks to make sure they have proper privileges
2340 2478
 	db_extend('packages');
@@ -2349,34 +2487,39 @@  discard block
 block discarded – undo
2349 2487
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2350 2488
 
2351 2489
 	// Sorry... we need CREATE, ALTER and DROP
2352
-	if (!$create || !$alter || !$drop)
2353
-		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);
2490
+	if (!$create || !$alter || !$drop) {
2491
+			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);
2492
+	}
2354 2493
 
2355 2494
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2356 2495
 		&& @file_exists($sourcedir . '/QueryString.php')
2357 2496
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2358
-	if (!$check && !isset($modSettings['smfVersion']))
2359
-		print_error('Error: Some files are missing or out-of-date.', true);
2497
+	if (!$check && !isset($modSettings['smfVersion'])) {
2498
+			print_error('Error: Some files are missing or out-of-date.', true);
2499
+	}
2360 2500
 
2361 2501
 	// Do a quick version spot check.
2362 2502
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2363 2503
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2364
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2365
-		print_error('Error: Some files have not yet been updated properly.');
2504
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2505
+			print_error('Error: Some files have not yet been updated properly.');
2506
+	}
2366 2507
 
2367 2508
 	// Make sure Settings.php is writable.
2368 2509
 		quickFileWritable($boarddir . '/Settings.php');
2369
-	if (!is_writable($boarddir . '/Settings.php'))
2370
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2510
+	if (!is_writable($boarddir . '/Settings.php')) {
2511
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2512
+	}
2371 2513
 
2372 2514
 	// Make sure Settings_bak.php is writable.
2373 2515
 		quickFileWritable($boarddir . '/Settings_bak.php');
2374
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2375
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2516
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2517
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2518
+	}
2376 2519
 
2377
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2378
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2379
-	elseif (isset($modSettings['agreement']))
2520
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2521
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2522
+	} elseif (isset($modSettings['agreement']))
2380 2523
 	{
2381 2524
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2382 2525
 		fwrite($fp, $modSettings['agreement']);
@@ -2386,31 +2529,36 @@  discard block
 block discarded – undo
2386 2529
 	// Make sure Themes is writable.
2387 2530
 	quickFileWritable($modSettings['theme_dir']);
2388 2531
 
2389
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2390
-		print_error('Error: Unable to obtain write access to "Themes".');
2532
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2533
+			print_error('Error: Unable to obtain write access to "Themes".');
2534
+	}
2391 2535
 
2392 2536
 	// Make sure cache directory exists and is writable!
2393 2537
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2394
-	if (!file_exists($cachedir_temp))
2395
-		@mkdir($cachedir_temp);
2538
+	if (!file_exists($cachedir_temp)) {
2539
+			@mkdir($cachedir_temp);
2540
+	}
2396 2541
 
2397 2542
 	// Make sure the cache temp dir is writable.
2398 2543
 	quickFileWritable($cachedir_temp);
2399 2544
 
2400
-	if (!is_writable($cachedir_temp))
2401
-		print_error('Error: Unable to obtain write access to "cache".', true);
2545
+	if (!is_writable($cachedir_temp)) {
2546
+			print_error('Error: Unable to obtain write access to "cache".', true);
2547
+	}
2402 2548
 
2403
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2404
-		print_error('Error: Unable to find language files!', true);
2405
-	else
2549
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2550
+			print_error('Error: Unable to find language files!', true);
2551
+	} else
2406 2552
 	{
2407 2553
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2408 2554
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2409 2555
 
2410
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2411
-			print_error('Error: Language files out of date.', true);
2412
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2413
-			print_error('Error: Install language is missing for selected language.', true);
2556
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2557
+					print_error('Error: Language files out of date.', true);
2558
+		}
2559
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2560
+					print_error('Error: Install language is missing for selected language.', true);
2561
+		}
2414 2562
 
2415 2563
 		// Otherwise include it!
2416 2564
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2429,8 +2577,9 @@  discard block
 block discarded – undo
2429 2577
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2430 2578
 
2431 2579
 	// Done it already?
2432
-	if (!empty($_POST['utf8_done']))
2433
-		return true;
2580
+	if (!empty($_POST['utf8_done'])) {
2581
+			return true;
2582
+	}
2434 2583
 
2435 2584
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2436 2585
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2443,8 +2592,7 @@  discard block
 block discarded – undo
2443 2592
 		);
2444 2593
 
2445 2594
 		return true;
2446
-	}
2447
-	else
2595
+	} else
2448 2596
 	{
2449 2597
 		$upcontext['page_title'] = 'Converting to UTF8';
2450 2598
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2488,8 +2636,9 @@  discard block
 block discarded – undo
2488 2636
 			)
2489 2637
 		);
2490 2638
 		$db_charsets = array();
2491
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2492
-			$db_charsets[] = $row['Charset'];
2639
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2640
+					$db_charsets[] = $row['Charset'];
2641
+		}
2493 2642
 
2494 2643
 		$smcFunc['db_free_result']($request);
2495 2644
 
@@ -2525,13 +2674,15 @@  discard block
 block discarded – undo
2525 2674
 		// If there's a fulltext index, we need to drop it first...
2526 2675
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2527 2676
 		{
2528
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2529
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2677
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2678
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2530 2679
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2680
+			}
2531 2681
 			$smcFunc['db_free_result']($request);
2532 2682
 
2533
-			if (isset($upcontext['fulltext_index']))
2534
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2683
+			if (isset($upcontext['fulltext_index'])) {
2684
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2685
+			}
2535 2686
 		}
2536 2687
 
2537 2688
 		// Drop it and make a note...
@@ -2721,8 +2872,9 @@  discard block
 block discarded – undo
2721 2872
 			$replace = '%field%';
2722 2873
 
2723 2874
 			// Build a huge REPLACE statement...
2724
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2725
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2875
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2876
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2877
+			}
2726 2878
 		}
2727 2879
 
2728 2880
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2732,9 +2884,10 @@  discard block
 block discarded – undo
2732 2884
 		$upcontext['table_count'] = count($queryTables);
2733 2885
 
2734 2886
 		// What ones have we already done?
2735
-		foreach ($queryTables as $id => $table)
2736
-			if ($id < $_GET['substep'])
2887
+		foreach ($queryTables as $id => $table) {
2888
+					if ($id < $_GET['substep'])
2737 2889
 				$upcontext['previous_tables'][] = $table;
2890
+		}
2738 2891
 
2739 2892
 		$upcontext['cur_table_num'] = $_GET['substep'];
2740 2893
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2771,8 +2924,9 @@  discard block
 block discarded – undo
2771 2924
 			nextSubstep($substep);
2772 2925
 
2773 2926
 			// Just to make sure it doesn't time out.
2774
-			if (function_exists('apache_reset_timeout'))
2775
-				@apache_reset_timeout();
2927
+			if (function_exists('apache_reset_timeout')) {
2928
+							@apache_reset_timeout();
2929
+			}
2776 2930
 
2777 2931
 			$table_charsets = array();
2778 2932
 
@@ -2795,8 +2949,9 @@  discard block
 block discarded – undo
2795 2949
 
2796 2950
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2797 2951
 						if ($charset != 'utf8') {
2798
-							if (!isset($table_charsets[$charset]))
2799
-								$table_charsets[$charset] = array();
2952
+							if (!isset($table_charsets[$charset])) {
2953
+															$table_charsets[$charset] = array();
2954
+							}
2800 2955
 
2801 2956
 							$table_charsets[$charset][] = $column_info;
2802 2957
 						}
@@ -2837,10 +2992,11 @@  discard block
 block discarded – undo
2837 2992
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2838 2993
 				{
2839 2994
 					$update = '';
2840
-					foreach ($table_charsets as $charset => $columns)
2841
-						foreach ($columns as $column)
2995
+					foreach ($table_charsets as $charset => $columns) {
2996
+											foreach ($columns as $column)
2842 2997
 							$update .= '
2843 2998
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2999
+					}
2844 3000
 
2845 3001
 					$smcFunc['db_query']('', '
2846 3002
 						UPDATE {raw:table_name}
@@ -2865,8 +3021,9 @@  discard block
 block discarded – undo
2865 3021
 			// Now do the actual conversion (if still needed).
2866 3022
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2867 3023
 			{
2868
-				if ($command_line)
2869
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3024
+				if ($command_line) {
3025
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3026
+				}
2870 3027
 
2871 3028
 				$smcFunc['db_query']('', '
2872 3029
 					ALTER TABLE {raw:table_name}
@@ -2876,12 +3033,14 @@  discard block
 block discarded – undo
2876 3033
 					)
2877 3034
 				);
2878 3035
 
2879
-				if ($command_line)
2880
-					echo " done.\n";
3036
+				if ($command_line) {
3037
+									echo " done.\n";
3038
+				}
2881 3039
 			}
2882 3040
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2883
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2884
-				return upgradeExit();
3041
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3042
+							return upgradeExit();
3043
+			}
2885 3044
 		}
2886 3045
 
2887 3046
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2910,8 +3069,8 @@  discard block
 block discarded – undo
2910 3069
 		);
2911 3070
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2912 3071
 		{
2913
-			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)
2914
-				$smcFunc['db_query']('', '
3072
+			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) {
3073
+							$smcFunc['db_query']('', '
2915 3074
 					UPDATE {db_prefix}log_actions
2916 3075
 					SET extra = {string:extra}
2917 3076
 					WHERE id_action = {int:current_action}',
@@ -2920,6 +3079,7 @@  discard block
 block discarded – undo
2920 3079
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2921 3080
 					)
2922 3081
 				);
3082
+			}
2923 3083
 		}
2924 3084
 		$smcFunc['db_free_result']($request);
2925 3085
 
@@ -2941,15 +3101,17 @@  discard block
 block discarded – undo
2941 3101
 	// First thing's first - did we already do this?
2942 3102
 	if (!empty($modSettings['json_done']))
2943 3103
 	{
2944
-		if ($command_line)
2945
-			return DeleteUpgrade();
2946
-		else
2947
-			return true;
3104
+		if ($command_line) {
3105
+					return DeleteUpgrade();
3106
+		} else {
3107
+					return true;
3108
+		}
2948 3109
 	}
2949 3110
 
2950 3111
 	// Done it already - js wise?
2951
-	if (!empty($_POST['json_done']))
2952
-		return true;
3112
+	if (!empty($_POST['json_done'])) {
3113
+			return true;
3114
+	}
2953 3115
 
2954 3116
 	// List of tables affected by this function
2955 3117
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2981,12 +3143,14 @@  discard block
 block discarded – undo
2981 3143
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2982 3144
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2983 3145
 
2984
-	foreach ($keys as $id => $table)
2985
-		if ($id < $_GET['substep'])
3146
+	foreach ($keys as $id => $table) {
3147
+			if ($id < $_GET['substep'])
2986 3148
 			$upcontext['previous_tables'][] = $table;
3149
+	}
2987 3150
 
2988
-	if ($command_line)
2989
-		echo 'Converting data from serialize() to json_encode().';
3151
+	if ($command_line) {
3152
+			echo 'Converting data from serialize() to json_encode().';
3153
+	}
2990 3154
 
2991 3155
 	if (!$support_js || isset($_GET['xml']))
2992 3156
 	{
@@ -3026,8 +3190,9 @@  discard block
 block discarded – undo
3026 3190
 
3027 3191
 				// Loop through and fix these...
3028 3192
 				$new_settings = array();
3029
-				if ($command_line)
3030
-					echo "\n" . 'Fixing some settings...';
3193
+				if ($command_line) {
3194
+									echo "\n" . 'Fixing some settings...';
3195
+				}
3031 3196
 
3032 3197
 				foreach ($serialized_settings as $var)
3033 3198
 				{
@@ -3035,22 +3200,24 @@  discard block
 block discarded – undo
3035 3200
 					{
3036 3201
 						// Attempt to unserialize the setting
3037 3202
 						$temp = @safe_unserialize($modSettings[$var]);
3038
-						if (!$temp && $command_line)
3039
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3040
-						elseif ($temp !== false)
3041
-							$new_settings[$var] = json_encode($temp);
3203
+						if (!$temp && $command_line) {
3204
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3205
+						} elseif ($temp !== false) {
3206
+													$new_settings[$var] = json_encode($temp);
3207
+						}
3042 3208
 					}
3043 3209
 				}
3044 3210
 
3045 3211
 				// Update everything at once
3046
-				if (!function_exists('cache_put_data'))
3047
-					require_once($sourcedir . '/Load.php');
3212
+				if (!function_exists('cache_put_data')) {
3213
+									require_once($sourcedir . '/Load.php');
3214
+				}
3048 3215
 				updateSettings($new_settings, true);
3049 3216
 
3050
-				if ($command_line)
3051
-					echo ' done.';
3052
-			}
3053
-			elseif ($table == 'themes')
3217
+				if ($command_line) {
3218
+									echo ' done.';
3219
+				}
3220
+			} elseif ($table == 'themes')
3054 3221
 			{
3055 3222
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3056 3223
 				$query = $smcFunc['db_query']('', '
@@ -3069,10 +3236,11 @@  discard block
 block discarded – undo
3069 3236
 
3070 3237
 						if ($command_line)
3071 3238
 						{
3072
-							if ($temp === false)
3073
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3074
-							else
3075
-								echo "\n" . 'Fixing admin preferences...';
3239
+							if ($temp === false) {
3240
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3241
+							} else {
3242
+															echo "\n" . 'Fixing admin preferences...';
3243
+							}
3076 3244
 						}
3077 3245
 
3078 3246
 						if ($temp !== false)
@@ -3094,15 +3262,15 @@  discard block
 block discarded – undo
3094 3262
 								)
3095 3263
 							);
3096 3264
 
3097
-							if ($command_line)
3098
-								echo ' done.';
3265
+							if ($command_line) {
3266
+															echo ' done.';
3267
+							}
3099 3268
 						}
3100 3269
 					}
3101 3270
 
3102 3271
 					$smcFunc['db_free_result']($query);
3103 3272
 				}
3104
-			}
3105
-			else
3273
+			} else
3106 3274
 			{
3107 3275
 				// First item is always the key...
3108 3276
 				$key = $info[0];
@@ -3113,8 +3281,7 @@  discard block
 block discarded – undo
3113 3281
 				{
3114 3282
 					$col_select = $info[1];
3115 3283
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3116
-				}
3117
-				else
3284
+				} else
3118 3285
 				{
3119 3286
 					$col_select = implode(', ', $info);
3120 3287
 				}
@@ -3147,8 +3314,7 @@  discard block
 block discarded – undo
3147 3314
 								if ($temp === false && $command_line)
3148 3315
 								{
3149 3316
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3150
-								}
3151
-								else
3317
+								} else
3152 3318
 								{
3153 3319
 									$row[$col] = json_encode($temp);
3154 3320
 
@@ -3173,16 +3339,18 @@  discard block
 block discarded – undo
3173 3339
 						}
3174 3340
 					}
3175 3341
 
3176
-					if ($command_line)
3177
-						echo ' done.';
3342
+					if ($command_line) {
3343
+											echo ' done.';
3344
+					}
3178 3345
 
3179 3346
 					// Free up some memory...
3180 3347
 					$smcFunc['db_free_result']($query);
3181 3348
 				}
3182 3349
 			}
3183 3350
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3184
-			if (isset($_GET['xml']))
3185
-				return upgradeExit();
3351
+			if (isset($_GET['xml'])) {
3352
+							return upgradeExit();
3353
+			}
3186 3354
 		}
3187 3355
 
3188 3356
 		if ($command_line)
@@ -3197,8 +3365,9 @@  discard block
 block discarded – undo
3197 3365
 
3198 3366
 		$_GET['substep'] = 0;
3199 3367
 		// Make sure we move on!
3200
-		if ($command_line)
3201
-			return DeleteUpgrade();
3368
+		if ($command_line) {
3369
+					return DeleteUpgrade();
3370
+		}
3202 3371
 
3203 3372
 		return true;
3204 3373
 	}
@@ -3218,14 +3387,16 @@  discard block
 block discarded – undo
3218 3387
 	global $upcontext, $txt, $settings;
3219 3388
 
3220 3389
 	// Don't call me twice!
3221
-	if (!empty($upcontext['chmod_called']))
3222
-		return;
3390
+	if (!empty($upcontext['chmod_called'])) {
3391
+			return;
3392
+	}
3223 3393
 
3224 3394
 	$upcontext['chmod_called'] = true;
3225 3395
 
3226 3396
 	// Nothing?
3227
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3228
-		return;
3397
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3398
+			return;
3399
+	}
3229 3400
 
3230 3401
 	// Was it a problem with Windows?
3231 3402
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3257,11 +3428,12 @@  discard block
 block discarded – undo
3257 3428
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3258 3429
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3259 3430
 
3260
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3261
-		echo '
3431
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3432
+			echo '
3262 3433
 					content.write(\'<hr>\n\t\t\t\');
3263 3434
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3264 3435
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3436
+	}
3265 3437
 
3266 3438
 	echo '
3267 3439
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3269,17 +3441,19 @@  discard block
 block discarded – undo
3269 3441
 				}
3270 3442
 			</script>';
3271 3443
 
3272
-	if (!empty($upcontext['chmod']['ftp_error']))
3273
-		echo '
3444
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3445
+			echo '
3274 3446
 			<div class="error_message red">
3275 3447
 				The following error was encountered when trying to connect:<br><br>
3276 3448
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3277 3449
 			</div>
3278 3450
 			<br>';
3451
+	}
3279 3452
 
3280
-	if (empty($upcontext['chmod_in_form']))
3281
-		echo '
3453
+	if (empty($upcontext['chmod_in_form'])) {
3454
+			echo '
3282 3455
 	<form action="', $upcontext['form_url'], '" method="post">';
3456
+	}
3283 3457
 
3284 3458
 	echo '
3285 3459
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3314,10 +3488,11 @@  discard block
 block discarded – undo
3314 3488
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3315 3489
 	</div>';
3316 3490
 
3317
-	if (empty($upcontext['chmod_in_form']))
3318
-		echo '
3491
+	if (empty($upcontext['chmod_in_form'])) {
3492
+			echo '
3319 3493
 	</form>';
3320
-}
3494
+	}
3495
+	}
3321 3496
 
3322 3497
 function template_upgrade_above()
3323 3498
 {
@@ -3377,9 +3552,10 @@  discard block
 block discarded – undo
3377 3552
 				<h2>', $txt['upgrade_progress'], '</h2>
3378 3553
 				<ul>';
3379 3554
 
3380
-	foreach ($upcontext['steps'] as $num => $step)
3381
-		echo '
3555
+	foreach ($upcontext['steps'] as $num => $step) {
3556
+			echo '
3382 3557
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3558
+	}
3383 3559
 
3384 3560
 	echo '
3385 3561
 					</ul>
@@ -3392,8 +3568,8 @@  discard block
 block discarded – undo
3392 3568
 				</div>
3393 3569
 			</div>';
3394 3570
 
3395
-	if (isset($upcontext['step_progress']))
3396
-		echo '
3571
+	if (isset($upcontext['step_progress'])) {
3572
+			echo '
3397 3573
 				<br>
3398 3574
 				<br>
3399 3575
 				<div id="progress_bar_step">
@@ -3402,6 +3578,7 @@  discard block
 block discarded – undo
3402 3578
 						<span>', $txt['upgrade_step_progress'], '</span>
3403 3579
 					</div>
3404 3580
 				</div>';
3581
+	}
3405 3582
 
3406 3583
 	echo '
3407 3584
 				<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>
@@ -3432,32 +3609,36 @@  discard block
 block discarded – undo
3432 3609
 {
3433 3610
 	global $upcontext, $txt;
3434 3611
 
3435
-	if (!empty($upcontext['pause']))
3436
-		echo '
3612
+	if (!empty($upcontext['pause'])) {
3613
+			echo '
3437 3614
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3438 3615
 
3439 3616
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3440 3617
 								<h3>
3441 3618
 									', $txt['upgrade_paused_overload'], '
3442 3619
 								</h3>';
3620
+	}
3443 3621
 
3444
-	if (!empty($upcontext['custom_warning']))
3445
-		echo '
3622
+	if (!empty($upcontext['custom_warning'])) {
3623
+			echo '
3446 3624
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3447 3625
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3448 3626
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3449 3627
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3450 3628
 								</div>';
3629
+	}
3451 3630
 
3452 3631
 	echo '
3453 3632
 								<div class="righttext" style="margin: 1ex;">';
3454 3633
 
3455
-	if (!empty($upcontext['continue']))
3456
-		echo '
3634
+	if (!empty($upcontext['continue'])) {
3635
+			echo '
3457 3636
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3458
-	if (!empty($upcontext['skip']))
3459
-		echo '
3637
+	}
3638
+	if (!empty($upcontext['skip'])) {
3639
+			echo '
3460 3640
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3641
+	}
3461 3642
 
3462 3643
 	echo '
3463 3644
 								</div>
@@ -3507,11 +3688,12 @@  discard block
 block discarded – undo
3507 3688
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3508 3689
 	<smf>';
3509 3690
 
3510
-	if (!empty($upcontext['get_data']))
3511
-		foreach ($upcontext['get_data'] as $k => $v)
3691
+	if (!empty($upcontext['get_data'])) {
3692
+			foreach ($upcontext['get_data'] as $k => $v)
3512 3693
 			echo '
3513 3694
 		<get key="', $k, '">', $v, '</get>';
3514
-}
3695
+	}
3696
+	}
3515 3697
 
3516 3698
 function template_xml_below()
3517 3699
 {
@@ -3552,8 +3734,8 @@  discard block
 block discarded – undo
3552 3734
 	template_chmod();
3553 3735
 
3554 3736
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3555
-	if ($upcontext['is_large_forum'])
3556
-		echo '
3737
+	if ($upcontext['is_large_forum']) {
3738
+			echo '
3557 3739
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3558 3740
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3559 3741
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3561,10 +3743,11 @@  discard block
 block discarded – undo
3561 3743
 				', $txt['upgrade_warning_lots_data'], '
3562 3744
 			</div>
3563 3745
 		</div>';
3746
+	}
3564 3747
 
3565 3748
 	// A warning message?
3566
-	if (!empty($upcontext['warning']))
3567
-		echo '
3749
+	if (!empty($upcontext['warning'])) {
3750
+			echo '
3568 3751
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3569 3752
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3570 3753
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3572,6 +3755,7 @@  discard block
 block discarded – undo
3572 3755
 				', $upcontext['warning'], '
3573 3756
 			</div>
3574 3757
 		</div>';
3758
+	}
3575 3759
 
3576 3760
 	// Paths are incorrect?
3577 3761
 	echo '
@@ -3587,20 +3771,22 @@  discard block
 block discarded – undo
3587 3771
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3588 3772
 	{
3589 3773
 		$ago = time() - $upcontext['started'];
3590
-		if ($ago < 60)
3591
-			$ago = $ago . ' seconds';
3592
-		elseif ($ago < 3600)
3593
-			$ago = (int) ($ago / 60) . ' minutes';
3594
-		else
3595
-			$ago = (int) ($ago / 3600) . ' hours';
3774
+		if ($ago < 60) {
3775
+					$ago = $ago . ' seconds';
3776
+		} elseif ($ago < 3600) {
3777
+					$ago = (int) ($ago / 60) . ' minutes';
3778
+		} else {
3779
+					$ago = (int) ($ago / 3600) . ' hours';
3780
+		}
3596 3781
 
3597 3782
 		$active = time() - $upcontext['updated'];
3598
-		if ($active < 60)
3599
-			$updated = $active . ' seconds';
3600
-		elseif ($active < 3600)
3601
-			$updated = (int) ($active / 60) . ' minutes';
3602
-		else
3603
-			$updated = (int) ($active / 3600) . ' hours';
3783
+		if ($active < 60) {
3784
+					$updated = $active . ' seconds';
3785
+		} elseif ($active < 3600) {
3786
+					$updated = (int) ($active / 60) . ' minutes';
3787
+		} else {
3788
+					$updated = (int) ($active / 3600) . ' hours';
3789
+		}
3604 3790
 
3605 3791
 		echo '
3606 3792
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3609,16 +3795,18 @@  discard block
 block discarded – undo
3609 3795
 			<div style="padding-left: 6ex;">
3610 3796
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3611 3797
 
3612
-		if ($active < 600)
3613
-			echo '
3798
+		if ($active < 600) {
3799
+					echo '
3614 3800
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3801
+		}
3615 3802
 
3616
-		if ($active > $upcontext['inactive_timeout'])
3617
-			echo '
3803
+		if ($active > $upcontext['inactive_timeout']) {
3804
+					echo '
3618 3805
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3619
-		else
3620
-			echo '
3806
+		} else {
3807
+					echo '
3621 3808
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3809
+		}
3622 3810
 
3623 3811
 		echo '
3624 3812
 			</div>
@@ -3634,9 +3822,10 @@  discard block
 block discarded – undo
3634 3822
 					<td>
3635 3823
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3636 3824
 
3637
-	if (!empty($upcontext['username_incorrect']))
3638
-		echo '
3825
+	if (!empty($upcontext['username_incorrect'])) {
3826
+			echo '
3639 3827
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3828
+	}
3640 3829
 
3641 3830
 	echo '
3642 3831
 					</td>
@@ -3647,9 +3836,10 @@  discard block
 block discarded – undo
3647 3836
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3648 3837
 						<input type="hidden" name="hash_passwrd" value="">';
3649 3838
 
3650
-	if (!empty($upcontext['password_failed']))
3651
-		echo '
3839
+	if (!empty($upcontext['password_failed'])) {
3840
+			echo '
3652 3841
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3842
+	}
3653 3843
 
3654 3844
 	echo '
3655 3845
 					</td>
@@ -3720,8 +3910,8 @@  discard block
 block discarded – undo
3720 3910
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3721 3911
 
3722 3912
 	// Warning message?
3723
-	if (!empty($upcontext['upgrade_options_warning']))
3724
-		echo '
3913
+	if (!empty($upcontext['upgrade_options_warning'])) {
3914
+			echo '
3725 3915
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3726 3916
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3727 3917
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3729,6 +3919,7 @@  discard block
 block discarded – undo
3729 3919
 				', $upcontext['upgrade_options_warning'], '
3730 3920
 			</div>
3731 3921
 		</div>';
3922
+	}
3732 3923
 
3733 3924
 	echo '
3734 3925
 				<table>
@@ -3771,8 +3962,8 @@  discard block
 block discarded – undo
3771 3962
 						</td>
3772 3963
 					</tr>';
3773 3964
 
3774
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3775
-		echo '
3965
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3966
+			echo '
3776 3967
 					<tr valign="top">
3777 3968
 						<td width="2%">
3778 3969
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3781,6 +3972,7 @@  discard block
 block discarded – undo
3781 3972
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3782 3973
 						</td>
3783 3974
 					</tr>';
3975
+	}
3784 3976
 
3785 3977
 	echo '
3786 3978
 					<tr valign="top">
@@ -3818,10 +4010,11 @@  discard block
 block discarded – undo
3818 4010
 			</div>';
3819 4011
 
3820 4012
 	// Dont any tables so far?
3821
-	if (!empty($upcontext['previous_tables']))
3822
-		foreach ($upcontext['previous_tables'] as $table)
4013
+	if (!empty($upcontext['previous_tables'])) {
4014
+			foreach ($upcontext['previous_tables'] as $table)
3823 4015
 			echo '
3824 4016
 			<br>Completed Table: &quot;', $table, '&quot;.';
4017
+	}
3825 4018
 
3826 4019
 	echo '
3827 4020
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3858,12 +4051,13 @@  discard block
 block discarded – undo
3858 4051
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3859 4052
 
3860 4053
 		// If debug flood the screen.
3861
-		if ($is_debug)
3862
-			echo '
4054
+		if ($is_debug) {
4055
+					echo '
3863 4056
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3864 4057
 
3865 4058
 				if (document.getElementById(\'debug_section\').scrollHeight)
3866 4059
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4060
+		}
3867 4061
 
3868 4062
 		echo '
3869 4063
 				// Get the next update...
@@ -3896,8 +4090,9 @@  discard block
 block discarded – undo
3896 4090
 {
3897 4091
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3898 4092
 
3899
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3900
-		$is_debug = true;
4093
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4094
+			$is_debug = true;
4095
+	}
3901 4096
 
3902 4097
 	echo '
3903 4098
 		<h3>Executing database changes</h3>
@@ -3912,8 +4107,9 @@  discard block
 block discarded – undo
3912 4107
 	{
3913 4108
 		foreach ($upcontext['actioned_items'] as $num => $item)
3914 4109
 		{
3915
-			if ($num != 0)
3916
-				echo ' Successful!';
4110
+			if ($num != 0) {
4111
+							echo ' Successful!';
4112
+			}
3917 4113
 			echo '<br>' . $item;
3918 4114
 		}
3919 4115
 		if (!empty($upcontext['changes_complete']))
@@ -3926,28 +4122,32 @@  discard block
 block discarded – undo
3926 4122
 				$seconds = intval($active % 60);
3927 4123
 
3928 4124
 				$totalTime = '';
3929
-				if ($hours > 0)
3930
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3931
-				if ($minutes > 0)
3932
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3933
-				if ($seconds > 0)
3934
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4125
+				if ($hours > 0) {
4126
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4127
+				}
4128
+				if ($minutes > 0) {
4129
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4130
+				}
4131
+				if ($seconds > 0) {
4132
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4133
+				}
3935 4134
 			}
3936 4135
 
3937
-			if ($is_debug && !empty($totalTime))
3938
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3939
-			else
3940
-				echo ' Successful!<br><br>';
4136
+			if ($is_debug && !empty($totalTime)) {
4137
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4138
+			} else {
4139
+							echo ' Successful!<br><br>';
4140
+			}
3941 4141
 
3942 4142
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3943 4143
 		}
3944
-	}
3945
-	else
4144
+	} else
3946 4145
 	{
3947 4146
 		// Tell them how many files we have in total.
3948
-		if ($upcontext['file_count'] > 1)
3949
-			echo '
4147
+		if ($upcontext['file_count'] > 1) {
4148
+					echo '
3950 4149
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4150
+		}
3951 4151
 
3952 4152
 		echo '
3953 4153
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3963,19 +4163,23 @@  discard block
 block discarded – undo
3963 4163
 				$seconds = intval($active % 60);
3964 4164
 
3965 4165
 				$totalTime = '';
3966
-				if ($hours > 0)
3967
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3968
-				if ($minutes > 0)
3969
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3970
-				if ($seconds > 0)
3971
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4166
+				if ($hours > 0) {
4167
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4168
+				}
4169
+				if ($minutes > 0) {
4170
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4171
+				}
4172
+				if ($seconds > 0) {
4173
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4174
+				}
3972 4175
 			}
3973 4176
 
3974 4177
 			echo '
3975 4178
 			<br><span id="upgradeCompleted">';
3976 4179
 
3977
-			if (!empty($totalTime))
3978
-				echo 'Completed in ', $totalTime, '<br>';
4180
+			if (!empty($totalTime)) {
4181
+							echo 'Completed in ', $totalTime, '<br>';
4182
+			}
3979 4183
 
3980 4184
 			echo '</span>
3981 4185
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4012,9 +4216,10 @@  discard block
 block discarded – undo
4012 4216
 			var getData = "";
4013 4217
 			var debugItems = ', $upcontext['debug_items'], ';';
4014 4218
 
4015
-		if ($is_debug)
4016
-			echo '
4219
+		if ($is_debug) {
4220
+					echo '
4017 4221
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4222
+		}
4018 4223
 
4019 4224
 		echo '
4020 4225
 			function getNextItem()
@@ -4054,9 +4259,10 @@  discard block
 block discarded – undo
4054 4259
 						document.getElementById("error_block").style.display = "";
4055 4260
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4056 4261
 
4057
-	if ($is_debug)
4058
-		echo '
4262
+	if ($is_debug) {
4263
+			echo '
4059 4264
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4265
+	}
4060 4266
 
4061 4267
 	echo '
4062 4268
 					}
@@ -4077,9 +4283,10 @@  discard block
 block discarded – undo
4077 4283
 						document.getElementById("error_block").style.display = "";
4078 4284
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4079 4285
 
4080
-	if ($is_debug)
4081
-		echo '
4286
+	if ($is_debug) {
4287
+			echo '
4082 4288
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4289
+	}
4083 4290
 
4084 4291
 	echo '
4085 4292
 					}
@@ -4138,8 +4345,8 @@  discard block
 block discarded – undo
4138 4345
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4139 4346
 				{';
4140 4347
 
4141
-		if ($is_debug)
4142
-			echo '
4348
+		if ($is_debug) {
4349
+					echo '
4143 4350
 					document.getElementById(\'debug_section\').style.display = "none";
4144 4351
 
4145 4352
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4157,6 +4364,7 @@  discard block
 block discarded – undo
4157 4364
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4158 4365
 
4159 4366
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4367
+		}
4160 4368
 
4161 4369
 		echo '
4162 4370
 
@@ -4164,9 +4372,10 @@  discard block
 block discarded – undo
4164 4372
 					document.getElementById(\'contbutt\').disabled = 0;
4165 4373
 					document.getElementById(\'database_done\').value = 1;';
4166 4374
 
4167
-		if ($upcontext['file_count'] > 1)
4168
-			echo '
4375
+		if ($upcontext['file_count'] > 1) {
4376
+					echo '
4169 4377
 					document.getElementById(\'info1\').style.display = "none";';
4378
+		}
4170 4379
 
4171 4380
 		echo '
4172 4381
 					document.getElementById(\'info2\').style.display = "none";
@@ -4179,9 +4388,10 @@  discard block
 block discarded – undo
4179 4388
 					lastItem = 0;
4180 4389
 					prevFile = curFile;';
4181 4390
 
4182
-		if ($is_debug)
4183
-			echo '
4391
+		if ($is_debug) {
4392
+					echo '
4184 4393
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4394
+		}
4185 4395
 
4186 4396
 		echo '
4187 4397
 					getNextItem();
@@ -4189,8 +4399,8 @@  discard block
 block discarded – undo
4189 4399
 				}';
4190 4400
 
4191 4401
 		// If debug scroll the screen.
4192
-		if ($is_debug)
4193
-			echo '
4402
+		if ($is_debug) {
4403
+					echo '
4194 4404
 				if (iLastSubStepProgress == -1)
4195 4405
 				{
4196 4406
 					// Give it consistent dots.
@@ -4209,6 +4419,7 @@  discard block
 block discarded – undo
4209 4419
 
4210 4420
 				if (document.getElementById(\'debug_section\').scrollHeight)
4211 4421
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4422
+		}
4212 4423
 
4213 4424
 		echo '
4214 4425
 				// Update the page.
@@ -4269,9 +4480,10 @@  discard block
 block discarded – undo
4269 4480
 			}';
4270 4481
 
4271 4482
 		// Start things off assuming we've not errored.
4272
-		if (empty($upcontext['error_message']))
4273
-			echo '
4483
+		if (empty($upcontext['error_message'])) {
4484
+					echo '
4274 4485
 			getNextItem();';
4486
+		}
4275 4487
 
4276 4488
 		echo '
4277 4489
 		//# sourceURL=dynamicScript-dbch.js
@@ -4289,18 +4501,21 @@  discard block
 block discarded – undo
4289 4501
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4290 4502
 	<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>';
4291 4503
 
4292
-	if (!empty($upcontext['error_message']))
4293
-		echo '
4504
+	if (!empty($upcontext['error_message'])) {
4505
+			echo '
4294 4506
 	<error>', $upcontext['error_message'], '</error>';
4507
+	}
4295 4508
 
4296
-	if (!empty($upcontext['error_string']))
4297
-		echo '
4509
+	if (!empty($upcontext['error_string'])) {
4510
+			echo '
4298 4511
 	<sql>', $upcontext['error_string'], '</sql>';
4512
+	}
4299 4513
 
4300
-	if ($is_debug)
4301
-		echo '
4514
+	if ($is_debug) {
4515
+			echo '
4302 4516
 	<curtime>', time(), '</curtime>';
4303
-}
4517
+	}
4518
+	}
4304 4519
 
4305 4520
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4306 4521
 function template_convert_utf8()
@@ -4319,18 +4534,20 @@  discard block
 block discarded – undo
4319 4534
 			</div>';
4320 4535
 
4321 4536
 	// Done any tables so far?
4322
-	if (!empty($upcontext['previous_tables']))
4323
-		foreach ($upcontext['previous_tables'] as $table)
4537
+	if (!empty($upcontext['previous_tables'])) {
4538
+			foreach ($upcontext['previous_tables'] as $table)
4324 4539
 			echo '
4325 4540
 			<br>Completed Table: &quot;', $table, '&quot;.';
4541
+	}
4326 4542
 
4327 4543
 	echo '
4328 4544
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4329 4545
 
4330 4546
 	// If we dropped their index, let's let them know
4331
-	if ($upcontext['dropping_index'])
4332
-		echo '
4547
+	if ($upcontext['dropping_index']) {
4548
+			echo '
4333 4549
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated in the admin area after the upgrade is complete.</span>';
4550
+	}
4334 4551
 
4335 4552
 	// Completion notification
4336 4553
 	echo '
@@ -4367,12 +4584,13 @@  discard block
 block discarded – undo
4367 4584
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4368 4585
 
4369 4586
 		// If debug flood the screen.
4370
-		if ($is_debug)
4371
-			echo '
4587
+		if ($is_debug) {
4588
+					echo '
4372 4589
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4373 4590
 
4374 4591
 				if (document.getElementById(\'debug_section\').scrollHeight)
4375 4592
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4593
+		}
4376 4594
 
4377 4595
 		echo '
4378 4596
 				// Get the next update...
@@ -4420,19 +4638,21 @@  discard block
 block discarded – undo
4420 4638
 			</div>';
4421 4639
 
4422 4640
 	// Dont any tables so far?
4423
-	if (!empty($upcontext['previous_tables']))
4424
-		foreach ($upcontext['previous_tables'] as $table)
4641
+	if (!empty($upcontext['previous_tables'])) {
4642
+			foreach ($upcontext['previous_tables'] as $table)
4425 4643
 			echo '
4426 4644
 			<br>Completed Table: &quot;', $table, '&quot;.';
4645
+	}
4427 4646
 
4428 4647
 	echo '
4429 4648
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4430 4649
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4431 4650
 
4432 4651
 	// Try to make sure substep was reset.
4433
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4434
-		echo '
4652
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4653
+			echo '
4435 4654
 			<input type="hidden" name="substep" id="substep" value="0">';
4655
+	}
4436 4656
 
4437 4657
 	// Continue please!
4438 4658
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4465,12 +4685,13 @@  discard block
 block discarded – undo
4465 4685
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4466 4686
 
4467 4687
 		// If debug flood the screen.
4468
-		if ($is_debug)
4469
-			echo '
4688
+		if ($is_debug) {
4689
+					echo '
4470 4690
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4471 4691
 
4472 4692
 				if (document.getElementById(\'debug_section\').scrollHeight)
4473 4693
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4694
+		}
4474 4695
 
4475 4696
 		echo '
4476 4697
 				// Get the next update...
@@ -4506,8 +4727,8 @@  discard block
 block discarded – undo
4506 4727
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4507 4728
 	<form action="', $boardurl, '/index.php">';
4508 4729
 
4509
-	if (!empty($upcontext['can_delete_script']))
4510
-		echo '
4730
+	if (!empty($upcontext['can_delete_script'])) {
4731
+			echo '
4511 4732
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4512 4733
 			<script>
4513 4734
 				function doTheDelete(theCheck)
@@ -4519,6 +4740,7 @@  discard block
 block discarded – undo
4519 4740
 				}
4520 4741
 			</script>
4521 4742
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4743
+	}
4522 4744
 
4523 4745
 	$active = time() - $upcontext['started'];
4524 4746
 	$hours = floor($active / 3600);
@@ -4528,16 +4750,20 @@  discard block
 block discarded – undo
4528 4750
 	if ($is_debug)
4529 4751
 	{
4530 4752
 		$totalTime = '';
4531
-		if ($hours > 0)
4532
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4533
-		if ($minutes > 0)
4534
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4535
-		if ($seconds > 0)
4536
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4753
+		if ($hours > 0) {
4754
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4755
+		}
4756
+		if ($minutes > 0) {
4757
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4758
+		}
4759
+		if ($seconds > 0) {
4760
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4761
+		}
4537 4762
 	}
4538 4763
 
4539
-	if ($is_debug && !empty($totalTime))
4540
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4764
+	if ($is_debug && !empty($totalTime)) {
4765
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4766
+	}
4541 4767
 
4542 4768
 	echo '<br>
4543 4769
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4564,8 +4790,9 @@  discard block
 block discarded – undo
4564 4790
 
4565 4791
 	$current_substep = $_GET['substep'];
4566 4792
 
4567
-	if (empty($_GET['a']))
4568
-		$_GET['a'] = 0;
4793
+	if (empty($_GET['a'])) {
4794
+			$_GET['a'] = 0;
4795
+	}
4569 4796
 	$step_progress['name'] = 'Converting ips';
4570 4797
 	$step_progress['current'] = $_GET['a'];
4571 4798
 
@@ -4608,16 +4835,19 @@  discard block
 block discarded – undo
4608 4835
 				'empty' => '',
4609 4836
 				'limit' => $limit,
4610 4837
 		));
4611
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4612
-			$arIp[] = $row[$oldCol];
4838
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4839
+					$arIp[] = $row[$oldCol];
4840
+		}
4613 4841
 		$smcFunc['db_free_result']($request);
4614 4842
 
4615 4843
 		// Special case, null ip could keep us in a loop.
4616
-		if (is_null($arIp[0]))
4617
-			unset($arIp[0]);
4844
+		if (is_null($arIp[0])) {
4845
+					unset($arIp[0]);
4846
+		}
4618 4847
 
4619
-		if (empty($arIp))
4620
-			$is_done = true;
4848
+		if (empty($arIp)) {
4849
+					$is_done = true;
4850
+		}
4621 4851
 
4622 4852
 		$updates = array();
4623 4853
 		$cases = array();
@@ -4626,16 +4856,18 @@  discard block
 block discarded – undo
4626 4856
 		{
4627 4857
 			$arIp[$i] = trim($arIp[$i]);
4628 4858
 
4629
-			if (empty($arIp[$i]))
4630
-				continue;
4859
+			if (empty($arIp[$i])) {
4860
+							continue;
4861
+			}
4631 4862
 
4632 4863
 			$updates['ip' . $i] = $arIp[$i];
4633 4864
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4634 4865
 
4635 4866
 			if ($setSize > 0 && $i % $setSize === 0)
4636 4867
 			{
4637
-				if (count($updates) == 1)
4638
-					continue;
4868
+				if (count($updates) == 1) {
4869
+									continue;
4870
+				}
4639 4871
 
4640 4872
 				$updates['whereSet'] = array_values($updates);
4641 4873
 				$smcFunc['db_query']('', '
@@ -4669,8 +4901,7 @@  discard block
 block discarded – undo
4669 4901
 							'ip' => $ip
4670 4902
 					));
4671 4903
 				}
4672
-			}
4673
-			else
4904
+			} else
4674 4905
 			{
4675 4906
 				$updates['whereSet'] = array_values($updates);
4676 4907
 				$smcFunc['db_query']('', '
@@ -4684,9 +4915,9 @@  discard block
 block discarded – undo
4684 4915
 					$updates
4685 4916
 				);
4686 4917
 			}
4918
+		} else {
4919
+					$is_done = true;
4687 4920
 		}
4688
-		else
4689
-			$is_done = true;
4690 4921
 
4691 4922
 		$_GET['a'] += $limit;
4692 4923
 		$step_progress['current'] = $_GET['a'];
@@ -4712,10 +4943,11 @@  discard block
 block discarded – undo
4712 4943
 
4713 4944
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4714 4945
 
4715
-	if (isset($columns[$column]))
4716
-		return $columns[$column];
4717
-	else
4718
-		return null;
4719
-}
4946
+	if (isset($columns[$column])) {
4947
+			return $columns[$column];
4948
+	} else {
4949
+			return null;
4950
+	}
4951
+	}
4720 4952
 
4721 4953
 ?>
4722 4954
\ No newline at end of file
Please login to merge, or discard this patch.