Completed
Pull Request — release-2.1 (#4470)
by Fran
16:42
created
other/upgrade.php 1 patch
Braces   +884 added lines, -649 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
 
@@ -104,11 +105,14 @@  discard block
 block discarded – undo
104 105
 	ini_set('default_socket_timeout', 900);
105 106
 }
106 107
 // Clean the upgrade path if this is from the client.
107
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
108
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
108
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
109
+	for ($i = 1;
110
+}
111
+$i < $_SERVER['argc']; $i++)
109 112
 	{
110
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
111
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
113
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
114
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
115
+		}
112 116
 	}
113 117
 
114 118
 // Are we from the client?
@@ -116,16 +120,17 @@  discard block
 block discarded – undo
116 120
 {
117 121
 	$command_line = true;
118 122
 	$disable_security = true;
119
-}
120
-else
123
+} else {
121 124
 	$command_line = false;
125
+}
122 126
 
123 127
 // Load this now just because we can.
124 128
 require_once($upgrade_path . '/Settings.php');
125 129
 
126 130
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
127
-if (isset($language))
131
+if (isset($language)) {
128 132
 	$language = str_ireplace('-utf8', '', $language);
133
+}
129 134
 
130 135
 // Are we logged in?
131 136
 if (isset($upgradeData))
@@ -133,10 +138,12 @@  discard block
 block discarded – undo
133 138
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
134 139
 
135 140
 	// Check for sensible values.
136
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
137
-		$upcontext['user']['started'] = time();
138
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
139
-		$upcontext['user']['updated'] = 0;
141
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
142
+			$upcontext['user']['started'] = time();
143
+	}
144
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
145
+			$upcontext['user']['updated'] = 0;
146
+	}
140 147
 
141 148
 	$upcontext['started'] = $upcontext['user']['started'];
142 149
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -201,8 +208,9 @@  discard block
 block discarded – undo
201 208
 			'db_error_skip' => true,
202 209
 		)
203 210
 	);
204
-	while ($row = $smcFunc['db_fetch_assoc']($request))
205
-		$modSettings[$row['variable']] = $row['value'];
211
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
212
+			$modSettings[$row['variable']] = $row['value'];
213
+	}
206 214
 	$smcFunc['db_free_result']($request);
207 215
 }
208 216
 
@@ -212,10 +220,12 @@  discard block
 block discarded – undo
212 220
 	$modSettings['theme_url'] = 'Themes/default';
213 221
 	$modSettings['images_url'] = 'Themes/default/images';
214 222
 }
215
-if (!isset($settings['default_theme_url']))
223
+if (!isset($settings['default_theme_url'])) {
216 224
 	$settings['default_theme_url'] = $modSettings['theme_url'];
217
-if (!isset($settings['default_theme_dir']))
225
+}
226
+if (!isset($settings['default_theme_dir'])) {
218 227
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
228
+}
219 229
 
220 230
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
221 231
 // Default title...
@@ -233,13 +243,15 @@  discard block
 block discarded – undo
233 243
 	$support_js = $upcontext['upgrade_status']['js'];
234 244
 
235 245
 	// Only set this if the upgrader status says so.
236
-	if (empty($is_debug))
237
-		$is_debug = $upcontext['upgrade_status']['debug'];
246
+	if (empty($is_debug)) {
247
+			$is_debug = $upcontext['upgrade_status']['debug'];
248
+	}
238 249
 
239 250
 	// Load the language.
240
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
241
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
-}
251
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
252
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
253
+	}
254
+	}
243 255
 // Set the defaults.
244 256
 else
245 257
 {
@@ -257,15 +269,18 @@  discard block
 block discarded – undo
257 269
 }
258 270
 
259 271
 // If this isn't the first stage see whether they are logging in and resuming.
260
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
272
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
261 273
 	checkLogin();
274
+}
262 275
 
263
-if ($command_line)
276
+if ($command_line) {
264 277
 	cmdStep0();
278
+}
265 279
 
266 280
 // Don't error if we're using xml.
267
-if (isset($_GET['xml']))
281
+if (isset($_GET['xml'])) {
268 282
 	$upcontext['return_error'] = true;
283
+}
269 284
 
270 285
 // Loop through all the steps doing each one as required.
271 286
 $upcontext['overall_percent'] = 0;
@@ -286,9 +301,9 @@  discard block
 block discarded – undo
286 301
 		}
287 302
 
288 303
 		// Call the step and if it returns false that means pause!
289
-		if (function_exists($step[2]) && $step[2]() === false)
290
-			break;
291
-		elseif (function_exists($step[2])) {
304
+		if (function_exists($step[2]) && $step[2]() === false) {
305
+					break;
306
+		} elseif (function_exists($step[2])) {
292 307
 			//Start each new step with this unset, so the 'normal' template is called first
293 308
 			unset($_GET['xml']);
294 309
 			//Clear out warnings at the start of each step
@@ -334,17 +349,18 @@  discard block
 block discarded – undo
334 349
 		// This should not happen my dear... HELP ME DEVELOPERS!!
335 350
 		if (!empty($command_line))
336 351
 		{
337
-			if (function_exists('debug_print_backtrace'))
338
-				debug_print_backtrace();
352
+			if (function_exists('debug_print_backtrace')) {
353
+							debug_print_backtrace();
354
+			}
339 355
 
340 356
 			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.';
341 357
 			flush();
342 358
 			die();
343 359
 		}
344 360
 
345
-		if (!isset($_GET['xml']))
346
-			template_upgrade_above();
347
-		else
361
+		if (!isset($_GET['xml'])) {
362
+					template_upgrade_above();
363
+		} else
348 364
 		{
349 365
 			header('Content-Type: text/xml; charset=UTF-8');
350 366
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -366,25 +382,29 @@  discard block
 block discarded – undo
366 382
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
367 383
 
368 384
 			// Custom stuff to pass back?
369
-			if (!empty($upcontext['query_string']))
370
-				$upcontext['form_url'] .= $upcontext['query_string'];
385
+			if (!empty($upcontext['query_string'])) {
386
+							$upcontext['form_url'] .= $upcontext['query_string'];
387
+			}
371 388
 
372 389
 			// Call the appropriate subtemplate
373
-			if (is_callable('template_' . $upcontext['sub_template']))
374
-				call_user_func('template_' . $upcontext['sub_template']);
375
-			else
376
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
390
+			if (is_callable('template_' . $upcontext['sub_template'])) {
391
+							call_user_func('template_' . $upcontext['sub_template']);
392
+			} else {
393
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
394
+			}
377 395
 		}
378 396
 
379 397
 		// Was there an error?
380
-		if (!empty($upcontext['forced_error_message']))
381
-			echo $upcontext['forced_error_message'];
398
+		if (!empty($upcontext['forced_error_message'])) {
399
+					echo $upcontext['forced_error_message'];
400
+		}
382 401
 
383 402
 		// Show the footer.
384
-		if (!isset($_GET['xml']))
385
-			template_upgrade_below();
386
-		else
387
-			template_xml_below();
403
+		if (!isset($_GET['xml'])) {
404
+					template_upgrade_below();
405
+		} else {
406
+					template_xml_below();
407
+		}
388 408
 	}
389 409
 
390 410
 
@@ -396,15 +416,19 @@  discard block
 block discarded – undo
396 416
 		$seconds = intval($active % 60);
397 417
 
398 418
 		$totalTime = '';
399
-		if ($hours > 0)
400
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
401
-		if ($minutes > 0)
402
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
403
-		if ($seconds > 0)
404
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
419
+		if ($hours > 0) {
420
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
421
+		}
422
+		if ($minutes > 0) {
423
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
424
+		}
425
+		if ($seconds > 0) {
426
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
427
+		}
405 428
 
406
-		if (!empty($totalTime))
407
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
429
+		if (!empty($totalTime)) {
430
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
431
+		}
408 432
 	}
409 433
 
410 434
 	// Bang - gone!
@@ -417,8 +441,9 @@  discard block
 block discarded – undo
417 441
 	global $upgradeurl, $upcontext, $command_line;
418 442
 
419 443
 	// Command line users can't be redirected.
420
-	if ($command_line)
421
-		upgradeExit(true);
444
+	if ($command_line) {
445
+			upgradeExit(true);
446
+	}
422 447
 
423 448
 	// Are we providing the core info?
424 449
 	if ($addForm)
@@ -444,12 +469,14 @@  discard block
 block discarded – undo
444 469
 	define('SMF', 1);
445 470
 
446 471
 	// Start the session.
447
-	if (@ini_get('session.save_handler') == 'user')
448
-		@ini_set('session.save_handler', 'files');
472
+	if (@ini_get('session.save_handler') == 'user') {
473
+			@ini_set('session.save_handler', 'files');
474
+	}
449 475
 	@session_start();
450 476
 
451
-	if (empty($smcFunc))
452
-		$smcFunc = array();
477
+	if (empty($smcFunc)) {
478
+			$smcFunc = array();
479
+	}
453 480
 
454 481
 	// We need this for authentication and some upgrade code
455 482
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -476,24 +503,27 @@  discard block
 block discarded – undo
476 503
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
477 504
 
478 505
 		// Make the connection...
479
-		if (empty($db_connection))
480
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
481
-		else
482
-			// If we've returned here, ping/reconnect to be safe
506
+		if (empty($db_connection)) {
507
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
508
+		} else {
509
+					// If we've returned here, ping/reconnect to be safe
483 510
 			$smcFunc['db_ping']($db_connection);
511
+		}
484 512
 
485 513
 		// Oh dear god!!
486
-		if ($db_connection === null)
487
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
514
+		if ($db_connection === null) {
515
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
516
+		}
488 517
 
489
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
490
-			$smcFunc['db_query']('', '
518
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
519
+					$smcFunc['db_query']('', '
491 520
 			SET NAMES {string:db_character_set}',
492 521
 			array(
493 522
 				'db_error_skip' => true,
494 523
 				'db_character_set' => $db_character_set,
495 524
 			)
496 525
 		);
526
+		}
497 527
 
498 528
 		// Load the modSettings data...
499 529
 		$request = $smcFunc['db_query']('', '
@@ -504,11 +534,11 @@  discard block
 block discarded – undo
504 534
 			)
505 535
 		);
506 536
 		$modSettings = array();
507
-		while ($row = $smcFunc['db_fetch_assoc']($request))
508
-			$modSettings[$row['variable']] = $row['value'];
537
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
538
+					$modSettings[$row['variable']] = $row['value'];
539
+		}
509 540
 		$smcFunc['db_free_result']($request);
510
-	}
511
-	else
541
+	} else
512 542
 	{
513 543
 		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.');
514 544
 	}
@@ -522,9 +552,10 @@  discard block
 block discarded – undo
522 552
 		cleanRequest();
523 553
 	}
524 554
 
525
-	if (!isset($_GET['substep']))
526
-		$_GET['substep'] = 0;
527
-}
555
+	if (!isset($_GET['substep'])) {
556
+			$_GET['substep'] = 0;
557
+	}
558
+	}
528 559
 
529 560
 function initialize_inputs()
530 561
 {
@@ -554,8 +585,9 @@  discard block
 block discarded – undo
554 585
 		$dh = opendir(dirname(__FILE__));
555 586
 		while ($file = readdir($dh))
556 587
 		{
557
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
558
-				@unlink(dirname(__FILE__) . '/' . $file);
588
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
589
+							@unlink(dirname(__FILE__) . '/' . $file);
590
+			}
559 591
 		}
560 592
 		closedir($dh);
561 593
 
@@ -584,8 +616,9 @@  discard block
 block discarded – undo
584 616
 	$temp = 'upgrade_php?step';
585 617
 	while (strlen($temp) > 4)
586 618
 	{
587
-		if (isset($_GET[$temp]))
588
-			unset($_GET[$temp]);
619
+		if (isset($_GET[$temp])) {
620
+					unset($_GET[$temp]);
621
+		}
589 622
 		$temp = substr($temp, 1);
590 623
 	}
591 624
 
@@ -612,32 +645,39 @@  discard block
 block discarded – undo
612 645
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
613 646
 
614 647
 	// Need legacy scripts?
615
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
616
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
617
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
618
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
619
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
620
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
648
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
649
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
650
+	}
651
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
652
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
653
+	}
654
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
655
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
656
+	}
621 657
 
622 658
 	// We don't need "-utf8" files anymore...
623 659
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
624 660
 
625 661
 	// This needs to exist!
626
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
627
-		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>]');
628
-	else
629
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
662
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
663
+			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>]');
664
+	} else {
665
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
666
+	}
630 667
 
631
-	if (!$check)
632
-		// 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.
668
+	if (!$check) {
669
+			// 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.
633 670
 		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.');
671
+	}
634 672
 
635 673
 	// Do they meet the install requirements?
636
-	if (!php_version_check())
637
-		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.');
674
+	if (!php_version_check()) {
675
+			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.');
676
+	}
638 677
 
639
-	if (!db_version_check())
640
-		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.');
678
+	if (!db_version_check()) {
679
+			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.');
680
+	}
641 681
 
642 682
 	// Do some checks to make sure they have proper privileges
643 683
 	db_extend('packages');
@@ -652,14 +692,16 @@  discard block
 block discarded – undo
652 692
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
653 693
 
654 694
 	// Sorry... we need CREATE, ALTER and DROP
655
-	if (!$create || !$alter || !$drop)
656
-		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.');
695
+	if (!$create || !$alter || !$drop) {
696
+			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.');
697
+	}
657 698
 
658 699
 	// Do a quick version spot check.
659 700
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
660 701
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
661
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
662
-		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.');
702
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
703
+			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.');
704
+	}
663 705
 
664 706
 	// What absolutely needs to be writable?
665 707
 	$writable_files = array(
@@ -681,12 +723,13 @@  discard block
 block discarded – undo
681 723
 	quickFileWritable($custom_av_dir);
682 724
 
683 725
 	// Are we good now?
684
-	if (!is_writable($custom_av_dir))
685
-		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));
686
-	elseif ($need_settings_update)
726
+	if (!is_writable($custom_av_dir)) {
727
+			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));
728
+	} elseif ($need_settings_update)
687 729
 	{
688
-		if (!function_exists('cache_put_data'))
689
-			require_once($sourcedir . '/Load.php');
730
+		if (!function_exists('cache_put_data')) {
731
+					require_once($sourcedir . '/Load.php');
732
+		}
690 733
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
691 734
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
692 735
 	}
@@ -695,28 +738,33 @@  discard block
 block discarded – undo
695 738
 
696 739
 	// Check the cache directory.
697 740
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
698
-	if (!file_exists($cachedir_temp))
699
-		@mkdir($cachedir_temp);
700
-	if (!file_exists($cachedir_temp))
701
-		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.');
702
-
703
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
704
-		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>.');
705
-	elseif (!isset($_GET['skiplang']))
741
+	if (!file_exists($cachedir_temp)) {
742
+			@mkdir($cachedir_temp);
743
+	}
744
+	if (!file_exists($cachedir_temp)) {
745
+			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.');
746
+	}
747
+
748
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
749
+			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>.');
750
+	} elseif (!isset($_GET['skiplang']))
706 751
 	{
707 752
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
708 753
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
709 754
 
710
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
711
-			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>]');
755
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
756
+					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>]');
757
+		}
712 758
 	}
713 759
 
714
-	if (!makeFilesWritable($writable_files))
715
-		return false;
760
+	if (!makeFilesWritable($writable_files)) {
761
+			return false;
762
+	}
716 763
 
717 764
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
718
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
719
-		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.');
765
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
766
+			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.');
767
+	}
720 768
 
721 769
 	// Upgrade the agreement.
722 770
 	elseif (isset($modSettings['agreement']))
@@ -727,8 +775,8 @@  discard block
 block discarded – undo
727 775
 	}
728 776
 
729 777
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
730
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
731
-		$upcontext['warning'] = '
778
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
779
+			$upcontext['warning'] = '
732 780
 			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>
733 781
 			<ul>
734 782
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -736,19 +784,23 @@  discard block
 block discarded – undo
736 784
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
737 785
 			</ul>
738 786
 			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.';
787
+	}
739 788
 
740 789
 	// Confirm mbstring is loaded...
741
-	if (!extension_loaded('mbstring'))
742
-		return throw_error($txt['install_no_mbstring']);
790
+	if (!extension_loaded('mbstring')) {
791
+			return throw_error($txt['install_no_mbstring']);
792
+	}
743 793
 
744 794
 	// Check for https stream support.
745 795
 	$supported_streams = stream_get_wrappers();
746
-	if (!in_array('https', $supported_streams))
747
-		$upcontext['custom_warning'] = $txt['install_no_https'];
796
+	if (!in_array('https', $supported_streams)) {
797
+			$upcontext['custom_warning'] = $txt['install_no_https'];
798
+	}
748 799
 
749 800
 	// Either we're logged in or we're going to present the login.
750
-	if (checkLogin())
751
-		return true;
801
+	if (checkLogin()) {
802
+			return true;
803
+	}
752 804
 
753 805
 	$upcontext += createToken('login');
754 806
 
@@ -762,15 +814,17 @@  discard block
 block discarded – undo
762 814
 	global $smcFunc, $db_type, $support_js;
763 815
 
764 816
 	// Don't bother if the security is disabled.
765
-	if ($disable_security)
766
-		return true;
817
+	if ($disable_security) {
818
+			return true;
819
+	}
767 820
 
768 821
 	// Are we trying to login?
769 822
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
770 823
 	{
771 824
 		// If we've disabled security pick a suitable name!
772
-		if (empty($_POST['user']))
773
-			$_POST['user'] = 'Administrator';
825
+		if (empty($_POST['user'])) {
826
+					$_POST['user'] = 'Administrator';
827
+		}
774 828
 
775 829
 		// Before 2.0 these column names were different!
776 830
 		$oldDB = false;
@@ -785,16 +839,17 @@  discard block
 block discarded – undo
785 839
 					'db_error_skip' => true,
786 840
 				)
787 841
 			);
788
-			if ($smcFunc['db_num_rows']($request) != 0)
789
-				$oldDB = true;
842
+			if ($smcFunc['db_num_rows']($request) != 0) {
843
+							$oldDB = true;
844
+			}
790 845
 			$smcFunc['db_free_result']($request);
791 846
 		}
792 847
 
793 848
 		// Get what we believe to be their details.
794 849
 		if (!$disable_security)
795 850
 		{
796
-			if ($oldDB)
797
-				$request = $smcFunc['db_query']('', '
851
+			if ($oldDB) {
852
+							$request = $smcFunc['db_query']('', '
798 853
 					SELECT id_member, memberName AS member_name, passwd, id_group,
799 854
 					additionalGroups AS additional_groups, lngfile
800 855
 					FROM {db_prefix}members
@@ -804,8 +859,8 @@  discard block
 block discarded – undo
804 859
 						'db_error_skip' => true,
805 860
 					)
806 861
 				);
807
-			else
808
-				$request = $smcFunc['db_query']('', '
862
+			} else {
863
+							$request = $smcFunc['db_query']('', '
809 864
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
810 865
 					FROM {db_prefix}members
811 866
 					WHERE member_name = {string:member_name}',
@@ -814,6 +869,7 @@  discard block
 block discarded – undo
814 869
 						'db_error_skip' => true,
815 870
 					)
816 871
 				);
872
+			}
817 873
 			if ($smcFunc['db_num_rows']($request) != 0)
818 874
 			{
819 875
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -821,16 +877,17 @@  discard block
 block discarded – undo
821 877
 				$groups = explode(',', $addGroups);
822 878
 				$groups[] = $id_group;
823 879
 
824
-				foreach ($groups as $k => $v)
825
-					$groups[$k] = (int) $v;
880
+				foreach ($groups as $k => $v) {
881
+									$groups[$k] = (int) $v;
882
+				}
826 883
 
827 884
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
828 885
 
829 886
 				// We don't use "-utf8" anymore...
830 887
 				$user_language = str_ireplace('-utf8', '', $user_language);
888
+			} else {
889
+							$upcontext['username_incorrect'] = true;
831 890
 			}
832
-			else
833
-				$upcontext['username_incorrect'] = true;
834 891
 			$smcFunc['db_free_result']($request);
835 892
 		}
836 893
 		$upcontext['username'] = $_POST['user'];
@@ -840,13 +897,14 @@  discard block
 block discarded – undo
840 897
 		{
841 898
 			$upcontext['upgrade_status']['js'] = 1;
842 899
 			$support_js = 1;
900
+		} else {
901
+					$support_js = 0;
843 902
 		}
844
-		else
845
-			$support_js = 0;
846 903
 
847 904
 		// Note down the version we are coming from.
848
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
849
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
905
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
906
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
907
+		}
850 908
 
851 909
 		// Didn't get anywhere?
852 910
 		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']))
@@ -880,15 +938,15 @@  discard block
 block discarded – undo
880 938
 							'db_error_skip' => true,
881 939
 						)
882 940
 					);
883
-					if ($smcFunc['db_num_rows']($request) == 0)
884
-						return throw_error('You need to be an admin to perform an upgrade!');
941
+					if ($smcFunc['db_num_rows']($request) == 0) {
942
+											return throw_error('You need to be an admin to perform an upgrade!');
943
+					}
885 944
 					$smcFunc['db_free_result']($request);
886 945
 				}
887 946
 
888 947
 				$upcontext['user']['id'] = $id_member;
889 948
 				$upcontext['user']['name'] = $name;
890
-			}
891
-			else
949
+			} else
892 950
 			{
893 951
 				$upcontext['user']['id'] = 1;
894 952
 				$upcontext['user']['name'] = 'Administrator';
@@ -904,11 +962,11 @@  discard block
 block discarded – undo
904 962
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
905 963
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
906 964
 
907
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
908
-					$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'] . '.';
909
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
910
-					$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'] . '.';
911
-				else
965
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
966
+									$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'] . '.';
967
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
968
+									$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'] . '.';
969
+				} else
912 970
 				{
913 971
 					// Set this as the new language.
914 972
 					$upcontext['language'] = $user_language;
@@ -952,8 +1010,9 @@  discard block
 block discarded – undo
952 1010
 	unset($member_columns);
953 1011
 
954 1012
 	// If we've not submitted then we're done.
955
-	if (empty($_POST['upcont']))
956
-		return false;
1013
+	if (empty($_POST['upcont'])) {
1014
+			return false;
1015
+	}
957 1016
 
958 1017
 	// Firstly, if they're enabling SM stat collection just do it.
959 1018
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -973,16 +1032,17 @@  discard block
 block discarded – undo
973 1032
 				fwrite($fp, $out);
974 1033
 
975 1034
 				$return_data = '';
976
-				while (!feof($fp))
977
-					$return_data .= fgets($fp, 128);
1035
+				while (!feof($fp)) {
1036
+									$return_data .= fgets($fp, 128);
1037
+				}
978 1038
 
979 1039
 				fclose($fp);
980 1040
 
981 1041
 				// Get the unique site ID.
982 1042
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
983 1043
 
984
-				if (!empty($ID[1]))
985
-					$smcFunc['db_insert']('replace',
1044
+				if (!empty($ID[1])) {
1045
+									$smcFunc['db_insert']('replace',
986 1046
 						$db_prefix . 'settings',
987 1047
 						array('variable' => 'string', 'value' => 'string'),
988 1048
 						array(
@@ -991,9 +1051,9 @@  discard block
 block discarded – undo
991 1051
 						),
992 1052
 						array('variable')
993 1053
 					);
1054
+				}
994 1055
 			}
995
-		}
996
-		else
1056
+		} else
997 1057
 		{
998 1058
 			$smcFunc['db_insert']('replace',
999 1059
 				$db_prefix . 'settings',
@@ -1004,8 +1064,8 @@  discard block
 block discarded – undo
1004 1064
 		}
1005 1065
 	}
1006 1066
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1007
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1008
-		$smcFunc['db_query']('', '
1067
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1068
+			$smcFunc['db_query']('', '
1009 1069
 			DELETE FROM {db_prefix}settings
1010 1070
 			WHERE variable = {string:enable_sm_stats}',
1011 1071
 			array(
@@ -1013,6 +1073,7 @@  discard block
 block discarded – undo
1013 1073
 				'db_error_skip' => true,
1014 1074
 			)
1015 1075
 		);
1076
+	}
1016 1077
 
1017 1078
 	// Deleting old karma stuff?
1018 1079
 	if (!empty($_POST['delete_karma']))
@@ -1027,20 +1088,22 @@  discard block
 block discarded – undo
1027 1088
 		);
1028 1089
 
1029 1090
 		// Cleaning up old karma member settings.
1030
-		if ($upcontext['karma_installed']['good'])
1031
-			$smcFunc['db_query']('', '
1091
+		if ($upcontext['karma_installed']['good']) {
1092
+					$smcFunc['db_query']('', '
1032 1093
 				ALTER TABLE {db_prefix}members
1033 1094
 				DROP karma_good',
1034 1095
 				array()
1035 1096
 			);
1097
+		}
1036 1098
 
1037 1099
 		// Does karma bad was enable?
1038
-		if ($upcontext['karma_installed']['bad'])
1039
-			$smcFunc['db_query']('', '
1100
+		if ($upcontext['karma_installed']['bad']) {
1101
+					$smcFunc['db_query']('', '
1040 1102
 				ALTER TABLE {db_prefix}members
1041 1103
 				DROP karma_bad',
1042 1104
 				array()
1043 1105
 			);
1106
+		}
1044 1107
 
1045 1108
 		// Cleaning up old karma permissions.
1046 1109
 		$smcFunc['db_query']('', '
@@ -1058,32 +1121,37 @@  discard block
 block discarded – undo
1058 1121
 	}
1059 1122
 
1060 1123
 	// Emptying the error log?
1061
-	if (!empty($_POST['empty_error']))
1062
-		$smcFunc['db_query']('truncate_table', '
1124
+	if (!empty($_POST['empty_error'])) {
1125
+			$smcFunc['db_query']('truncate_table', '
1063 1126
 			TRUNCATE {db_prefix}log_errors',
1064 1127
 			array(
1065 1128
 			)
1066 1129
 		);
1130
+	}
1067 1131
 
1068 1132
 	$changes = array();
1069 1133
 
1070 1134
 	// Add proxy settings.
1071
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1072
-		$changes += array(
1135
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1136
+			$changes += array(
1073 1137
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1074 1138
 			'image_proxy_maxsize' => 5190,
1075 1139
 			'image_proxy_enabled' => 0,
1076 1140
 		);
1141
+	}
1077 1142
 
1078 1143
 	// If $boardurl reflects https, set force_ssl
1079
-	if (!function_exists('cache_put_data'))
1080
-		require_once($sourcedir . '/Load.php');
1081
-	if (stripos($boardurl, 'https://') !== false)
1082
-		updateSettings(array('force_ssl' => '2'));
1144
+	if (!function_exists('cache_put_data')) {
1145
+			require_once($sourcedir . '/Load.php');
1146
+	}
1147
+	if (stripos($boardurl, 'https://') !== false) {
1148
+			updateSettings(array('force_ssl' => '2'));
1149
+	}
1083 1150
 
1084 1151
 	// If we're overriding the language follow it through.
1085
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1086
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1152
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1153
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1154
+	}
1087 1155
 
1088 1156
 	if (!empty($_POST['maint']))
1089 1157
 	{
@@ -1095,26 +1163,29 @@  discard block
 block discarded – undo
1095 1163
 		{
1096 1164
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1097 1165
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1098
-		}
1099
-		else
1166
+		} else
1100 1167
 		{
1101 1168
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1102 1169
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1103 1170
 		}
1104 1171
 	}
1105 1172
 
1106
-	if ($command_line)
1107
-		echo ' * Updating Settings.php...';
1173
+	if ($command_line) {
1174
+			echo ' * Updating Settings.php...';
1175
+	}
1108 1176
 
1109 1177
 	// Fix some old paths.
1110
-	if (substr($boarddir, 0, 1) == '.')
1111
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1178
+	if (substr($boarddir, 0, 1) == '.') {
1179
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1180
+	}
1112 1181
 
1113
-	if (substr($sourcedir, 0, 1) == '.')
1114
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1182
+	if (substr($sourcedir, 0, 1) == '.') {
1183
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1184
+	}
1115 1185
 
1116
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1117
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1186
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1187
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1188
+	}
1118 1189
 
1119 1190
 	// If they have a "host:port" setup for the host, split that into separate values
1120 1191
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1125,32 +1196,36 @@  discard block
 block discarded – undo
1125 1196
 		$changes['db_server'] = '\'' . $db_server . '\'';
1126 1197
 
1127 1198
 		// Only set this if we're not using the default port
1128
-		if ($db_port != ini_get('mysqli.default_port'))
1129
-			$changes['db_port'] = (int) $db_port;
1130
-	}
1131
-	elseif (!empty($db_port))
1199
+		if ($db_port != ini_get('mysqli.default_port')) {
1200
+					$changes['db_port'] = (int) $db_port;
1201
+		}
1202
+	} elseif (!empty($db_port))
1132 1203
 	{
1133 1204
 		// If db_port is set and is the same as the default, set it to ''
1134 1205
 		if ($db_type == 'mysql')
1135 1206
 		{
1136
-			if ($db_port == ini_get('mysqli.default_port'))
1137
-				$changes['db_port'] = '\'\'';
1138
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1139
-				$changes['db_port'] = '\'\'';
1207
+			if ($db_port == ini_get('mysqli.default_port')) {
1208
+							$changes['db_port'] = '\'\'';
1209
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1210
+							$changes['db_port'] = '\'\'';
1211
+			}
1140 1212
 		}
1141 1213
 	}
1142 1214
 
1143 1215
 	// Maybe we haven't had this option yet?
1144
-	if (empty($packagesdir))
1145
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1216
+	if (empty($packagesdir)) {
1217
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1218
+	}
1146 1219
 
1147 1220
 	// Add support for $tasksdir var.
1148
-	if (empty($tasksdir))
1149
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1221
+	if (empty($tasksdir)) {
1222
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1223
+	}
1150 1224
 
1151 1225
 	// Make sure we fix the language as well.
1152
-	if (stristr($language, '-utf8'))
1153
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1226
+	if (stristr($language, '-utf8')) {
1227
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1228
+	}
1154 1229
 
1155 1230
 	// @todo Maybe change the cookie name if going to 1.1, too?
1156 1231
 
@@ -1158,8 +1233,9 @@  discard block
 block discarded – undo
1158 1233
 	require_once($sourcedir . '/Subs-Admin.php');
1159 1234
 	updateSettingsFile($changes);
1160 1235
 
1161
-	if ($command_line)
1162
-		echo ' Successful.' . "\n";
1236
+	if ($command_line) {
1237
+			echo ' Successful.' . "\n";
1238
+	}
1163 1239
 
1164 1240
 	// Are we doing debug?
1165 1241
 	if (isset($_POST['debug']))
@@ -1169,8 +1245,9 @@  discard block
 block discarded – undo
1169 1245
 	}
1170 1246
 
1171 1247
 	// If we're not backing up then jump one.
1172
-	if (empty($_POST['backup']))
1173
-		$upcontext['current_step']++;
1248
+	if (empty($_POST['backup'])) {
1249
+			$upcontext['current_step']++;
1250
+	}
1174 1251
 
1175 1252
 	// If we've got here then let's proceed to the next step!
1176 1253
 	return true;
@@ -1185,8 +1262,9 @@  discard block
 block discarded – undo
1185 1262
 	$upcontext['page_title'] = 'Backup Database';
1186 1263
 
1187 1264
 	// Done it already - js wise?
1188
-	if (!empty($_POST['backup_done']))
1189
-		return true;
1265
+	if (!empty($_POST['backup_done'])) {
1266
+			return true;
1267
+	}
1190 1268
 
1191 1269
 	// Some useful stuff here.
1192 1270
 	db_extend();
@@ -1200,9 +1278,10 @@  discard block
 block discarded – undo
1200 1278
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1201 1279
 
1202 1280
 	$table_names = array();
1203
-	foreach ($tables as $table)
1204
-		if (substr($table, 0, 7) !== 'backup_')
1281
+	foreach ($tables as $table) {
1282
+			if (substr($table, 0, 7) !== 'backup_')
1205 1283
 			$table_names[] = $table;
1284
+	}
1206 1285
 
1207 1286
 	$upcontext['table_count'] = count($table_names);
1208 1287
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1212,12 +1291,14 @@  discard block
 block discarded – undo
1212 1291
 	$file_steps = $upcontext['table_count'];
1213 1292
 
1214 1293
 	// What ones have we already done?
1215
-	foreach ($table_names as $id => $table)
1216
-		if ($id < $_GET['substep'])
1294
+	foreach ($table_names as $id => $table) {
1295
+			if ($id < $_GET['substep'])
1217 1296
 			$upcontext['previous_tables'][] = $table;
1297
+	}
1218 1298
 
1219
-	if ($command_line)
1220
-		echo 'Backing Up Tables.';
1299
+	if ($command_line) {
1300
+			echo 'Backing Up Tables.';
1301
+	}
1221 1302
 
1222 1303
 	// If we don't support javascript we backup here.
1223 1304
 	if (!$support_js || isset($_GET['xml']))
@@ -1236,8 +1317,9 @@  discard block
 block discarded – undo
1236 1317
 			backupTable($table_names[$substep]);
1237 1318
 
1238 1319
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1239
-			if (isset($_GET['xml']))
1240
-				return upgradeExit();
1320
+			if (isset($_GET['xml'])) {
1321
+							return upgradeExit();
1322
+			}
1241 1323
 		}
1242 1324
 
1243 1325
 		if ($command_line)
@@ -1270,9 +1352,10 @@  discard block
 block discarded – undo
1270 1352
 
1271 1353
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1272 1354
 
1273
-	if ($command_line)
1274
-		echo ' done.';
1275
-}
1355
+	if ($command_line) {
1356
+			echo ' done.';
1357
+	}
1358
+	}
1276 1359
 
1277 1360
 // Step 2: Everything.
1278 1361
 function DatabaseChanges()
@@ -1281,8 +1364,9 @@  discard block
 block discarded – undo
1281 1364
 	global $upcontext, $support_js, $db_type;
1282 1365
 
1283 1366
 	// Have we just completed this?
1284
-	if (!empty($_POST['database_done']))
1285
-		return true;
1367
+	if (!empty($_POST['database_done'])) {
1368
+			return true;
1369
+	}
1286 1370
 
1287 1371
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1288 1372
 	$upcontext['page_title'] = 'Database Changes';
@@ -1297,15 +1381,16 @@  discard block
 block discarded – undo
1297 1381
 	);
1298 1382
 
1299 1383
 	// How many files are there in total?
1300
-	if (isset($_GET['filecount']))
1301
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1302
-	else
1384
+	if (isset($_GET['filecount'])) {
1385
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1386
+	} else
1303 1387
 	{
1304 1388
 		$upcontext['file_count'] = 0;
1305 1389
 		foreach ($files as $file)
1306 1390
 		{
1307
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1308
-				$upcontext['file_count']++;
1391
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1392
+							$upcontext['file_count']++;
1393
+			}
1309 1394
 		}
1310 1395
 	}
1311 1396
 
@@ -1315,9 +1400,9 @@  discard block
 block discarded – undo
1315 1400
 	$upcontext['cur_file_num'] = 0;
1316 1401
 	foreach ($files as $file)
1317 1402
 	{
1318
-		if ($did_not_do)
1319
-			$did_not_do--;
1320
-		else
1403
+		if ($did_not_do) {
1404
+					$did_not_do--;
1405
+		} else
1321 1406
 		{
1322 1407
 			$upcontext['cur_file_num']++;
1323 1408
 			$upcontext['cur_file_name'] = $file[0];
@@ -1344,12 +1429,13 @@  discard block
 block discarded – undo
1344 1429
 					// Flag to move on to the next.
1345 1430
 					$upcontext['completed_step'] = true;
1346 1431
 					// Did we complete the whole file?
1347
-					if ($nextFile)
1348
-						$upcontext['current_debug_item_num'] = -1;
1432
+					if ($nextFile) {
1433
+											$upcontext['current_debug_item_num'] = -1;
1434
+					}
1349 1435
 					return upgradeExit();
1436
+				} elseif ($support_js) {
1437
+									break;
1350 1438
 				}
1351
-				elseif ($support_js)
1352
-					break;
1353 1439
 			}
1354 1440
 			// Set the progress bar to be right as if we had - even if we hadn't...
1355 1441
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1374,8 +1460,9 @@  discard block
 block discarded – undo
1374 1460
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1375 1461
 
1376 1462
 	// Now it's nice to have some of the basic SMF source files.
1377
-	if (!isset($_GET['ssi']) && !$command_line)
1378
-		redirectLocation('&ssi=1');
1463
+	if (!isset($_GET['ssi']) && !$command_line) {
1464
+			redirectLocation('&ssi=1');
1465
+	}
1379 1466
 
1380 1467
 	$upcontext['sub_template'] = 'upgrade_complete';
1381 1468
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1391,14 +1478,16 @@  discard block
 block discarded – undo
1391 1478
 	// Are we in maintenance mode?
1392 1479
 	if (isset($upcontext['user']['main']))
1393 1480
 	{
1394
-		if ($command_line)
1395
-			echo ' * ';
1481
+		if ($command_line) {
1482
+					echo ' * ';
1483
+		}
1396 1484
 		$upcontext['removed_maintenance'] = true;
1397 1485
 		$changes['maintenance'] = $upcontext['user']['main'];
1398 1486
 	}
1399 1487
 	// Otherwise if somehow we are in 2 let's go to 1.
1400
-	elseif (!empty($maintenance) && $maintenance == 2)
1401
-		$changes['maintenance'] = 1;
1488
+	elseif (!empty($maintenance) && $maintenance == 2) {
1489
+			$changes['maintenance'] = 1;
1490
+	}
1402 1491
 
1403 1492
 	// Wipe this out...
1404 1493
 	$upcontext['user'] = array();
@@ -1413,9 +1502,9 @@  discard block
 block discarded – undo
1413 1502
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1414 1503
 
1415 1504
 	// Now is the perfect time to fetch the SM files.
1416
-	if ($command_line)
1417
-		cli_scheduled_fetchSMfiles();
1418
-	else
1505
+	if ($command_line) {
1506
+			cli_scheduled_fetchSMfiles();
1507
+	} else
1419 1508
 	{
1420 1509
 		require_once($sourcedir . '/ScheduledTasks.php');
1421 1510
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1423,8 +1512,9 @@  discard block
 block discarded – undo
1423 1512
 	}
1424 1513
 
1425 1514
 	// Log what we've done.
1426
-	if (empty($user_info['id']))
1427
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1515
+	if (empty($user_info['id'])) {
1516
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1517
+	}
1428 1518
 
1429 1519
 	// Log the action manually, so CLI still works.
1430 1520
 	$smcFunc['db_insert']('',
@@ -1443,8 +1533,9 @@  discard block
 block discarded – undo
1443 1533
 
1444 1534
 	// Save the current database version.
1445 1535
 	$server_version = $smcFunc['db_server_info']();
1446
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1447
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1536
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1537
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1538
+	}
1448 1539
 
1449 1540
 	if ($command_line)
1450 1541
 	{
@@ -1456,8 +1547,9 @@  discard block
 block discarded – undo
1456 1547
 
1457 1548
 	// Make sure it says we're done.
1458 1549
 	$upcontext['overall_percent'] = 100;
1459
-	if (isset($upcontext['step_progress']))
1460
-		unset($upcontext['step_progress']);
1550
+	if (isset($upcontext['step_progress'])) {
1551
+			unset($upcontext['step_progress']);
1552
+	}
1461 1553
 
1462 1554
 	$_GET['substep'] = 0;
1463 1555
 	return false;
@@ -1468,8 +1560,9 @@  discard block
 block discarded – undo
1468 1560
 {
1469 1561
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1470 1562
 
1471
-	if (empty($modSettings['time_format']))
1472
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1563
+	if (empty($modSettings['time_format'])) {
1564
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1565
+	}
1473 1566
 
1474 1567
 	// What files do we want to get
1475 1568
 	$request = $smcFunc['db_query']('', '
@@ -1503,8 +1596,9 @@  discard block
 block discarded – undo
1503 1596
 		$file_data = fetch_web_data($url);
1504 1597
 
1505 1598
 		// If we got an error - give up - the site might be down.
1506
-		if ($file_data === false)
1507
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1599
+		if ($file_data === false) {
1600
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1601
+		}
1508 1602
 
1509 1603
 		// Save the file to the database.
1510 1604
 		$smcFunc['db_query']('substring', '
@@ -1546,8 +1640,9 @@  discard block
 block discarded – undo
1546 1640
 	$themeData = array();
1547 1641
 	foreach ($values as $variable => $value)
1548 1642
 	{
1549
-		if (!isset($value) || $value === null)
1550
-			$value = 0;
1643
+		if (!isset($value) || $value === null) {
1644
+					$value = 0;
1645
+		}
1551 1646
 
1552 1647
 		$themeData[] = array(0, 1, $variable, $value);
1553 1648
 	}
@@ -1576,8 +1671,9 @@  discard block
 block discarded – undo
1576 1671
 
1577 1672
 	foreach ($values as $variable => $value)
1578 1673
 	{
1579
-		if (empty($modSettings[$value[0]]))
1580
-			continue;
1674
+		if (empty($modSettings[$value[0]])) {
1675
+					continue;
1676
+		}
1581 1677
 
1582 1678
 		$smcFunc['db_query']('', '
1583 1679
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1663,19 +1759,21 @@  discard block
 block discarded – undo
1663 1759
 	set_error_handler(
1664 1760
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1665 1761
 		{
1666
-			if ($support_js)
1667
-				return true;
1668
-			else
1669
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1762
+			if ($support_js) {
1763
+							return true;
1764
+			} else {
1765
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1766
+			}
1670 1767
 		}
1671 1768
 	);
1672 1769
 
1673 1770
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1674 1771
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1675
-	if ($db_type == 'mysql')
1676
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1677
-	else
1678
-		$db_collation = '';
1772
+	if ($db_type == 'mysql') {
1773
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1774
+	} else {
1775
+			$db_collation = '';
1776
+	}
1679 1777
 
1680 1778
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1681 1779
 
@@ -1687,8 +1785,9 @@  discard block
 block discarded – undo
1687 1785
 	$last_step = '';
1688 1786
 
1689 1787
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1690
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1691
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1788
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1789
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1790
+	}
1692 1791
 
1693 1792
 	// Count the total number of steps within this file - for progress.
1694 1793
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1708,15 +1807,18 @@  discard block
 block discarded – undo
1708 1807
 		$do_current = $substep >= $_GET['substep'];
1709 1808
 
1710 1809
 		// Get rid of any comments in the beginning of the line...
1711
-		if (substr(trim($line), 0, 2) === '/*')
1712
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1810
+		if (substr(trim($line), 0, 2) === '/*') {
1811
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1812
+		}
1713 1813
 
1714 1814
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1715
-		if ($is_debug && !$support_js && $command_line)
1716
-			flush();
1815
+		if ($is_debug && !$support_js && $command_line) {
1816
+					flush();
1817
+		}
1717 1818
 
1718
-		if (trim($line) === '')
1719
-			continue;
1819
+		if (trim($line) === '') {
1820
+					continue;
1821
+		}
1720 1822
 
1721 1823
 		if (trim(substr($line, 0, 3)) === '---')
1722 1824
 		{
@@ -1726,8 +1828,9 @@  discard block
 block discarded – undo
1726 1828
 			if (trim($current_data) != '' && $type !== '}')
1727 1829
 			{
1728 1830
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1729
-				if ($command_line)
1730
-					echo $upcontext['error_message'];
1831
+				if ($command_line) {
1832
+									echo $upcontext['error_message'];
1833
+				}
1731 1834
 			}
1732 1835
 
1733 1836
 			if ($type == ' ')
@@ -1745,17 +1848,18 @@  discard block
 block discarded – undo
1745 1848
 				if ($do_current)
1746 1849
 				{
1747 1850
 					$upcontext['actioned_items'][] = $last_step;
1748
-					if ($command_line)
1749
-						echo ' * ';
1851
+					if ($command_line) {
1852
+											echo ' * ';
1853
+					}
1750 1854
 				}
1751
-			}
1752
-			elseif ($type == '#')
1855
+			} elseif ($type == '#')
1753 1856
 			{
1754 1857
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1755 1858
 
1756 1859
 				$upcontext['current_debug_item_num']++;
1757
-				if (trim($line) != '---#')
1758
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1860
+				if (trim($line) != '---#') {
1861
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1862
+				}
1759 1863
 
1760 1864
 				// Have we already done something?
1761 1865
 				if (isset($_GET['xml']) && $done_something)
@@ -1766,34 +1870,36 @@  discard block
 block discarded – undo
1766 1870
 
1767 1871
 				if ($do_current)
1768 1872
 				{
1769
-					if (trim($line) == '---#' && $command_line)
1770
-						echo ' done.', $endl;
1771
-					elseif ($command_line)
1772
-						echo ' +++ ', rtrim(substr($line, 4));
1773
-					elseif (trim($line) != '---#')
1873
+					if (trim($line) == '---#' && $command_line) {
1874
+											echo ' done.', $endl;
1875
+					} elseif ($command_line) {
1876
+											echo ' +++ ', rtrim(substr($line, 4));
1877
+					} elseif (trim($line) != '---#')
1774 1878
 					{
1775
-						if ($is_debug)
1776
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1879
+						if ($is_debug) {
1880
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1881
+						}
1777 1882
 					}
1778 1883
 				}
1779 1884
 
1780 1885
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1781 1886
 				{
1782
-					if ($command_line)
1783
-						echo ' * ';
1784
-					else
1785
-						$upcontext['actioned_items'][] = $last_step;
1887
+					if ($command_line) {
1888
+											echo ' * ';
1889
+					} else {
1890
+											$upcontext['actioned_items'][] = $last_step;
1891
+					}
1786 1892
 				}
1787 1893
 
1788 1894
 				// Small step - only if we're actually doing stuff.
1789
-				if ($do_current)
1790
-					nextSubstep(++$substep);
1791
-				else
1792
-					$substep++;
1793
-			}
1794
-			elseif ($type == '{')
1795
-				$current_type = 'code';
1796
-			elseif ($type == '}')
1895
+				if ($do_current) {
1896
+									nextSubstep(++$substep);
1897
+				} else {
1898
+									$substep++;
1899
+				}
1900
+			} elseif ($type == '{') {
1901
+							$current_type = 'code';
1902
+			} elseif ($type == '}')
1797 1903
 			{
1798 1904
 				$current_type = 'sql';
1799 1905
 
@@ -1806,8 +1912,9 @@  discard block
 block discarded – undo
1806 1912
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1807 1913
 				{
1808 1914
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1809
-					if ($command_line)
1810
-						echo $upcontext['error_message'];
1915
+					if ($command_line) {
1916
+											echo $upcontext['error_message'];
1917
+					}
1811 1918
 				}
1812 1919
 
1813 1920
 				// Done with code!
@@ -1887,8 +1994,9 @@  discard block
 block discarded – undo
1887 1994
 	$db_unbuffered = false;
1888 1995
 
1889 1996
 	// Failure?!
1890
-	if ($result !== false)
1891
-		return $result;
1997
+	if ($result !== false) {
1998
+			return $result;
1999
+	}
1892 2000
 
1893 2001
 	$db_error_message = $smcFunc['db_error']($db_connection);
1894 2002
 	// If MySQL we do something more clever.
@@ -1916,54 +2024,61 @@  discard block
 block discarded – undo
1916 2024
 			{
1917 2025
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1918 2026
 				$result = mysqli_query($db_connection, $string);
1919
-				if ($result !== false)
1920
-					return $result;
2027
+				if ($result !== false) {
2028
+									return $result;
2029
+				}
1921 2030
 			}
1922
-		}
1923
-		elseif ($mysqli_errno == 2013)
2031
+		} elseif ($mysqli_errno == 2013)
1924 2032
 		{
1925 2033
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1926 2034
 			mysqli_select_db($db_connection, $db_name);
1927 2035
 			if ($db_connection)
1928 2036
 			{
1929 2037
 				$result = mysqli_query($db_connection, $string);
1930
-				if ($result !== false)
1931
-					return $result;
2038
+				if ($result !== false) {
2039
+									return $result;
2040
+				}
1932 2041
 			}
1933 2042
 		}
1934 2043
 		// Duplicate column name... should be okay ;).
1935
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1936
-			return false;
2044
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2045
+					return false;
2046
+		}
1937 2047
 		// Duplicate insert... make sure it's the proper type of query ;).
1938
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1939
-			return false;
2048
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2049
+					return false;
2050
+		}
1940 2051
 		// Creating an index on a non-existent column.
1941
-		elseif ($mysqli_errno == 1072)
1942
-			return false;
1943
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1944
-			return false;
2052
+		elseif ($mysqli_errno == 1072) {
2053
+					return false;
2054
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2055
+					return false;
2056
+		}
1945 2057
 	}
1946 2058
 	// If a table already exists don't go potty.
1947 2059
 	else
1948 2060
 	{
1949 2061
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1950 2062
 		{
1951
-			if (strpos($db_error_message, 'exist') !== false)
1952
-				return true;
1953
-		}
1954
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2063
+			if (strpos($db_error_message, 'exist') !== false) {
2064
+							return true;
2065
+			}
2066
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1955 2067
 		{
1956
-			if (strpos($db_error_message, 'duplicate') !== false)
1957
-				return true;
2068
+			if (strpos($db_error_message, 'duplicate') !== false) {
2069
+							return true;
2070
+			}
1958 2071
 		}
1959 2072
 	}
1960 2073
 
1961 2074
 	// Get the query string so we pass everything.
1962 2075
 	$query_string = '';
1963
-	foreach ($_GET as $k => $v)
1964
-		$query_string .= ';' . $k . '=' . $v;
1965
-	if (strlen($query_string) != 0)
1966
-		$query_string = '?' . substr($query_string, 1);
2076
+	foreach ($_GET as $k => $v) {
2077
+			$query_string .= ';' . $k . '=' . $v;
2078
+	}
2079
+	if (strlen($query_string) != 0) {
2080
+			$query_string = '?' . substr($query_string, 1);
2081
+	}
1967 2082
 
1968 2083
 	if ($command_line)
1969 2084
 	{
@@ -2018,16 +2133,18 @@  discard block
 block discarded – undo
2018 2133
 			{
2019 2134
 				$found |= 1;
2020 2135
 				// Do some checks on the data if we have it set.
2021
-				if (isset($change['col_type']))
2022
-					$found &= $change['col_type'] === $column['type'];
2023
-				if (isset($change['null_allowed']))
2024
-					$found &= $column['null'] == $change['null_allowed'];
2025
-				if (isset($change['default']))
2026
-					$found &= $change['default'] === $column['default'];
2136
+				if (isset($change['col_type'])) {
2137
+									$found &= $change['col_type'] === $column['type'];
2138
+				}
2139
+				if (isset($change['null_allowed'])) {
2140
+									$found &= $column['null'] == $change['null_allowed'];
2141
+				}
2142
+				if (isset($change['default'])) {
2143
+									$found &= $change['default'] === $column['default'];
2144
+				}
2027 2145
 			}
2028 2146
 		}
2029
-	}
2030
-	elseif ($change['type'] === 'index')
2147
+	} elseif ($change['type'] === 'index')
2031 2148
 	{
2032 2149
 		$request = upgrade_query('
2033 2150
 			SHOW INDEX
@@ -2036,9 +2153,10 @@  discard block
 block discarded – undo
2036 2153
 		{
2037 2154
 			$cur_index = array();
2038 2155
 
2039
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2040
-				if ($row['Key_name'] === $change['name'])
2156
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2157
+							if ($row['Key_name'] === $change['name'])
2041 2158
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2159
+			}
2042 2160
 
2043 2161
 			ksort($cur_index, SORT_NUMERIC);
2044 2162
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2048,14 +2166,17 @@  discard block
 block discarded – undo
2048 2166
 	}
2049 2167
 
2050 2168
 	// If we're trying to add and it's added, we're done.
2051
-	if ($found && in_array($change['method'], array('add', 'change')))
2052
-		return true;
2169
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2170
+			return true;
2171
+	}
2053 2172
 	// Otherwise if we're removing and it wasn't found we're also done.
2054
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2055
-		return true;
2173
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2174
+			return true;
2175
+	}
2056 2176
 	// Otherwise is it just a test?
2057
-	elseif ($is_test)
2058
-		return false;
2177
+	elseif ($is_test) {
2178
+			return false;
2179
+	}
2059 2180
 
2060 2181
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2061 2182
 	$running = false;
@@ -2066,8 +2187,9 @@  discard block
 block discarded – undo
2066 2187
 			SHOW FULL PROCESSLIST');
2067 2188
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2068 2189
 		{
2069
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2070
-				$found = true;
2190
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2191
+							$found = true;
2192
+			}
2071 2193
 		}
2072 2194
 
2073 2195
 		// Can't find it? Then we need to run it fools!
@@ -2079,8 +2201,9 @@  discard block
 block discarded – undo
2079 2201
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2080 2202
 				' . $change['text'], true) !== false;
2081 2203
 
2082
-			if (!$success)
2083
-				return false;
2204
+			if (!$success) {
2205
+							return false;
2206
+			}
2084 2207
 
2085 2208
 			// Return
2086 2209
 			$running = true;
@@ -2122,8 +2245,9 @@  discard block
 block discarded – undo
2122 2245
 			'db_error_skip' => true,
2123 2246
 		)
2124 2247
 	);
2125
-	if ($smcFunc['db_num_rows']($request) === 0)
2126
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2248
+	if ($smcFunc['db_num_rows']($request) === 0) {
2249
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2250
+	}
2127 2251
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2128 2252
 	$smcFunc['db_free_result']($request);
2129 2253
 
@@ -2145,18 +2269,19 @@  discard block
 block discarded – undo
2145 2269
 			)
2146 2270
 		);
2147 2271
 		// No results? Just forget it all together.
2148
-		if ($smcFunc['db_num_rows']($request) === 0)
2149
-			unset($table_row['Collation']);
2150
-		else
2151
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2272
+		if ($smcFunc['db_num_rows']($request) === 0) {
2273
+					unset($table_row['Collation']);
2274
+		} else {
2275
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2276
+		}
2152 2277
 		$smcFunc['db_free_result']($request);
2153 2278
 	}
2154 2279
 
2155 2280
 	if ($column_fix)
2156 2281
 	{
2157 2282
 		// Make sure there are no NULL's left.
2158
-		if ($null_fix)
2159
-			$smcFunc['db_query']('', '
2283
+		if ($null_fix) {
2284
+					$smcFunc['db_query']('', '
2160 2285
 				UPDATE {db_prefix}' . $change['table'] . '
2161 2286
 				SET ' . $change['column'] . ' = {string:default}
2162 2287
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2165,6 +2290,7 @@  discard block
 block discarded – undo
2165 2290
 					'db_error_skip' => true,
2166 2291
 				)
2167 2292
 			);
2293
+		}
2168 2294
 
2169 2295
 		// Do the actual alteration.
2170 2296
 		$smcFunc['db_query']('', '
@@ -2193,8 +2319,9 @@  discard block
 block discarded – undo
2193 2319
 	}
2194 2320
 
2195 2321
 	// Not a column we need to check on?
2196
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2197
-		return;
2322
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2323
+			return;
2324
+	}
2198 2325
 
2199 2326
 	// Break it up you (six|seven).
2200 2327
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2213,13 +2340,13 @@  discard block
 block discarded – undo
2213 2340
 				'new_name' => $temp[2],
2214 2341
 		));
2215 2342
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2216
-		if ($smcFunc['db_num_rows'] != 1)
2217
-			return;
2343
+		if ($smcFunc['db_num_rows'] != 1) {
2344
+					return;
2345
+		}
2218 2346
 
2219 2347
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2220 2348
 		$smcFunc['db_free_result']($request);
2221
-	}
2222
-	else
2349
+	} else
2223 2350
 	{
2224 2351
 		// Do this the old fashion, sure method way.
2225 2352
 		$request = $smcFunc['db_query']('', '
@@ -2230,21 +2357,24 @@  discard block
 block discarded – undo
2230 2357
 		));
2231 2358
 		// Mayday!
2232 2359
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2233
-		if ($smcFunc['db_num_rows'] == 0)
2234
-			return;
2360
+		if ($smcFunc['db_num_rows'] == 0) {
2361
+					return;
2362
+		}
2235 2363
 
2236 2364
 		// Oh where, oh where has my little field gone. Oh where can it be...
2237
-		while ($row = $smcFunc['db_query']($request))
2238
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2365
+		while ($row = $smcFunc['db_query']($request)) {
2366
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2239 2367
 			{
2240 2368
 				$current_type = $row['Type'];
2369
+		}
2241 2370
 				break;
2242 2371
 			}
2243 2372
 	}
2244 2373
 
2245 2374
 	// If this doesn't match, the column may of been altered for a reason.
2246
-	if (trim($current_type) != trim($temp[3]))
2247
-		$temp[3] = $current_type;
2375
+	if (trim($current_type) != trim($temp[3])) {
2376
+			$temp[3] = $current_type;
2377
+	}
2248 2378
 
2249 2379
 	// Piece this back together.
2250 2380
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2256,8 +2386,9 @@  discard block
 block discarded – undo
2256 2386
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2257 2387
 	global $step_progress, $is_debug, $upcontext;
2258 2388
 
2259
-	if ($_GET['substep'] < $substep)
2260
-		$_GET['substep'] = $substep;
2389
+	if ($_GET['substep'] < $substep) {
2390
+			$_GET['substep'] = $substep;
2391
+	}
2261 2392
 
2262 2393
 	if ($command_line)
2263 2394
 	{
@@ -2270,29 +2401,33 @@  discard block
 block discarded – undo
2270 2401
 	}
2271 2402
 
2272 2403
 	@set_time_limit(300);
2273
-	if (function_exists('apache_reset_timeout'))
2274
-		@apache_reset_timeout();
2404
+	if (function_exists('apache_reset_timeout')) {
2405
+			@apache_reset_timeout();
2406
+	}
2275 2407
 
2276
-	if (time() - $start_time <= $timeLimitThreshold)
2277
-		return;
2408
+	if (time() - $start_time <= $timeLimitThreshold) {
2409
+			return;
2410
+	}
2278 2411
 
2279 2412
 	// Do we have some custom step progress stuff?
2280 2413
 	if (!empty($step_progress))
2281 2414
 	{
2282 2415
 		$upcontext['substep_progress'] = 0;
2283 2416
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2284
-		if ($step_progress['current'] > $step_progress['total'])
2285
-			$upcontext['substep_progress'] = 99.9;
2286
-		else
2287
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2417
+		if ($step_progress['current'] > $step_progress['total']) {
2418
+					$upcontext['substep_progress'] = 99.9;
2419
+		} else {
2420
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2421
+		}
2288 2422
 
2289 2423
 		// Make it nicely rounded.
2290 2424
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2291 2425
 	}
2292 2426
 
2293 2427
 	// If this is XML we just exit right away!
2294
-	if (isset($_GET['xml']))
2295
-		return upgradeExit();
2428
+	if (isset($_GET['xml'])) {
2429
+			return upgradeExit();
2430
+	}
2296 2431
 
2297 2432
 	// We're going to pause after this!
2298 2433
 	$upcontext['pause'] = true;
@@ -2300,13 +2435,15 @@  discard block
 block discarded – undo
2300 2435
 	$upcontext['query_string'] = '';
2301 2436
 	foreach ($_GET as $k => $v)
2302 2437
 	{
2303
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2304
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2438
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2439
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2440
+		}
2305 2441
 	}
2306 2442
 
2307 2443
 	// Custom warning?
2308
-	if (!empty($custom_warning))
2309
-		$upcontext['custom_warning'] = $custom_warning;
2444
+	if (!empty($custom_warning)) {
2445
+			$upcontext['custom_warning'] = $custom_warning;
2446
+	}
2310 2447
 
2311 2448
 	upgradeExit();
2312 2449
 }
@@ -2321,25 +2458,26 @@  discard block
 block discarded – undo
2321 2458
 	ob_implicit_flush(true);
2322 2459
 	@set_time_limit(600);
2323 2460
 
2324
-	if (!isset($_SERVER['argv']))
2325
-		$_SERVER['argv'] = array();
2461
+	if (!isset($_SERVER['argv'])) {
2462
+			$_SERVER['argv'] = array();
2463
+	}
2326 2464
 	$_GET['maint'] = 1;
2327 2465
 
2328 2466
 	foreach ($_SERVER['argv'] as $i => $arg)
2329 2467
 	{
2330
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2331
-			$_GET['lang'] = $match[1];
2332
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2333
-			continue;
2334
-		elseif ($arg == '--no-maintenance')
2335
-			$_GET['maint'] = 0;
2336
-		elseif ($arg == '--debug')
2337
-			$is_debug = true;
2338
-		elseif ($arg == '--backup')
2339
-			$_POST['backup'] = 1;
2340
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2341
-			$_GET['conv'] = 1;
2342
-		elseif ($i != 0)
2468
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2469
+					$_GET['lang'] = $match[1];
2470
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2471
+					continue;
2472
+		} elseif ($arg == '--no-maintenance') {
2473
+					$_GET['maint'] = 0;
2474
+		} elseif ($arg == '--debug') {
2475
+					$is_debug = true;
2476
+		} elseif ($arg == '--backup') {
2477
+					$_POST['backup'] = 1;
2478
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2479
+					$_GET['conv'] = 1;
2480
+		} elseif ($i != 0)
2343 2481
 		{
2344 2482
 			echo 'SMF Command-line Upgrader
2345 2483
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2353,10 +2491,12 @@  discard block
 block discarded – undo
2353 2491
 		}
2354 2492
 	}
2355 2493
 
2356
-	if (!php_version_check())
2357
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2358
-	if (!db_version_check())
2359
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2494
+	if (!php_version_check()) {
2495
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2496
+	}
2497
+	if (!db_version_check()) {
2498
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2499
+	}
2360 2500
 
2361 2501
 	// Do some checks to make sure they have proper privileges
2362 2502
 	db_extend('packages');
@@ -2371,39 +2511,45 @@  discard block
 block discarded – undo
2371 2511
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2372 2512
 
2373 2513
 	// Sorry... we need CREATE, ALTER and DROP
2374
-	if (!$create || !$alter || !$drop)
2375
-		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);
2514
+	if (!$create || !$alter || !$drop) {
2515
+			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);
2516
+	}
2376 2517
 
2377 2518
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2378 2519
 		&& @file_exists($sourcedir . '/QueryString.php')
2379 2520
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2380
-	if (!$check && !isset($modSettings['smfVersion']))
2381
-		print_error('Error: Some files are missing or out-of-date.', true);
2521
+	if (!$check && !isset($modSettings['smfVersion'])) {
2522
+			print_error('Error: Some files are missing or out-of-date.', true);
2523
+	}
2382 2524
 
2383 2525
 	// Do a quick version spot check.
2384 2526
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2385 2527
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2386
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2387
-		print_error('Error: Some files have not yet been updated properly.');
2528
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2529
+			print_error('Error: Some files have not yet been updated properly.');
2530
+	}
2388 2531
 
2389 2532
 	// Make sure Settings.php is writable.
2390 2533
 	quickFileWritable($boarddir . '/Settings.php');
2391
-	if (!is_writable($boarddir . '/Settings.php'))
2392
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2534
+	if (!is_writable($boarddir . '/Settings.php')) {
2535
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2536
+	}
2393 2537
 
2394 2538
 	// Make sure Settings_bak.php is writable.
2395 2539
 	quickFileWritable($boarddir . '/Settings_bak.php');
2396
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2397
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2540
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2541
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2542
+	}
2398 2543
 
2399 2544
 	// Make sure db_last_error.php is writable.
2400 2545
 	quickFileWritable($boarddir . '/db_last_error.php');
2401
-	if (!is_writable($boarddir . '/db_last_error.php'))
2402
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2546
+	if (!is_writable($boarddir . '/db_last_error.php')) {
2547
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2548
+	}
2403 2549
 
2404
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2405
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2406
-	elseif (isset($modSettings['agreement']))
2550
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2551
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2552
+	} elseif (isset($modSettings['agreement']))
2407 2553
 	{
2408 2554
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2409 2555
 		fwrite($fp, $modSettings['agreement']);
@@ -2413,31 +2559,36 @@  discard block
 block discarded – undo
2413 2559
 	// Make sure Themes is writable.
2414 2560
 	quickFileWritable($modSettings['theme_dir']);
2415 2561
 
2416
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2417
-		print_error('Error: Unable to obtain write access to "Themes".');
2562
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2563
+			print_error('Error: Unable to obtain write access to "Themes".');
2564
+	}
2418 2565
 
2419 2566
 	// Make sure cache directory exists and is writable!
2420 2567
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2421
-	if (!file_exists($cachedir_temp))
2422
-		@mkdir($cachedir_temp);
2568
+	if (!file_exists($cachedir_temp)) {
2569
+			@mkdir($cachedir_temp);
2570
+	}
2423 2571
 
2424 2572
 	// Make sure the cache temp dir is writable.
2425 2573
 	quickFileWritable($cachedir_temp);
2426 2574
 
2427
-	if (!is_writable($cachedir_temp))
2428
-		print_error('Error: Unable to obtain write access to "cache".', true);
2575
+	if (!is_writable($cachedir_temp)) {
2576
+			print_error('Error: Unable to obtain write access to "cache".', true);
2577
+	}
2429 2578
 
2430
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2431
-		print_error('Error: Unable to find language files!', true);
2432
-	else
2579
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2580
+			print_error('Error: Unable to find language files!', true);
2581
+	} else
2433 2582
 	{
2434 2583
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2435 2584
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2436 2585
 
2437
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2438
-			print_error('Error: Language files out of date.', true);
2439
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2440
-			print_error('Error: Install language is missing for selected language.', true);
2586
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2587
+					print_error('Error: Language files out of date.', true);
2588
+		}
2589
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2590
+					print_error('Error: Install language is missing for selected language.', true);
2591
+		}
2441 2592
 
2442 2593
 		// Otherwise include it!
2443 2594
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2456,8 +2607,9 @@  discard block
 block discarded – undo
2456 2607
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2457 2608
 
2458 2609
 	// Done it already?
2459
-	if (!empty($_POST['utf8_done']))
2460
-		return true;
2610
+	if (!empty($_POST['utf8_done'])) {
2611
+			return true;
2612
+	}
2461 2613
 
2462 2614
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2463 2615
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2470,8 +2622,7 @@  discard block
 block discarded – undo
2470 2622
 		);
2471 2623
 
2472 2624
 		return true;
2473
-	}
2474
-	else
2625
+	} else
2475 2626
 	{
2476 2627
 		$upcontext['page_title'] = 'Converting to UTF8';
2477 2628
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2515,8 +2666,9 @@  discard block
 block discarded – undo
2515 2666
 			)
2516 2667
 		);
2517 2668
 		$db_charsets = array();
2518
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2519
-			$db_charsets[] = $row['Charset'];
2669
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2670
+					$db_charsets[] = $row['Charset'];
2671
+		}
2520 2672
 
2521 2673
 		$smcFunc['db_free_result']($request);
2522 2674
 
@@ -2552,13 +2704,15 @@  discard block
 block discarded – undo
2552 2704
 		// If there's a fulltext index, we need to drop it first...
2553 2705
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2554 2706
 		{
2555
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2556
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2707
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2708
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2557 2709
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2710
+			}
2558 2711
 			$smcFunc['db_free_result']($request);
2559 2712
 
2560
-			if (isset($upcontext['fulltext_index']))
2561
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2713
+			if (isset($upcontext['fulltext_index'])) {
2714
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2715
+			}
2562 2716
 		}
2563 2717
 
2564 2718
 		// Drop it and make a note...
@@ -2748,8 +2902,9 @@  discard block
 block discarded – undo
2748 2902
 			$replace = '%field%';
2749 2903
 
2750 2904
 			// Build a huge REPLACE statement...
2751
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2752
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2905
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2906
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2907
+			}
2753 2908
 		}
2754 2909
 
2755 2910
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2759,9 +2914,10 @@  discard block
 block discarded – undo
2759 2914
 		$upcontext['table_count'] = count($queryTables);
2760 2915
 
2761 2916
 		// What ones have we already done?
2762
-		foreach ($queryTables as $id => $table)
2763
-			if ($id < $_GET['substep'])
2917
+		foreach ($queryTables as $id => $table) {
2918
+					if ($id < $_GET['substep'])
2764 2919
 				$upcontext['previous_tables'][] = $table;
2920
+		}
2765 2921
 
2766 2922
 		$upcontext['cur_table_num'] = $_GET['substep'];
2767 2923
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2798,8 +2954,9 @@  discard block
 block discarded – undo
2798 2954
 			nextSubstep($substep);
2799 2955
 
2800 2956
 			// Just to make sure it doesn't time out.
2801
-			if (function_exists('apache_reset_timeout'))
2802
-				@apache_reset_timeout();
2957
+			if (function_exists('apache_reset_timeout')) {
2958
+							@apache_reset_timeout();
2959
+			}
2803 2960
 
2804 2961
 			$table_charsets = array();
2805 2962
 
@@ -2822,8 +2979,9 @@  discard block
 block discarded – undo
2822 2979
 
2823 2980
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2824 2981
 						if ($charset != 'utf8') {
2825
-							if (!isset($table_charsets[$charset]))
2826
-								$table_charsets[$charset] = array();
2982
+							if (!isset($table_charsets[$charset])) {
2983
+															$table_charsets[$charset] = array();
2984
+							}
2827 2985
 
2828 2986
 							$table_charsets[$charset][] = $column_info;
2829 2987
 						}
@@ -2864,10 +3022,11 @@  discard block
 block discarded – undo
2864 3022
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2865 3023
 				{
2866 3024
 					$update = '';
2867
-					foreach ($table_charsets as $charset => $columns)
2868
-						foreach ($columns as $column)
3025
+					foreach ($table_charsets as $charset => $columns) {
3026
+											foreach ($columns as $column)
2869 3027
 							$update .= '
2870 3028
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3029
+					}
2871 3030
 
2872 3031
 					$smcFunc['db_query']('', '
2873 3032
 						UPDATE {raw:table_name}
@@ -2892,8 +3051,9 @@  discard block
 block discarded – undo
2892 3051
 			// Now do the actual conversion (if still needed).
2893 3052
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2894 3053
 			{
2895
-				if ($command_line)
2896
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3054
+				if ($command_line) {
3055
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3056
+				}
2897 3057
 
2898 3058
 				$smcFunc['db_query']('', '
2899 3059
 					ALTER TABLE {raw:table_name}
@@ -2903,12 +3063,14 @@  discard block
 block discarded – undo
2903 3063
 					)
2904 3064
 				);
2905 3065
 
2906
-				if ($command_line)
2907
-					echo " done.\n";
3066
+				if ($command_line) {
3067
+									echo " done.\n";
3068
+				}
2908 3069
 			}
2909 3070
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2910
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2911
-				return upgradeExit();
3071
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3072
+							return upgradeExit();
3073
+			}
2912 3074
 		}
2913 3075
 
2914 3076
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2937,8 +3099,8 @@  discard block
 block discarded – undo
2937 3099
 		);
2938 3100
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2939 3101
 		{
2940
-			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)
2941
-				$smcFunc['db_query']('', '
3102
+			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) {
3103
+							$smcFunc['db_query']('', '
2942 3104
 					UPDATE {db_prefix}log_actions
2943 3105
 					SET extra = {string:extra}
2944 3106
 					WHERE id_action = {int:current_action}',
@@ -2947,6 +3109,7 @@  discard block
 block discarded – undo
2947 3109
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2948 3110
 					)
2949 3111
 				);
3112
+			}
2950 3113
 		}
2951 3114
 		$smcFunc['db_free_result']($request);
2952 3115
 
@@ -2968,15 +3131,17 @@  discard block
 block discarded – undo
2968 3131
 	// First thing's first - did we already do this?
2969 3132
 	if (!empty($modSettings['json_done']))
2970 3133
 	{
2971
-		if ($command_line)
2972
-			return DeleteUpgrade();
2973
-		else
2974
-			return true;
3134
+		if ($command_line) {
3135
+					return DeleteUpgrade();
3136
+		} else {
3137
+					return true;
3138
+		}
2975 3139
 	}
2976 3140
 
2977 3141
 	// Done it already - js wise?
2978
-	if (!empty($_POST['json_done']))
2979
-		return true;
3142
+	if (!empty($_POST['json_done'])) {
3143
+			return true;
3144
+	}
2980 3145
 
2981 3146
 	// List of tables affected by this function
2982 3147
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3008,12 +3173,14 @@  discard block
 block discarded – undo
3008 3173
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3009 3174
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3010 3175
 
3011
-	foreach ($keys as $id => $table)
3012
-		if ($id < $_GET['substep'])
3176
+	foreach ($keys as $id => $table) {
3177
+			if ($id < $_GET['substep'])
3013 3178
 			$upcontext['previous_tables'][] = $table;
3179
+	}
3014 3180
 
3015
-	if ($command_line)
3016
-		echo 'Converting data from serialize() to json_encode().';
3181
+	if ($command_line) {
3182
+			echo 'Converting data from serialize() to json_encode().';
3183
+	}
3017 3184
 
3018 3185
 	if (!$support_js || isset($_GET['xml']))
3019 3186
 	{
@@ -3053,8 +3220,9 @@  discard block
 block discarded – undo
3053 3220
 
3054 3221
 				// Loop through and fix these...
3055 3222
 				$new_settings = array();
3056
-				if ($command_line)
3057
-					echo "\n" . 'Fixing some settings...';
3223
+				if ($command_line) {
3224
+									echo "\n" . 'Fixing some settings...';
3225
+				}
3058 3226
 
3059 3227
 				foreach ($serialized_settings as $var)
3060 3228
 				{
@@ -3062,22 +3230,24 @@  discard block
 block discarded – undo
3062 3230
 					{
3063 3231
 						// Attempt to unserialize the setting
3064 3232
 						$temp = @safe_unserialize($modSettings[$var]);
3065
-						if (!$temp && $command_line)
3066
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3067
-						elseif ($temp !== false)
3068
-							$new_settings[$var] = json_encode($temp);
3233
+						if (!$temp && $command_line) {
3234
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3235
+						} elseif ($temp !== false) {
3236
+													$new_settings[$var] = json_encode($temp);
3237
+						}
3069 3238
 					}
3070 3239
 				}
3071 3240
 
3072 3241
 				// Update everything at once
3073
-				if (!function_exists('cache_put_data'))
3074
-					require_once($sourcedir . '/Load.php');
3242
+				if (!function_exists('cache_put_data')) {
3243
+									require_once($sourcedir . '/Load.php');
3244
+				}
3075 3245
 				updateSettings($new_settings, true);
3076 3246
 
3077
-				if ($command_line)
3078
-					echo ' done.';
3079
-			}
3080
-			elseif ($table == 'themes')
3247
+				if ($command_line) {
3248
+									echo ' done.';
3249
+				}
3250
+			} elseif ($table == 'themes')
3081 3251
 			{
3082 3252
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3083 3253
 				$query = $smcFunc['db_query']('', '
@@ -3096,10 +3266,11 @@  discard block
 block discarded – undo
3096 3266
 
3097 3267
 						if ($command_line)
3098 3268
 						{
3099
-							if ($temp === false)
3100
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3101
-							else
3102
-								echo "\n" . 'Fixing admin preferences...';
3269
+							if ($temp === false) {
3270
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3271
+							} else {
3272
+															echo "\n" . 'Fixing admin preferences...';
3273
+							}
3103 3274
 						}
3104 3275
 
3105 3276
 						if ($temp !== false)
@@ -3121,15 +3292,15 @@  discard block
 block discarded – undo
3121 3292
 								)
3122 3293
 							);
3123 3294
 
3124
-							if ($command_line)
3125
-								echo ' done.';
3295
+							if ($command_line) {
3296
+															echo ' done.';
3297
+							}
3126 3298
 						}
3127 3299
 					}
3128 3300
 
3129 3301
 					$smcFunc['db_free_result']($query);
3130 3302
 				}
3131
-			}
3132
-			else
3303
+			} else
3133 3304
 			{
3134 3305
 				// First item is always the key...
3135 3306
 				$key = $info[0];
@@ -3140,8 +3311,7 @@  discard block
 block discarded – undo
3140 3311
 				{
3141 3312
 					$col_select = $info[1];
3142 3313
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3143
-				}
3144
-				else
3314
+				} else
3145 3315
 				{
3146 3316
 					$col_select = implode(', ', $info);
3147 3317
 				}
@@ -3174,8 +3344,7 @@  discard block
 block discarded – undo
3174 3344
 								if ($temp === false && $command_line)
3175 3345
 								{
3176 3346
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3177
-								}
3178
-								else
3347
+								} else
3179 3348
 								{
3180 3349
 									$row[$col] = json_encode($temp);
3181 3350
 
@@ -3200,16 +3369,18 @@  discard block
 block discarded – undo
3200 3369
 						}
3201 3370
 					}
3202 3371
 
3203
-					if ($command_line)
3204
-						echo ' done.';
3372
+					if ($command_line) {
3373
+											echo ' done.';
3374
+					}
3205 3375
 
3206 3376
 					// Free up some memory...
3207 3377
 					$smcFunc['db_free_result']($query);
3208 3378
 				}
3209 3379
 			}
3210 3380
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3211
-			if (isset($_GET['xml']))
3212
-				return upgradeExit();
3381
+			if (isset($_GET['xml'])) {
3382
+							return upgradeExit();
3383
+			}
3213 3384
 		}
3214 3385
 
3215 3386
 		if ($command_line)
@@ -3224,8 +3395,9 @@  discard block
 block discarded – undo
3224 3395
 
3225 3396
 		$_GET['substep'] = 0;
3226 3397
 		// Make sure we move on!
3227
-		if ($command_line)
3228
-			return DeleteUpgrade();
3398
+		if ($command_line) {
3399
+					return DeleteUpgrade();
3400
+		}
3229 3401
 
3230 3402
 		return true;
3231 3403
 	}
@@ -3245,14 +3417,16 @@  discard block
 block discarded – undo
3245 3417
 	global $upcontext, $txt, $settings;
3246 3418
 
3247 3419
 	// Don't call me twice!
3248
-	if (!empty($upcontext['chmod_called']))
3249
-		return;
3420
+	if (!empty($upcontext['chmod_called'])) {
3421
+			return;
3422
+	}
3250 3423
 
3251 3424
 	$upcontext['chmod_called'] = true;
3252 3425
 
3253 3426
 	// Nothing?
3254
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3255
-		return;
3427
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3428
+			return;
3429
+	}
3256 3430
 
3257 3431
 	// Was it a problem with Windows?
3258 3432
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3284,11 +3458,12 @@  discard block
 block discarded – undo
3284 3458
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3285 3459
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3286 3460
 
3287
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3288
-		echo '
3461
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3462
+			echo '
3289 3463
 					content.write(\'<hr>\n\t\t\t\');
3290 3464
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3291 3465
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3466
+	}
3292 3467
 
3293 3468
 	echo '
3294 3469
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3296,17 +3471,19 @@  discard block
 block discarded – undo
3296 3471
 				}
3297 3472
 			</script>';
3298 3473
 
3299
-	if (!empty($upcontext['chmod']['ftp_error']))
3300
-		echo '
3474
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3475
+			echo '
3301 3476
 			<div class="error_message red">
3302 3477
 				', $txt['upgrade_ftp_error'], '<br><br>
3303 3478
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3304 3479
 			</div>
3305 3480
 			<br>';
3481
+	}
3306 3482
 
3307
-	if (empty($upcontext['chmod_in_form']))
3308
-		echo '
3483
+	if (empty($upcontext['chmod_in_form'])) {
3484
+			echo '
3309 3485
 	<form action="', $upcontext['form_url'], '" method="post">';
3486
+	}
3310 3487
 
3311 3488
 	echo '
3312 3489
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3341,10 +3518,11 @@  discard block
 block discarded – undo
3341 3518
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3342 3519
 	</div>';
3343 3520
 
3344
-	if (empty($upcontext['chmod_in_form']))
3345
-		echo '
3521
+	if (empty($upcontext['chmod_in_form'])) {
3522
+			echo '
3346 3523
 	</form>';
3347
-}
3524
+	}
3525
+	}
3348 3526
 
3349 3527
 function template_upgrade_above()
3350 3528
 {
@@ -3404,9 +3582,10 @@  discard block
 block discarded – undo
3404 3582
 				<h2>', $txt['upgrade_progress'], '</h2>
3405 3583
 				<ul>';
3406 3584
 
3407
-	foreach ($upcontext['steps'] as $num => $step)
3408
-		echo '
3585
+	foreach ($upcontext['steps'] as $num => $step) {
3586
+			echo '
3409 3587
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3588
+	}
3410 3589
 
3411 3590
 	echo '
3412 3591
 					</ul>
@@ -3419,8 +3598,8 @@  discard block
 block discarded – undo
3419 3598
 				</div>
3420 3599
 			</div>';
3421 3600
 
3422
-	if (isset($upcontext['step_progress']))
3423
-		echo '
3601
+	if (isset($upcontext['step_progress'])) {
3602
+			echo '
3424 3603
 				<br>
3425 3604
 				<br>
3426 3605
 				<div id="progress_bar_step">
@@ -3429,6 +3608,7 @@  discard block
 block discarded – undo
3429 3608
 						<span>', $txt['upgrade_step_progress'], '</span>
3430 3609
 					</div>
3431 3610
 				</div>';
3611
+	}
3432 3612
 
3433 3613
 	echo '
3434 3614
 				<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>
@@ -3459,32 +3639,36 @@  discard block
 block discarded – undo
3459 3639
 {
3460 3640
 	global $upcontext, $txt;
3461 3641
 
3462
-	if (!empty($upcontext['pause']))
3463
-		echo '
3642
+	if (!empty($upcontext['pause'])) {
3643
+			echo '
3464 3644
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3465 3645
 
3466 3646
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3467 3647
 								<h3>
3468 3648
 									', $txt['upgrade_paused_overload'], '
3469 3649
 								</h3>';
3650
+	}
3470 3651
 
3471
-	if (!empty($upcontext['custom_warning']))
3472
-		echo '
3652
+	if (!empty($upcontext['custom_warning'])) {
3653
+			echo '
3473 3654
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3474 3655
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3475 3656
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3476 3657
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3477 3658
 								</div>';
3659
+	}
3478 3660
 
3479 3661
 	echo '
3480 3662
 								<div class="righttext" style="margin: 1ex;">';
3481 3663
 
3482
-	if (!empty($upcontext['continue']))
3483
-		echo '
3664
+	if (!empty($upcontext['continue'])) {
3665
+			echo '
3484 3666
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3485
-	if (!empty($upcontext['skip']))
3486
-		echo '
3667
+	}
3668
+	if (!empty($upcontext['skip'])) {
3669
+			echo '
3487 3670
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3671
+	}
3488 3672
 
3489 3673
 	echo '
3490 3674
 								</div>
@@ -3534,11 +3718,12 @@  discard block
 block discarded – undo
3534 3718
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3535 3719
 	<smf>';
3536 3720
 
3537
-	if (!empty($upcontext['get_data']))
3538
-		foreach ($upcontext['get_data'] as $k => $v)
3721
+	if (!empty($upcontext['get_data'])) {
3722
+			foreach ($upcontext['get_data'] as $k => $v)
3539 3723
 			echo '
3540 3724
 		<get key="', $k, '">', $v, '</get>';
3541
-}
3725
+	}
3726
+	}
3542 3727
 
3543 3728
 function template_xml_below()
3544 3729
 {
@@ -3579,8 +3764,8 @@  discard block
 block discarded – undo
3579 3764
 	template_chmod();
3580 3765
 
3581 3766
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3582
-	if ($upcontext['is_large_forum'])
3583
-		echo '
3767
+	if ($upcontext['is_large_forum']) {
3768
+			echo '
3584 3769
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3585 3770
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3586 3771
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3588,10 +3773,11 @@  discard block
 block discarded – undo
3588 3773
 				', $txt['upgrade_warning_lots_data'], '
3589 3774
 			</div>
3590 3775
 		</div>';
3776
+	}
3591 3777
 
3592 3778
 	// A warning message?
3593
-	if (!empty($upcontext['warning']))
3594
-		echo '
3779
+	if (!empty($upcontext['warning'])) {
3780
+			echo '
3595 3781
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3596 3782
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3597 3783
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3599,6 +3785,7 @@  discard block
 block discarded – undo
3599 3785
 				', $upcontext['warning'], '
3600 3786
 			</div>
3601 3787
 		</div>';
3788
+	}
3602 3789
 
3603 3790
 	// Paths are incorrect?
3604 3791
 	echo '
@@ -3614,20 +3801,22 @@  discard block
 block discarded – undo
3614 3801
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3615 3802
 	{
3616 3803
 		$ago = time() - $upcontext['started'];
3617
-		if ($ago < 60)
3618
-			$ago = $ago . ' seconds';
3619
-		elseif ($ago < 3600)
3620
-			$ago = (int) ($ago / 60) . ' minutes';
3621
-		else
3622
-			$ago = (int) ($ago / 3600) . ' hours';
3804
+		if ($ago < 60) {
3805
+					$ago = $ago . ' seconds';
3806
+		} elseif ($ago < 3600) {
3807
+					$ago = (int) ($ago / 60) . ' minutes';
3808
+		} else {
3809
+					$ago = (int) ($ago / 3600) . ' hours';
3810
+		}
3623 3811
 
3624 3812
 		$active = time() - $upcontext['updated'];
3625
-		if ($active < 60)
3626
-			$updated = $active . ' seconds';
3627
-		elseif ($active < 3600)
3628
-			$updated = (int) ($active / 60) . ' minutes';
3629
-		else
3630
-			$updated = (int) ($active / 3600) . ' hours';
3813
+		if ($active < 60) {
3814
+					$updated = $active . ' seconds';
3815
+		} elseif ($active < 3600) {
3816
+					$updated = (int) ($active / 60) . ' minutes';
3817
+		} else {
3818
+					$updated = (int) ($active / 3600) . ' hours';
3819
+		}
3631 3820
 
3632 3821
 		echo '
3633 3822
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3636,16 +3825,18 @@  discard block
 block discarded – undo
3636 3825
 			<div style="padding-left: 6ex;">
3637 3826
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3638 3827
 
3639
-		if ($active < 600)
3640
-			echo '
3828
+		if ($active < 600) {
3829
+					echo '
3641 3830
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3831
+		}
3642 3832
 
3643
-		if ($active > $upcontext['inactive_timeout'])
3644
-			echo '
3833
+		if ($active > $upcontext['inactive_timeout']) {
3834
+					echo '
3645 3835
 				<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.';
3646
-		else
3647
-			echo '
3836
+		} else {
3837
+					echo '
3648 3838
 				<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!');
3839
+		}
3649 3840
 
3650 3841
 		echo '
3651 3842
 			</div>
@@ -3661,9 +3852,10 @@  discard block
 block discarded – undo
3661 3852
 					<td>
3662 3853
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3663 3854
 
3664
-	if (!empty($upcontext['username_incorrect']))
3665
-		echo '
3855
+	if (!empty($upcontext['username_incorrect'])) {
3856
+			echo '
3666 3857
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>';
3858
+	}
3667 3859
 
3668 3860
 	echo '
3669 3861
 					</td>
@@ -3674,9 +3866,10 @@  discard block
 block discarded – undo
3674 3866
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3675 3867
 						<input type="hidden" name="hash_passwrd" value="">';
3676 3868
 
3677
-	if (!empty($upcontext['password_failed']))
3678
-		echo '
3869
+	if (!empty($upcontext['password_failed'])) {
3870
+			echo '
3679 3871
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>';
3872
+	}
3680 3873
 
3681 3874
 	echo '
3682 3875
 					</td>
@@ -3747,8 +3940,8 @@  discard block
 block discarded – undo
3747 3940
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3748 3941
 
3749 3942
 	// Warning message?
3750
-	if (!empty($upcontext['upgrade_options_warning']))
3751
-		echo '
3943
+	if (!empty($upcontext['upgrade_options_warning'])) {
3944
+			echo '
3752 3945
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3753 3946
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3754 3947
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3756,6 +3949,7 @@  discard block
 block discarded – undo
3756 3949
 				', $upcontext['upgrade_options_warning'], '
3757 3950
 			</div>
3758 3951
 		</div>';
3952
+	}
3759 3953
 
3760 3954
 	echo '
3761 3955
 				<table>
@@ -3798,8 +3992,8 @@  discard block
 block discarded – undo
3798 3992
 						</td>
3799 3993
 					</tr>';
3800 3994
 
3801
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3802
-		echo '
3995
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3996
+			echo '
3803 3997
 					<tr valign="top">
3804 3998
 						<td width="2%">
3805 3999
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3808,6 +4002,7 @@  discard block
 block discarded – undo
3808 4002
 							<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3809 4003
 						</td>
3810 4004
 					</tr>';
4005
+	}
3811 4006
 
3812 4007
 	echo '
3813 4008
 					<tr valign="top">
@@ -3845,10 +4040,11 @@  discard block
 block discarded – undo
3845 4040
 			</div>';
3846 4041
 
3847 4042
 	// Dont any tables so far?
3848
-	if (!empty($upcontext['previous_tables']))
3849
-		foreach ($upcontext['previous_tables'] as $table)
4043
+	if (!empty($upcontext['previous_tables'])) {
4044
+			foreach ($upcontext['previous_tables'] as $table)
3850 4045
 			echo '
3851 4046
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4047
+	}
3852 4048
 
3853 4049
 	echo '
3854 4050
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3885,12 +4081,13 @@  discard block
 block discarded – undo
3885 4081
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3886 4082
 
3887 4083
 		// If debug flood the screen.
3888
-		if ($is_debug)
3889
-			echo '
4084
+		if ($is_debug) {
4085
+					echo '
3890 4086
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3891 4087
 
3892 4088
 				if (document.getElementById(\'debug_section\').scrollHeight)
3893 4089
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4090
+		}
3894 4091
 
3895 4092
 		echo '
3896 4093
 				// Get the next update...
@@ -3923,8 +4120,9 @@  discard block
 block discarded – undo
3923 4120
 {
3924 4121
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3925 4122
 
3926
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3927
-		$is_debug = true;
4123
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4124
+			$is_debug = true;
4125
+	}
3928 4126
 
3929 4127
 	echo '
3930 4128
 		<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -3939,8 +4137,9 @@  discard block
 block discarded – undo
3939 4137
 	{
3940 4138
 		foreach ($upcontext['actioned_items'] as $num => $item)
3941 4139
 		{
3942
-			if ($num != 0)
3943
-				echo ' Successful!';
4140
+			if ($num != 0) {
4141
+							echo ' Successful!';
4142
+			}
3944 4143
 			echo '<br>' . $item;
3945 4144
 		}
3946 4145
 		if (!empty($upcontext['changes_complete']))
@@ -3953,28 +4152,32 @@  discard block
 block discarded – undo
3953 4152
 				$seconds = intval($active % 60);
3954 4153
 
3955 4154
 				$totalTime = '';
3956
-				if ($hours > 0)
3957
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3958
-				if ($minutes > 0)
3959
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3960
-				if ($seconds > 0)
3961
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4155
+				if ($hours > 0) {
4156
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4157
+				}
4158
+				if ($minutes > 0) {
4159
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4160
+				}
4161
+				if ($seconds > 0) {
4162
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4163
+				}
3962 4164
 			}
3963 4165
 
3964
-			if ($is_debug && !empty($totalTime))
3965
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3966
-			else
3967
-				echo ' Successful!<br><br>';
4166
+			if ($is_debug && !empty($totalTime)) {
4167
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4168
+			} else {
4169
+							echo ' Successful!<br><br>';
4170
+			}
3968 4171
 
3969 4172
 			echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>';
3970 4173
 		}
3971
-	}
3972
-	else
4174
+	} else
3973 4175
 	{
3974 4176
 		// Tell them how many files we have in total.
3975
-		if ($upcontext['file_count'] > 1)
3976
-			echo '
4177
+		if ($upcontext['file_count'] > 1) {
4178
+					echo '
3977 4179
 		<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4180
+		}
3978 4181
 
3979 4182
 		echo '
3980 4183
 		<h3 id="info2"><strong>', $txt['upgrade_executing'], '</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> ', $txt['upgrade_of'], ' <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3990,19 +4193,23 @@  discard block
 block discarded – undo
3990 4193
 				$seconds = intval($active % 60);
3991 4194
 
3992 4195
 				$totalTime = '';
3993
-				if ($hours > 0)
3994
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3995
-				if ($minutes > 0)
3996
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3997
-				if ($seconds > 0)
3998
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4196
+				if ($hours > 0) {
4197
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4198
+				}
4199
+				if ($minutes > 0) {
4200
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4201
+				}
4202
+				if ($seconds > 0) {
4203
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4204
+				}
3999 4205
 			}
4000 4206
 
4001 4207
 			echo '
4002 4208
 			<br><span id="upgradeCompleted">';
4003 4209
 
4004
-			if (!empty($totalTime))
4005
-				echo 'Completed in ', $totalTime, '<br>';
4210
+			if (!empty($totalTime)) {
4211
+							echo 'Completed in ', $totalTime, '<br>';
4212
+			}
4006 4213
 
4007 4214
 			echo '</span>
4008 4215
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4039,9 +4246,10 @@  discard block
 block discarded – undo
4039 4246
 			var getData = "";
4040 4247
 			var debugItems = ', $upcontext['debug_items'], ';';
4041 4248
 
4042
-		if ($is_debug)
4043
-			echo '
4249
+		if ($is_debug) {
4250
+					echo '
4044 4251
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4252
+		}
4045 4253
 
4046 4254
 		echo '
4047 4255
 			function getNextItem()
@@ -4081,9 +4289,10 @@  discard block
 block discarded – undo
4081 4289
 						document.getElementById("error_block").style.display = "";
4082 4290
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4083 4291
 
4084
-	if ($is_debug)
4085
-		echo '
4292
+	if ($is_debug) {
4293
+			echo '
4086 4294
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4295
+	}
4087 4296
 
4088 4297
 	echo '
4089 4298
 					}
@@ -4104,9 +4313,10 @@  discard block
 block discarded – undo
4104 4313
 						document.getElementById("error_block").style.display = "";
4105 4314
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4106 4315
 
4107
-	if ($is_debug)
4108
-		echo '
4316
+	if ($is_debug) {
4317
+			echo '
4109 4318
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4319
+	}
4110 4320
 
4111 4321
 	echo '
4112 4322
 					}
@@ -4165,8 +4375,8 @@  discard block
 block discarded – undo
4165 4375
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4166 4376
 				{';
4167 4377
 
4168
-		if ($is_debug)
4169
-			echo '
4378
+		if ($is_debug) {
4379
+					echo '
4170 4380
 					document.getElementById(\'debug_section\').style.display = "none";
4171 4381
 
4172 4382
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4184,6 +4394,7 @@  discard block
 block discarded – undo
4184 4394
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4185 4395
 
4186 4396
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4397
+		}
4187 4398
 
4188 4399
 		echo '
4189 4400
 
@@ -4191,9 +4402,10 @@  discard block
 block discarded – undo
4191 4402
 					document.getElementById(\'contbutt\').disabled = 0;
4192 4403
 					document.getElementById(\'database_done\').value = 1;';
4193 4404
 
4194
-		if ($upcontext['file_count'] > 1)
4195
-			echo '
4405
+		if ($upcontext['file_count'] > 1) {
4406
+					echo '
4196 4407
 					document.getElementById(\'info1\').style.display = "none";';
4408
+		}
4197 4409
 
4198 4410
 		echo '
4199 4411
 					document.getElementById(\'info2\').style.display = "none";
@@ -4206,9 +4418,10 @@  discard block
 block discarded – undo
4206 4418
 					lastItem = 0;
4207 4419
 					prevFile = curFile;';
4208 4420
 
4209
-		if ($is_debug)
4210
-			echo '
4421
+		if ($is_debug) {
4422
+					echo '
4211 4423
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4424
+		}
4212 4425
 
4213 4426
 		echo '
4214 4427
 					getNextItem();
@@ -4216,8 +4429,8 @@  discard block
 block discarded – undo
4216 4429
 				}';
4217 4430
 
4218 4431
 		// If debug scroll the screen.
4219
-		if ($is_debug)
4220
-			echo '
4432
+		if ($is_debug) {
4433
+					echo '
4221 4434
 				if (iLastSubStepProgress == -1)
4222 4435
 				{
4223 4436
 					// Give it consistent dots.
@@ -4236,6 +4449,7 @@  discard block
 block discarded – undo
4236 4449
 
4237 4450
 				if (document.getElementById(\'debug_section\').scrollHeight)
4238 4451
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4452
+		}
4239 4453
 
4240 4454
 		echo '
4241 4455
 				// Update the page.
@@ -4296,9 +4510,10 @@  discard block
 block discarded – undo
4296 4510
 			}';
4297 4511
 
4298 4512
 		// Start things off assuming we've not errored.
4299
-		if (empty($upcontext['error_message']))
4300
-			echo '
4513
+		if (empty($upcontext['error_message'])) {
4514
+					echo '
4301 4515
 			getNextItem();';
4516
+		}
4302 4517
 
4303 4518
 		echo '
4304 4519
 		//# sourceURL=dynamicScript-dbch.js
@@ -4316,18 +4531,21 @@  discard block
 block discarded – undo
4316 4531
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4317 4532
 	<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>';
4318 4533
 
4319
-	if (!empty($upcontext['error_message']))
4320
-		echo '
4534
+	if (!empty($upcontext['error_message'])) {
4535
+			echo '
4321 4536
 	<error>', $upcontext['error_message'], '</error>';
4537
+	}
4322 4538
 
4323
-	if (!empty($upcontext['error_string']))
4324
-		echo '
4539
+	if (!empty($upcontext['error_string'])) {
4540
+			echo '
4325 4541
 	<sql>', $upcontext['error_string'], '</sql>';
4542
+	}
4326 4543
 
4327
-	if ($is_debug)
4328
-		echo '
4544
+	if ($is_debug) {
4545
+			echo '
4329 4546
 	<curtime>', time(), '</curtime>';
4330
-}
4547
+	}
4548
+	}
4331 4549
 
4332 4550
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4333 4551
 function template_convert_utf8()
@@ -4346,18 +4564,20 @@  discard block
 block discarded – undo
4346 4564
 			</div>';
4347 4565
 
4348 4566
 	// Done any tables so far?
4349
-	if (!empty($upcontext['previous_tables']))
4350
-		foreach ($upcontext['previous_tables'] as $table)
4567
+	if (!empty($upcontext['previous_tables'])) {
4568
+			foreach ($upcontext['previous_tables'] as $table)
4351 4569
 			echo '
4352 4570
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4571
+	}
4353 4572
 
4354 4573
 	echo '
4355 4574
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4356 4575
 
4357 4576
 	// If we dropped their index, let's let them know
4358
-	if ($upcontext['dropping_index'])
4359
-		echo '
4577
+	if ($upcontext['dropping_index']) {
4578
+			echo '
4360 4579
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</span>';
4580
+	}
4361 4581
 
4362 4582
 	// Completion notification
4363 4583
 	echo '
@@ -4394,12 +4614,13 @@  discard block
 block discarded – undo
4394 4614
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4395 4615
 
4396 4616
 		// If debug flood the screen.
4397
-		if ($is_debug)
4398
-			echo '
4617
+		if ($is_debug) {
4618
+					echo '
4399 4619
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4400 4620
 
4401 4621
 				if (document.getElementById(\'debug_section\').scrollHeight)
4402 4622
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4623
+		}
4403 4624
 
4404 4625
 		echo '
4405 4626
 				// Get the next update...
@@ -4447,19 +4668,21 @@  discard block
 block discarded – undo
4447 4668
 			</div>';
4448 4669
 
4449 4670
 	// Dont any tables so far?
4450
-	if (!empty($upcontext['previous_tables']))
4451
-		foreach ($upcontext['previous_tables'] as $table)
4671
+	if (!empty($upcontext['previous_tables'])) {
4672
+			foreach ($upcontext['previous_tables'] as $table)
4452 4673
 			echo '
4453 4674
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4675
+	}
4454 4676
 
4455 4677
 	echo '
4456 4678
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4457 4679
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>';
4458 4680
 
4459 4681
 	// Try to make sure substep was reset.
4460
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4461
-		echo '
4682
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4683
+			echo '
4462 4684
 			<input type="hidden" name="substep" id="substep" value="0">';
4685
+	}
4463 4686
 
4464 4687
 	// Continue please!
4465 4688
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4492,12 +4715,13 @@  discard block
 block discarded – undo
4492 4715
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4493 4716
 
4494 4717
 		// If debug flood the screen.
4495
-		if ($is_debug)
4496
-			echo '
4718
+		if ($is_debug) {
4719
+					echo '
4497 4720
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4498 4721
 
4499 4722
 				if (document.getElementById(\'debug_section\').scrollHeight)
4500 4723
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4724
+		}
4501 4725
 
4502 4726
 		echo '
4503 4727
 				// Get the next update...
@@ -4533,8 +4757,8 @@  discard block
 block discarded – undo
4533 4757
 	<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done2'], '</h3>
4534 4758
 	<form action="', $boardurl, '/index.php">';
4535 4759
 
4536
-	if (!empty($upcontext['can_delete_script']))
4537
-		echo '
4760
+	if (!empty($upcontext['can_delete_script'])) {
4761
+			echo '
4538 4762
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> ', $txt['upgrade_delete_server'], '
4539 4763
 			<script>
4540 4764
 				function doTheDelete(theCheck)
@@ -4546,6 +4770,7 @@  discard block
 block discarded – undo
4546 4770
 				}
4547 4771
 			</script>
4548 4772
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4773
+	}
4549 4774
 
4550 4775
 	$active = time() - $upcontext['started'];
4551 4776
 	$hours = floor($active / 3600);
@@ -4555,16 +4780,20 @@  discard block
 block discarded – undo
4555 4780
 	if ($is_debug)
4556 4781
 	{
4557 4782
 		$totalTime = '';
4558
-		if ($hours > 0)
4559
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4560
-		if ($minutes > 0)
4561
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4562
-		if ($seconds > 0)
4563
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4783
+		if ($hours > 0) {
4784
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4785
+		}
4786
+		if ($minutes > 0) {
4787
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4788
+		}
4789
+		if ($seconds > 0) {
4790
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4791
+		}
4564 4792
 	}
4565 4793
 
4566
-	if ($is_debug && !empty($totalTime))
4567
-		echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4794
+	if ($is_debug && !empty($totalTime)) {
4795
+			echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4796
+	}
4568 4797
 
4569 4798
 	echo '<br>
4570 4799
 			', $txt['upgrade_problems'], '<br>
@@ -4591,8 +4820,9 @@  discard block
 block discarded – undo
4591 4820
 
4592 4821
 	$current_substep = $_GET['substep'];
4593 4822
 
4594
-	if (empty($_GET['a']))
4595
-		$_GET['a'] = 0;
4823
+	if (empty($_GET['a'])) {
4824
+			$_GET['a'] = 0;
4825
+	}
4596 4826
 	$step_progress['name'] = 'Converting ips';
4597 4827
 	$step_progress['current'] = $_GET['a'];
4598 4828
 
@@ -4635,16 +4865,19 @@  discard block
 block discarded – undo
4635 4865
 				'empty' => '',
4636 4866
 				'limit' => $limit,
4637 4867
 		));
4638
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4639
-			$arIp[] = $row[$oldCol];
4868
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4869
+					$arIp[] = $row[$oldCol];
4870
+		}
4640 4871
 		$smcFunc['db_free_result']($request);
4641 4872
 
4642 4873
 		// Special case, null ip could keep us in a loop.
4643
-		if (is_null($arIp[0]))
4644
-			unset($arIp[0]);
4874
+		if (is_null($arIp[0])) {
4875
+					unset($arIp[0]);
4876
+		}
4645 4877
 
4646
-		if (empty($arIp))
4647
-			$is_done = true;
4878
+		if (empty($arIp)) {
4879
+					$is_done = true;
4880
+		}
4648 4881
 
4649 4882
 		$updates = array();
4650 4883
 		$cases = array();
@@ -4653,16 +4886,18 @@  discard block
 block discarded – undo
4653 4886
 		{
4654 4887
 			$arIp[$i] = trim($arIp[$i]);
4655 4888
 
4656
-			if (empty($arIp[$i]))
4657
-				continue;
4889
+			if (empty($arIp[$i])) {
4890
+							continue;
4891
+			}
4658 4892
 
4659 4893
 			$updates['ip' . $i] = $arIp[$i];
4660 4894
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4661 4895
 
4662 4896
 			if ($setSize > 0 && $i % $setSize === 0)
4663 4897
 			{
4664
-				if (count($updates) == 1)
4665
-					continue;
4898
+				if (count($updates) == 1) {
4899
+									continue;
4900
+				}
4666 4901
 
4667 4902
 				$updates['whereSet'] = array_values($updates);
4668 4903
 				$smcFunc['db_query']('', '
@@ -4696,8 +4931,7 @@  discard block
 block discarded – undo
4696 4931
 							'ip' => $ip
4697 4932
 					));
4698 4933
 				}
4699
-			}
4700
-			else
4934
+			} else
4701 4935
 			{
4702 4936
 				$updates['whereSet'] = array_values($updates);
4703 4937
 				$smcFunc['db_query']('', '
@@ -4711,9 +4945,9 @@  discard block
 block discarded – undo
4711 4945
 					$updates
4712 4946
 				);
4713 4947
 			}
4948
+		} else {
4949
+					$is_done = true;
4714 4950
 		}
4715
-		else
4716
-			$is_done = true;
4717 4951
 
4718 4952
 		$_GET['a'] += $limit;
4719 4953
 		$step_progress['current'] = $_GET['a'];
@@ -4739,10 +4973,11 @@  discard block
 block discarded – undo
4739 4973
 
4740 4974
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4741 4975
 
4742
-	if (isset($columns[$column]))
4743
-		return $columns[$column];
4744
-	else
4745
-		return null;
4746
-}
4976
+	if (isset($columns[$column])) {
4977
+			return $columns[$column];
4978
+	} else {
4979
+			return null;
4980
+	}
4981
+	}
4747 4982
 
4748 4983
 ?>
Please login to merge, or discard this patch.