Completed
Pull Request — release-2.1 (#4591)
by Fran
07:44
created
other/upgrade.php 1 patch
Braces   +898 added lines, -659 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -107,11 +108,14 @@  discard block
 block discarded – undo
107 108
 	ini_set('default_socket_timeout', 900);
108 109
 }
109 110
 // Clean the upgrade path if this is from the client.
110
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
111
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
111
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
112
+	for ($i = 1;
113
+}
114
+$i < $_SERVER['argc']; $i++)
112 115
 	{
113
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
114
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
116
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
117
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
118
+		}
115 119
 	}
116 120
 
117 121
 // Are we from the client?
@@ -119,16 +123,17 @@  discard block
 block discarded – undo
119 123
 {
120 124
 	$command_line = true;
121 125
 	$disable_security = true;
122
-}
123
-else
126
+} else {
124 127
 	$command_line = false;
128
+}
125 129
 
126 130
 // Load this now just because we can.
127 131
 require_once($upgrade_path . '/Settings.php');
128 132
 
129 133
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
130
-if (isset($language))
134
+if (isset($language)) {
131 135
 	$language = str_ireplace('-utf8', '', $language);
136
+}
132 137
 
133 138
 // Are we logged in?
134 139
 if (isset($upgradeData))
@@ -136,10 +141,12 @@  discard block
 block discarded – undo
136 141
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
137 142
 
138 143
 	// Check for sensible values.
139
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
140
-		$upcontext['user']['started'] = time();
141
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
142
-		$upcontext['user']['updated'] = 0;
144
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
145
+			$upcontext['user']['started'] = time();
146
+	}
147
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
148
+			$upcontext['user']['updated'] = 0;
149
+	}
143 150
 
144 151
 	$upcontext['started'] = $upcontext['user']['started'];
145 152
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 			'db_error_skip' => true,
205 212
 		)
206 213
 	);
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$modSettings[$row['variable']] = $row['value'];
214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
215
+			$modSettings[$row['variable']] = $row['value'];
216
+	}
209 217
 	$smcFunc['db_free_result']($request);
210 218
 }
211 219
 
@@ -215,10 +223,12 @@  discard block
 block discarded – undo
215 223
 	$modSettings['theme_url'] = 'Themes/default';
216 224
 	$modSettings['images_url'] = 'Themes/default/images';
217 225
 }
218
-if (!isset($settings['default_theme_url']))
226
+if (!isset($settings['default_theme_url'])) {
219 227
 	$settings['default_theme_url'] = $modSettings['theme_url'];
220
-if (!isset($settings['default_theme_dir']))
228
+}
229
+if (!isset($settings['default_theme_dir'])) {
221 230
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
231
+}
222 232
 
223 233
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
224 234
 // Default title...
@@ -236,13 +246,15 @@  discard block
 block discarded – undo
236 246
 	$support_js = $upcontext['upgrade_status']['js'];
237 247
 
238 248
 	// Only set this if the upgrader status says so.
239
-	if (empty($is_debug))
240
-		$is_debug = $upcontext['upgrade_status']['debug'];
249
+	if (empty($is_debug)) {
250
+			$is_debug = $upcontext['upgrade_status']['debug'];
251
+	}
241 252
 
242 253
 	// Load the language.
243
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
244
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
245
-}
254
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
255
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
256
+	}
257
+	}
246 258
 // Set the defaults.
247 259
 else
248 260
 {
@@ -260,15 +272,18 @@  discard block
 block discarded – undo
260 272
 }
261 273
 
262 274
 // If this isn't the first stage see whether they are logging in and resuming.
263
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
275
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
264 276
 	checkLogin();
277
+}
265 278
 
266
-if ($command_line)
279
+if ($command_line) {
267 280
 	cmdStep0();
281
+}
268 282
 
269 283
 // Don't error if we're using xml.
270
-if (isset($_GET['xml']))
284
+if (isset($_GET['xml'])) {
271 285
 	$upcontext['return_error'] = true;
286
+}
272 287
 
273 288
 // Loop through all the steps doing each one as required.
274 289
 $upcontext['overall_percent'] = 0;
@@ -289,9 +304,9 @@  discard block
 block discarded – undo
289 304
 		}
290 305
 
291 306
 		// Call the step and if it returns false that means pause!
292
-		if (function_exists($step[2]) && $step[2]() === false)
293
-			break;
294
-		elseif (function_exists($step[2])) {
307
+		if (function_exists($step[2]) && $step[2]() === false) {
308
+					break;
309
+		} elseif (function_exists($step[2])) {
295 310
 			//Start each new step with this unset, so the 'normal' template is called first
296 311
 			unset($_GET['xml']);
297 312
 			//Clear out warnings at the start of each step
@@ -337,17 +352,18 @@  discard block
 block discarded – undo
337 352
 		// This should not happen my dear... HELP ME DEVELOPERS!!
338 353
 		if (!empty($command_line))
339 354
 		{
340
-			if (function_exists('debug_print_backtrace'))
341
-				debug_print_backtrace();
355
+			if (function_exists('debug_print_backtrace')) {
356
+							debug_print_backtrace();
357
+			}
342 358
 
343 359
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
344 360
 			flush();
345 361
 			die();
346 362
 		}
347 363
 
348
-		if (!isset($_GET['xml']))
349
-			template_upgrade_above();
350
-		else
364
+		if (!isset($_GET['xml'])) {
365
+					template_upgrade_above();
366
+		} else
351 367
 		{
352 368
 			header('content-type: text/xml; charset=UTF-8');
353 369
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -369,25 +385,29 @@  discard block
 block discarded – undo
369 385
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
370 386
 
371 387
 			// Custom stuff to pass back?
372
-			if (!empty($upcontext['query_string']))
373
-				$upcontext['form_url'] .= $upcontext['query_string'];
388
+			if (!empty($upcontext['query_string'])) {
389
+							$upcontext['form_url'] .= $upcontext['query_string'];
390
+			}
374 391
 
375 392
 			// Call the appropriate subtemplate
376
-			if (is_callable('template_' . $upcontext['sub_template']))
377
-				call_user_func('template_' . $upcontext['sub_template']);
378
-			else
379
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
393
+			if (is_callable('template_' . $upcontext['sub_template'])) {
394
+							call_user_func('template_' . $upcontext['sub_template']);
395
+			} else {
396
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
397
+			}
380 398
 		}
381 399
 
382 400
 		// Was there an error?
383
-		if (!empty($upcontext['forced_error_message']))
384
-			echo $upcontext['forced_error_message'];
401
+		if (!empty($upcontext['forced_error_message'])) {
402
+					echo $upcontext['forced_error_message'];
403
+		}
385 404
 
386 405
 		// Show the footer.
387
-		if (!isset($_GET['xml']))
388
-			template_upgrade_below();
389
-		else
390
-			template_xml_below();
406
+		if (!isset($_GET['xml'])) {
407
+					template_upgrade_below();
408
+		} else {
409
+					template_xml_below();
410
+		}
391 411
 	}
392 412
 
393 413
 
@@ -399,15 +419,19 @@  discard block
 block discarded – undo
399 419
 		$seconds = intval($active % 60);
400 420
 
401 421
 		$totalTime = '';
402
-		if ($hours > 0)
403
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
404
-		if ($minutes > 0)
405
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
406
-		if ($seconds > 0)
407
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
422
+		if ($hours > 0) {
423
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
424
+		}
425
+		if ($minutes > 0) {
426
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
427
+		}
428
+		if ($seconds > 0) {
429
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
430
+		}
408 431
 
409
-		if (!empty($totalTime))
410
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
432
+		if (!empty($totalTime)) {
433
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
434
+		}
411 435
 	}
412 436
 
413 437
 	// Bang - gone!
@@ -428,8 +452,9 @@  discard block
 block discarded – undo
428 452
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
429 453
 		while ($entry = $dir->read())
430 454
 		{
431
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
432
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
455
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
456
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
457
+			}
433 458
 		}
434 459
 		$dir->close();
435 460
 	}
@@ -464,10 +489,11 @@  discard block
 block discarded – undo
464 489
 	}
465 490
 
466 491
 		// Override the language file?
467
-		if (isset($_GET['lang_file']))
468
-			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
469
-		elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
470
-			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
492
+		if (isset($_GET['lang_file'])) {
493
+					$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
494
+		} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
495
+					$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
496
+		}
471 497
 
472 498
 		// Make sure it exists, if it doesn't reset it.
473 499
 		if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -476,8 +502,9 @@  discard block
 block discarded – undo
476 502
 			list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
477 503
 
478 504
 			// If we have english and some other language, use the other language.  We Americans hate english :P.
479
-			if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
480
-				list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
505
+			if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
506
+							list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
507
+			}
481 508
 		}
482 509
 
483 510
 		// And now include the actual language file itself.
@@ -494,8 +521,9 @@  discard block
 block discarded – undo
494 521
 	global $upgradeurl, $upcontext, $command_line;
495 522
 
496 523
 	// Command line users can't be redirected.
497
-	if ($command_line)
498
-		upgradeExit(true);
524
+	if ($command_line) {
525
+			upgradeExit(true);
526
+	}
499 527
 
500 528
 	// Are we providing the core info?
501 529
 	if ($addForm)
@@ -521,12 +549,14 @@  discard block
 block discarded – undo
521 549
 	define('SMF', 1);
522 550
 
523 551
 	// Start the session.
524
-	if (@ini_get('session.save_handler') == 'user')
525
-		@ini_set('session.save_handler', 'files');
552
+	if (@ini_get('session.save_handler') == 'user') {
553
+			@ini_set('session.save_handler', 'files');
554
+	}
526 555
 	@session_start();
527 556
 
528
-	if (empty($smcFunc))
529
-		$smcFunc = array();
557
+	if (empty($smcFunc)) {
558
+			$smcFunc = array();
559
+	}
530 560
 
531 561
 	// We need this for authentication and some upgrade code
532 562
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -553,24 +583,27 @@  discard block
 block discarded – undo
553 583
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
554 584
 
555 585
 		// Make the connection...
556
-		if (empty($db_connection))
557
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
558
-		else
559
-			// If we've returned here, ping/reconnect to be safe
586
+		if (empty($db_connection)) {
587
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
588
+		} else {
589
+					// If we've returned here, ping/reconnect to be safe
560 590
 			$smcFunc['db_ping']($db_connection);
591
+		}
561 592
 
562 593
 		// Oh dear god!!
563
-		if ($db_connection === null)
564
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
594
+		if ($db_connection === null) {
595
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
596
+		}
565 597
 
566
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
567
-			$smcFunc['db_query']('', '
598
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
599
+					$smcFunc['db_query']('', '
568 600
 			SET NAMES {string:db_character_set}',
569 601
 			array(
570 602
 				'db_error_skip' => true,
571 603
 				'db_character_set' => $db_character_set,
572 604
 			)
573 605
 		);
606
+		}
574 607
 
575 608
 		// Load the modSettings data...
576 609
 		$request = $smcFunc['db_query']('', '
@@ -581,11 +614,11 @@  discard block
 block discarded – undo
581 614
 			)
582 615
 		);
583 616
 		$modSettings = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$modSettings[$row['variable']] = $row['value'];
617
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
618
+					$modSettings[$row['variable']] = $row['value'];
619
+		}
586 620
 		$smcFunc['db_free_result']($request);
587
-	}
588
-	else
621
+	} else
589 622
 	{
590 623
 		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.');
591 624
 	}
@@ -599,9 +632,10 @@  discard block
 block discarded – undo
599 632
 		cleanRequest();
600 633
 	}
601 634
 
602
-	if (!isset($_GET['substep']))
603
-		$_GET['substep'] = 0;
604
-}
635
+	if (!isset($_GET['substep'])) {
636
+			$_GET['substep'] = 0;
637
+	}
638
+	}
605 639
 
606 640
 function initialize_inputs()
607 641
 {
@@ -631,8 +665,9 @@  discard block
 block discarded – undo
631 665
 		$dh = opendir(dirname(__FILE__));
632 666
 		while ($file = readdir($dh))
633 667
 		{
634
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
635
-				@unlink(dirname(__FILE__) . '/' . $file);
668
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
669
+							@unlink(dirname(__FILE__) . '/' . $file);
670
+			}
636 671
 		}
637 672
 		closedir($dh);
638 673
 
@@ -661,8 +696,9 @@  discard block
 block discarded – undo
661 696
 	$temp = 'upgrade_php?step';
662 697
 	while (strlen($temp) > 4)
663 698
 	{
664
-		if (isset($_GET[$temp]))
665
-			unset($_GET[$temp]);
699
+		if (isset($_GET[$temp])) {
700
+					unset($_GET[$temp]);
701
+		}
666 702
 		$temp = substr($temp, 1);
667 703
 	}
668 704
 
@@ -689,32 +725,39 @@  discard block
 block discarded – undo
689 725
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
690 726
 
691 727
 	// Need legacy scripts?
692
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
693
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
694
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
695
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
696
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
697
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
728
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
729
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
730
+	}
731
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
732
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
733
+	}
734
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
735
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
736
+	}
698 737
 
699 738
 	// We don't need "-utf8" files anymore...
700 739
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
701 740
 
702 741
 	// This needs to exist!
703
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
704
-		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>]');
705
-	else
706
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
742
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
743
+			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>]');
744
+	} else {
745
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
746
+	}
707 747
 
708
-	if (!$check)
709
-		// 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.
748
+	if (!$check) {
749
+			// 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.
710 750
 		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.');
751
+	}
711 752
 
712 753
 	// Do they meet the install requirements?
713
-	if (!php_version_check())
714
-		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.');
754
+	if (!php_version_check()) {
755
+			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.');
756
+	}
715 757
 
716
-	if (!db_version_check())
717
-		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.');
758
+	if (!db_version_check()) {
759
+			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.');
760
+	}
718 761
 
719 762
 	// Do some checks to make sure they have proper privileges
720 763
 	db_extend('packages');
@@ -729,14 +772,16 @@  discard block
 block discarded – undo
729 772
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
730 773
 
731 774
 	// Sorry... we need CREATE, ALTER and DROP
732
-	if (!$create || !$alter || !$drop)
733
-		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.');
775
+	if (!$create || !$alter || !$drop) {
776
+			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.');
777
+	}
734 778
 
735 779
 	// Do a quick version spot check.
736 780
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
737 781
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
738
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
739
-		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.');
782
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
783
+			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.');
784
+	}
740 785
 
741 786
 	// What absolutely needs to be writable?
742 787
 	$writable_files = array(
@@ -745,12 +790,13 @@  discard block
 block discarded – undo
745 790
 	);
746 791
 
747 792
 	// Only check for minified writable files if we have it enabled or not set.
748
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
749
-		$writable_files += array(
793
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
794
+			$writable_files += array(
750 795
 			$modSettings['theme_dir'] . '/css/minified.css',
751 796
 			$modSettings['theme_dir'] . '/scripts/minified.js',
752 797
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
753 798
 		);
799
+	}
754 800
 
755 801
 	// Do we need to add this setting?
756 802
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -762,12 +808,13 @@  discard block
 block discarded – undo
762 808
 	quickFileWritable($custom_av_dir);
763 809
 
764 810
 	// Are we good now?
765
-	if (!is_writable($custom_av_dir))
766
-		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));
767
-	elseif ($need_settings_update)
811
+	if (!is_writable($custom_av_dir)) {
812
+			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));
813
+	} elseif ($need_settings_update)
768 814
 	{
769
-		if (!function_exists('cache_put_data'))
770
-			require_once($sourcedir . '/Load.php');
815
+		if (!function_exists('cache_put_data')) {
816
+					require_once($sourcedir . '/Load.php');
817
+		}
771 818
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
772 819
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
773 820
 	}
@@ -776,28 +823,33 @@  discard block
 block discarded – undo
776 823
 
777 824
 	// Check the cache directory.
778 825
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
779
-	if (!file_exists($cachedir_temp))
780
-		@mkdir($cachedir_temp);
781
-	if (!file_exists($cachedir_temp))
782
-		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.');
783
-
784
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
785
-		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>.');
786
-	elseif (!isset($_GET['skiplang']))
826
+	if (!file_exists($cachedir_temp)) {
827
+			@mkdir($cachedir_temp);
828
+	}
829
+	if (!file_exists($cachedir_temp)) {
830
+			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.');
831
+	}
832
+
833
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
834
+			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>.');
835
+	} elseif (!isset($_GET['skiplang']))
787 836
 	{
788 837
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
789 838
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
790 839
 
791
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
792
-			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>]');
840
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
841
+					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>]');
842
+		}
793 843
 	}
794 844
 
795
-	if (!makeFilesWritable($writable_files))
796
-		return false;
845
+	if (!makeFilesWritable($writable_files)) {
846
+			return false;
847
+	}
797 848
 
798 849
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
799
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
800
-		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.');
850
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
851
+			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.');
852
+	}
801 853
 
802 854
 	// Upgrade the agreement.
803 855
 	elseif (isset($modSettings['agreement']))
@@ -808,8 +860,8 @@  discard block
 block discarded – undo
808 860
 	}
809 861
 
810 862
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
811
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
812
-		$upcontext['warning'] = '
863
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
864
+			$upcontext['warning'] = '
813 865
 			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>
814 866
 			<ul>
815 867
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -817,19 +869,23 @@  discard block
 block discarded – undo
817 869
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
818 870
 			</ul>
819 871
 			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.';
872
+	}
820 873
 
821 874
 	// Confirm mbstring is loaded...
822
-	if (!extension_loaded('mbstring'))
823
-		return throw_error($txt['install_no_mbstring']);
875
+	if (!extension_loaded('mbstring')) {
876
+			return throw_error($txt['install_no_mbstring']);
877
+	}
824 878
 
825 879
 	// Check for https stream support.
826 880
 	$supported_streams = stream_get_wrappers();
827
-	if (!in_array('https', $supported_streams))
828
-		$upcontext['custom_warning'] = $txt['install_no_https'];
881
+	if (!in_array('https', $supported_streams)) {
882
+			$upcontext['custom_warning'] = $txt['install_no_https'];
883
+	}
829 884
 
830 885
 	// Either we're logged in or we're going to present the login.
831
-	if (checkLogin())
832
-		return true;
886
+	if (checkLogin()) {
887
+			return true;
888
+	}
833 889
 
834 890
 	$upcontext += createToken('login');
835 891
 
@@ -843,15 +899,17 @@  discard block
 block discarded – undo
843 899
 	global $smcFunc, $db_type, $support_js;
844 900
 
845 901
 	// Don't bother if the security is disabled.
846
-	if ($disable_security)
847
-		return true;
902
+	if ($disable_security) {
903
+			return true;
904
+	}
848 905
 
849 906
 	// Are we trying to login?
850 907
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
851 908
 	{
852 909
 		// If we've disabled security pick a suitable name!
853
-		if (empty($_POST['user']))
854
-			$_POST['user'] = 'Administrator';
910
+		if (empty($_POST['user'])) {
911
+					$_POST['user'] = 'Administrator';
912
+		}
855 913
 
856 914
 		// Before 2.0 these column names were different!
857 915
 		$oldDB = false;
@@ -866,16 +924,17 @@  discard block
 block discarded – undo
866 924
 					'db_error_skip' => true,
867 925
 				)
868 926
 			);
869
-			if ($smcFunc['db_num_rows']($request) != 0)
870
-				$oldDB = true;
927
+			if ($smcFunc['db_num_rows']($request) != 0) {
928
+							$oldDB = true;
929
+			}
871 930
 			$smcFunc['db_free_result']($request);
872 931
 		}
873 932
 
874 933
 		// Get what we believe to be their details.
875 934
 		if (!$disable_security)
876 935
 		{
877
-			if ($oldDB)
878
-				$request = $smcFunc['db_query']('', '
936
+			if ($oldDB) {
937
+							$request = $smcFunc['db_query']('', '
879 938
 					SELECT id_member, memberName AS member_name, passwd, id_group,
880 939
 					additionalGroups AS additional_groups, lngfile
881 940
 					FROM {db_prefix}members
@@ -885,8 +944,8 @@  discard block
 block discarded – undo
885 944
 						'db_error_skip' => true,
886 945
 					)
887 946
 				);
888
-			else
889
-				$request = $smcFunc['db_query']('', '
947
+			} else {
948
+							$request = $smcFunc['db_query']('', '
890 949
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
891 950
 					FROM {db_prefix}members
892 951
 					WHERE member_name = {string:member_name}',
@@ -895,6 +954,7 @@  discard block
 block discarded – undo
895 954
 						'db_error_skip' => true,
896 955
 					)
897 956
 				);
957
+			}
898 958
 			if ($smcFunc['db_num_rows']($request) != 0)
899 959
 			{
900 960
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -902,16 +962,17 @@  discard block
 block discarded – undo
902 962
 				$groups = explode(',', $addGroups);
903 963
 				$groups[] = $id_group;
904 964
 
905
-				foreach ($groups as $k => $v)
906
-					$groups[$k] = (int) $v;
965
+				foreach ($groups as $k => $v) {
966
+									$groups[$k] = (int) $v;
967
+				}
907 968
 
908 969
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
909 970
 
910 971
 				// We don't use "-utf8" anymore...
911 972
 				$user_language = str_ireplace('-utf8', '', $user_language);
973
+			} else {
974
+							$upcontext['username_incorrect'] = true;
912 975
 			}
913
-			else
914
-				$upcontext['username_incorrect'] = true;
915 976
 			$smcFunc['db_free_result']($request);
916 977
 		}
917 978
 		$upcontext['username'] = $_POST['user'];
@@ -921,13 +982,14 @@  discard block
 block discarded – undo
921 982
 		{
922 983
 			$upcontext['upgrade_status']['js'] = 1;
923 984
 			$support_js = 1;
985
+		} else {
986
+					$support_js = 0;
924 987
 		}
925
-		else
926
-			$support_js = 0;
927 988
 
928 989
 		// Note down the version we are coming from.
929
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
930
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
990
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
991
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
992
+		}
931 993
 
932 994
 		// Didn't get anywhere?
933 995
 		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']))
@@ -961,15 +1023,15 @@  discard block
 block discarded – undo
961 1023
 							'db_error_skip' => true,
962 1024
 						)
963 1025
 					);
964
-					if ($smcFunc['db_num_rows']($request) == 0)
965
-						return throw_error('You need to be an admin to perform an upgrade!');
1026
+					if ($smcFunc['db_num_rows']($request) == 0) {
1027
+											return throw_error('You need to be an admin to perform an upgrade!');
1028
+					}
966 1029
 					$smcFunc['db_free_result']($request);
967 1030
 				}
968 1031
 
969 1032
 				$upcontext['user']['id'] = $id_member;
970 1033
 				$upcontext['user']['name'] = $name;
971
-			}
972
-			else
1034
+			} else
973 1035
 			{
974 1036
 				$upcontext['user']['id'] = 1;
975 1037
 				$upcontext['user']['name'] = 'Administrator';
@@ -985,11 +1047,11 @@  discard block
 block discarded – undo
985 1047
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
986 1048
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
987 1049
 
988
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
989
-					$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'] . '.';
990
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
991
-					$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'] . '.';
992
-				else
1050
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1051
+									$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'] . '.';
1052
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1053
+									$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'] . '.';
1054
+				} else
993 1055
 				{
994 1056
 					// Set this as the new language.
995 1057
 					$upcontext['language'] = $user_language;
@@ -1033,8 +1095,9 @@  discard block
 block discarded – undo
1033 1095
 	unset($member_columns);
1034 1096
 
1035 1097
 	// If we've not submitted then we're done.
1036
-	if (empty($_POST['upcont']))
1037
-		return false;
1098
+	if (empty($_POST['upcont'])) {
1099
+			return false;
1100
+	}
1038 1101
 
1039 1102
 	// Firstly, if they're enabling SM stat collection just do it.
1040 1103
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1054,16 +1117,17 @@  discard block
 block discarded – undo
1054 1117
 				fwrite($fp, $out);
1055 1118
 
1056 1119
 				$return_data = '';
1057
-				while (!feof($fp))
1058
-					$return_data .= fgets($fp, 128);
1120
+				while (!feof($fp)) {
1121
+									$return_data .= fgets($fp, 128);
1122
+				}
1059 1123
 
1060 1124
 				fclose($fp);
1061 1125
 
1062 1126
 				// Get the unique site ID.
1063 1127
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1064 1128
 
1065
-				if (!empty($ID[1]))
1066
-					$smcFunc['db_insert']('replace',
1129
+				if (!empty($ID[1])) {
1130
+									$smcFunc['db_insert']('replace',
1067 1131
 						$db_prefix . 'settings',
1068 1132
 						array('variable' => 'string', 'value' => 'string'),
1069 1133
 						array(
@@ -1072,9 +1136,9 @@  discard block
 block discarded – undo
1072 1136
 						),
1073 1137
 						array('variable')
1074 1138
 					);
1139
+				}
1075 1140
 			}
1076
-		}
1077
-		else
1141
+		} else
1078 1142
 		{
1079 1143
 			$smcFunc['db_insert']('replace',
1080 1144
 				$db_prefix . 'settings',
@@ -1085,8 +1149,8 @@  discard block
 block discarded – undo
1085 1149
 		}
1086 1150
 	}
1087 1151
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1088
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1089
-		$smcFunc['db_query']('', '
1152
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1153
+			$smcFunc['db_query']('', '
1090 1154
 			DELETE FROM {db_prefix}settings
1091 1155
 			WHERE variable = {string:enable_sm_stats}',
1092 1156
 			array(
@@ -1094,6 +1158,7 @@  discard block
 block discarded – undo
1094 1158
 				'db_error_skip' => true,
1095 1159
 			)
1096 1160
 		);
1161
+	}
1097 1162
 
1098 1163
 	// Deleting old karma stuff?
1099 1164
 	if (!empty($_POST['delete_karma']))
@@ -1108,20 +1173,22 @@  discard block
 block discarded – undo
1108 1173
 		);
1109 1174
 
1110 1175
 		// Cleaning up old karma member settings.
1111
-		if ($upcontext['karma_installed']['good'])
1112
-			$smcFunc['db_query']('', '
1176
+		if ($upcontext['karma_installed']['good']) {
1177
+					$smcFunc['db_query']('', '
1113 1178
 				ALTER TABLE {db_prefix}members
1114 1179
 				DROP karma_good',
1115 1180
 				array()
1116 1181
 			);
1182
+		}
1117 1183
 
1118 1184
 		// Does karma bad was enable?
1119
-		if ($upcontext['karma_installed']['bad'])
1120
-			$smcFunc['db_query']('', '
1185
+		if ($upcontext['karma_installed']['bad']) {
1186
+					$smcFunc['db_query']('', '
1121 1187
 				ALTER TABLE {db_prefix}members
1122 1188
 				DROP karma_bad',
1123 1189
 				array()
1124 1190
 			);
1191
+		}
1125 1192
 
1126 1193
 		// Cleaning up old karma permissions.
1127 1194
 		$smcFunc['db_query']('', '
@@ -1139,32 +1206,37 @@  discard block
 block discarded – undo
1139 1206
 	}
1140 1207
 
1141 1208
 	// Emptying the error log?
1142
-	if (!empty($_POST['empty_error']))
1143
-		$smcFunc['db_query']('truncate_table', '
1209
+	if (!empty($_POST['empty_error'])) {
1210
+			$smcFunc['db_query']('truncate_table', '
1144 1211
 			TRUNCATE {db_prefix}log_errors',
1145 1212
 			array(
1146 1213
 			)
1147 1214
 		);
1215
+	}
1148 1216
 
1149 1217
 	$changes = array();
1150 1218
 
1151 1219
 	// Add proxy settings.
1152
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1153
-		$changes += array(
1220
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1221
+			$changes += array(
1154 1222
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1155 1223
 			'image_proxy_maxsize' => 5190,
1156 1224
 			'image_proxy_enabled' => 0,
1157 1225
 		);
1226
+	}
1158 1227
 
1159 1228
 	// If $boardurl reflects https, set force_ssl
1160
-	if (!function_exists('cache_put_data'))
1161
-		require_once($sourcedir . '/Load.php');
1162
-	if (stripos($boardurl, 'https://') !== false)
1163
-		updateSettings(array('force_ssl' => '1'));
1229
+	if (!function_exists('cache_put_data')) {
1230
+			require_once($sourcedir . '/Load.php');
1231
+	}
1232
+	if (stripos($boardurl, 'https://') !== false) {
1233
+			updateSettings(array('force_ssl' => '1'));
1234
+	}
1164 1235
 
1165 1236
 	// If we're overriding the language follow it through.
1166
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1167
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1237
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1238
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1239
+	}
1168 1240
 
1169 1241
 	if (!empty($_POST['maint']))
1170 1242
 	{
@@ -1176,26 +1248,29 @@  discard block
 block discarded – undo
1176 1248
 		{
1177 1249
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1178 1250
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1179
-		}
1180
-		else
1251
+		} else
1181 1252
 		{
1182 1253
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1183 1254
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1184 1255
 		}
1185 1256
 	}
1186 1257
 
1187
-	if ($command_line)
1188
-		echo ' * Updating Settings.php...';
1258
+	if ($command_line) {
1259
+			echo ' * Updating Settings.php...';
1260
+	}
1189 1261
 
1190 1262
 	// Fix some old paths.
1191
-	if (substr($boarddir, 0, 1) == '.')
1192
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1263
+	if (substr($boarddir, 0, 1) == '.') {
1264
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1265
+	}
1193 1266
 
1194
-	if (substr($sourcedir, 0, 1) == '.')
1195
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1267
+	if (substr($sourcedir, 0, 1) == '.') {
1268
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1269
+	}
1196 1270
 
1197
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1198
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1271
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1272
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1273
+	}
1199 1274
 
1200 1275
 	// If they have a "host:port" setup for the host, split that into separate values
1201 1276
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1206,32 +1281,36 @@  discard block
 block discarded – undo
1206 1281
 		$changes['db_server'] = '\'' . $db_server . '\'';
1207 1282
 
1208 1283
 		// Only set this if we're not using the default port
1209
-		if ($db_port != ini_get('mysqli.default_port'))
1210
-			$changes['db_port'] = (int) $db_port;
1211
-	}
1212
-	elseif (!empty($db_port))
1284
+		if ($db_port != ini_get('mysqli.default_port')) {
1285
+					$changes['db_port'] = (int) $db_port;
1286
+		}
1287
+	} elseif (!empty($db_port))
1213 1288
 	{
1214 1289
 		// If db_port is set and is the same as the default, set it to ''
1215 1290
 		if ($db_type == 'mysql')
1216 1291
 		{
1217
-			if ($db_port == ini_get('mysqli.default_port'))
1218
-				$changes['db_port'] = '\'\'';
1219
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1220
-				$changes['db_port'] = '\'\'';
1292
+			if ($db_port == ini_get('mysqli.default_port')) {
1293
+							$changes['db_port'] = '\'\'';
1294
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1295
+							$changes['db_port'] = '\'\'';
1296
+			}
1221 1297
 		}
1222 1298
 	}
1223 1299
 
1224 1300
 	// Maybe we haven't had this option yet?
1225
-	if (empty($packagesdir))
1226
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1301
+	if (empty($packagesdir)) {
1302
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1303
+	}
1227 1304
 
1228 1305
 	// Add support for $tasksdir var.
1229
-	if (empty($tasksdir))
1230
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1306
+	if (empty($tasksdir)) {
1307
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1308
+	}
1231 1309
 
1232 1310
 	// Make sure we fix the language as well.
1233
-	if (stristr($language, '-utf8'))
1234
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1311
+	if (stristr($language, '-utf8')) {
1312
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1313
+	}
1235 1314
 
1236 1315
 	// @todo Maybe change the cookie name if going to 1.1, too?
1237 1316
 
@@ -1242,8 +1321,9 @@  discard block
 block discarded – undo
1242 1321
 	// Tell Settings.php to store db_last_error.php in the cache
1243 1322
 	move_db_last_error_to_cachedir();
1244 1323
 
1245
-	if ($command_line)
1246
-		echo ' Successful.' . "\n";
1324
+	if ($command_line) {
1325
+			echo ' Successful.' . "\n";
1326
+	}
1247 1327
 
1248 1328
 	// Are we doing debug?
1249 1329
 	if (isset($_POST['debug']))
@@ -1253,8 +1333,9 @@  discard block
 block discarded – undo
1253 1333
 	}
1254 1334
 
1255 1335
 	// If we're not backing up then jump one.
1256
-	if (empty($_POST['backup']))
1257
-		$upcontext['current_step']++;
1336
+	if (empty($_POST['backup'])) {
1337
+			$upcontext['current_step']++;
1338
+	}
1258 1339
 
1259 1340
 	// If we've got here then let's proceed to the next step!
1260 1341
 	return true;
@@ -1269,8 +1350,9 @@  discard block
 block discarded – undo
1269 1350
 	$upcontext['page_title'] = $txt['backup_database'];
1270 1351
 
1271 1352
 	// Done it already - js wise?
1272
-	if (!empty($_POST['backup_done']))
1273
-		return true;
1353
+	if (!empty($_POST['backup_done'])) {
1354
+			return true;
1355
+	}
1274 1356
 
1275 1357
 	// Some useful stuff here.
1276 1358
 	db_extend();
@@ -1284,9 +1366,10 @@  discard block
 block discarded – undo
1284 1366
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1285 1367
 
1286 1368
 	$table_names = array();
1287
-	foreach ($tables as $table)
1288
-		if (substr($table, 0, 7) !== 'backup_')
1369
+	foreach ($tables as $table) {
1370
+			if (substr($table, 0, 7) !== 'backup_')
1289 1371
 			$table_names[] = $table;
1372
+	}
1290 1373
 
1291 1374
 	$upcontext['table_count'] = count($table_names);
1292 1375
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1296,12 +1379,14 @@  discard block
 block discarded – undo
1296 1379
 	$file_steps = $upcontext['table_count'];
1297 1380
 
1298 1381
 	// What ones have we already done?
1299
-	foreach ($table_names as $id => $table)
1300
-		if ($id < $_GET['substep'])
1382
+	foreach ($table_names as $id => $table) {
1383
+			if ($id < $_GET['substep'])
1301 1384
 			$upcontext['previous_tables'][] = $table;
1385
+	}
1302 1386
 
1303
-	if ($command_line)
1304
-		echo 'Backing Up Tables.';
1387
+	if ($command_line) {
1388
+			echo 'Backing Up Tables.';
1389
+	}
1305 1390
 
1306 1391
 	// If we don't support javascript we backup here.
1307 1392
 	if (!$support_js || isset($_GET['xml']))
@@ -1320,8 +1405,9 @@  discard block
 block discarded – undo
1320 1405
 			backupTable($table_names[$substep]);
1321 1406
 
1322 1407
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1323
-			if (isset($_GET['xml']))
1324
-				return upgradeExit();
1408
+			if (isset($_GET['xml'])) {
1409
+							return upgradeExit();
1410
+			}
1325 1411
 		}
1326 1412
 
1327 1413
 		if ($command_line)
@@ -1354,9 +1440,10 @@  discard block
 block discarded – undo
1354 1440
 
1355 1441
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1356 1442
 
1357
-	if ($command_line)
1358
-		echo ' done.';
1359
-}
1443
+	if ($command_line) {
1444
+			echo ' done.';
1445
+	}
1446
+	}
1360 1447
 
1361 1448
 // Step 2: Everything.
1362 1449
 function DatabaseChanges()
@@ -1365,8 +1452,9 @@  discard block
 block discarded – undo
1365 1452
 	global $upcontext, $support_js, $db_type;
1366 1453
 
1367 1454
 	// Have we just completed this?
1368
-	if (!empty($_POST['database_done']))
1369
-		return true;
1455
+	if (!empty($_POST['database_done'])) {
1456
+			return true;
1457
+	}
1370 1458
 
1371 1459
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1372 1460
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1381,15 +1469,16 @@  discard block
 block discarded – undo
1381 1469
 	);
1382 1470
 
1383 1471
 	// How many files are there in total?
1384
-	if (isset($_GET['filecount']))
1385
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1386
-	else
1472
+	if (isset($_GET['filecount'])) {
1473
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1474
+	} else
1387 1475
 	{
1388 1476
 		$upcontext['file_count'] = 0;
1389 1477
 		foreach ($files as $file)
1390 1478
 		{
1391
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1392
-				$upcontext['file_count']++;
1479
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1480
+							$upcontext['file_count']++;
1481
+			}
1393 1482
 		}
1394 1483
 	}
1395 1484
 
@@ -1399,9 +1488,9 @@  discard block
 block discarded – undo
1399 1488
 	$upcontext['cur_file_num'] = 0;
1400 1489
 	foreach ($files as $file)
1401 1490
 	{
1402
-		if ($did_not_do)
1403
-			$did_not_do--;
1404
-		else
1491
+		if ($did_not_do) {
1492
+					$did_not_do--;
1493
+		} else
1405 1494
 		{
1406 1495
 			$upcontext['cur_file_num']++;
1407 1496
 			$upcontext['cur_file_name'] = $file[0];
@@ -1428,12 +1517,13 @@  discard block
 block discarded – undo
1428 1517
 					// Flag to move on to the next.
1429 1518
 					$upcontext['completed_step'] = true;
1430 1519
 					// Did we complete the whole file?
1431
-					if ($nextFile)
1432
-						$upcontext['current_debug_item_num'] = -1;
1520
+					if ($nextFile) {
1521
+											$upcontext['current_debug_item_num'] = -1;
1522
+					}
1433 1523
 					return upgradeExit();
1524
+				} elseif ($support_js) {
1525
+									break;
1434 1526
 				}
1435
-				elseif ($support_js)
1436
-					break;
1437 1527
 			}
1438 1528
 			// Set the progress bar to be right as if we had - even if we hadn't...
1439 1529
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1459,8 +1549,9 @@  discard block
 block discarded – undo
1459 1549
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt;
1460 1550
 
1461 1551
 	// Now it's nice to have some of the basic SMF source files.
1462
-	if (!isset($_GET['ssi']) && !$command_line)
1463
-		redirectLocation('&ssi=1');
1552
+	if (!isset($_GET['ssi']) && !$command_line) {
1553
+			redirectLocation('&ssi=1');
1554
+	}
1464 1555
 
1465 1556
 	$upcontext['sub_template'] = 'upgrade_complete';
1466 1557
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1476,14 +1567,16 @@  discard block
 block discarded – undo
1476 1567
 	// Are we in maintenance mode?
1477 1568
 	if (isset($upcontext['user']['main']))
1478 1569
 	{
1479
-		if ($command_line)
1480
-			echo ' * ';
1570
+		if ($command_line) {
1571
+					echo ' * ';
1572
+		}
1481 1573
 		$upcontext['removed_maintenance'] = true;
1482 1574
 		$changes['maintenance'] = $upcontext['user']['main'];
1483 1575
 	}
1484 1576
 	// Otherwise if somehow we are in 2 let's go to 1.
1485
-	elseif (!empty($maintenance) && $maintenance == 2)
1486
-		$changes['maintenance'] = 1;
1577
+	elseif (!empty($maintenance) && $maintenance == 2) {
1578
+			$changes['maintenance'] = 1;
1579
+	}
1487 1580
 
1488 1581
 	// Wipe this out...
1489 1582
 	$upcontext['user'] = array();
@@ -1498,9 +1591,9 @@  discard block
 block discarded – undo
1498 1591
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1499 1592
 
1500 1593
 	// Now is the perfect time to fetch the SM files.
1501
-	if ($command_line)
1502
-		cli_scheduled_fetchSMfiles();
1503
-	else
1594
+	if ($command_line) {
1595
+			cli_scheduled_fetchSMfiles();
1596
+	} else
1504 1597
 	{
1505 1598
 		require_once($sourcedir . '/ScheduledTasks.php');
1506 1599
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1508,8 +1601,9 @@  discard block
 block discarded – undo
1508 1601
 	}
1509 1602
 
1510 1603
 	// Log what we've done.
1511
-	if (empty($user_info['id']))
1512
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1604
+	if (empty($user_info['id'])) {
1605
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1606
+	}
1513 1607
 
1514 1608
 	// Log the action manually, so CLI still works.
1515 1609
 	$smcFunc['db_insert']('',
@@ -1528,8 +1622,9 @@  discard block
 block discarded – undo
1528 1622
 
1529 1623
 	// Save the current database version.
1530 1624
 	$server_version = $smcFunc['db_server_info']();
1531
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1532
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1625
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1626
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1627
+	}
1533 1628
 
1534 1629
 	if ($command_line)
1535 1630
 	{
@@ -1541,8 +1636,9 @@  discard block
 block discarded – undo
1541 1636
 
1542 1637
 	// Make sure it says we're done.
1543 1638
 	$upcontext['overall_percent'] = 100;
1544
-	if (isset($upcontext['step_progress']))
1545
-		unset($upcontext['step_progress']);
1639
+	if (isset($upcontext['step_progress'])) {
1640
+			unset($upcontext['step_progress']);
1641
+	}
1546 1642
 
1547 1643
 	$_GET['substep'] = 0;
1548 1644
 	return false;
@@ -1553,8 +1649,9 @@  discard block
 block discarded – undo
1553 1649
 {
1554 1650
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1555 1651
 
1556
-	if (empty($modSettings['time_format']))
1557
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1652
+	if (empty($modSettings['time_format'])) {
1653
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1654
+	}
1558 1655
 
1559 1656
 	// What files do we want to get
1560 1657
 	$request = $smcFunc['db_query']('', '
@@ -1588,8 +1685,9 @@  discard block
 block discarded – undo
1588 1685
 		$file_data = fetch_web_data($url);
1589 1686
 
1590 1687
 		// If we got an error - give up - the site might be down.
1591
-		if ($file_data === false)
1592
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1688
+		if ($file_data === false) {
1689
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1690
+		}
1593 1691
 
1594 1692
 		// Save the file to the database.
1595 1693
 		$smcFunc['db_query']('substring', '
@@ -1631,8 +1729,9 @@  discard block
 block discarded – undo
1631 1729
 	$themeData = array();
1632 1730
 	foreach ($values as $variable => $value)
1633 1731
 	{
1634
-		if (!isset($value) || $value === null)
1635
-			$value = 0;
1732
+		if (!isset($value) || $value === null) {
1733
+					$value = 0;
1734
+		}
1636 1735
 
1637 1736
 		$themeData[] = array(0, 1, $variable, $value);
1638 1737
 	}
@@ -1661,8 +1760,9 @@  discard block
 block discarded – undo
1661 1760
 
1662 1761
 	foreach ($values as $variable => $value)
1663 1762
 	{
1664
-		if (empty($modSettings[$value[0]]))
1665
-			continue;
1763
+		if (empty($modSettings[$value[0]])) {
1764
+					continue;
1765
+		}
1666 1766
 
1667 1767
 		$smcFunc['db_query']('', '
1668 1768
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1748,19 +1848,21 @@  discard block
 block discarded – undo
1748 1848
 	set_error_handler(
1749 1849
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1750 1850
 		{
1751
-			if ($support_js)
1752
-				return true;
1753
-			else
1754
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1851
+			if ($support_js) {
1852
+							return true;
1853
+			} else {
1854
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1855
+			}
1755 1856
 		}
1756 1857
 	);
1757 1858
 
1758 1859
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1759 1860
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1760
-	if ($db_type == 'mysql')
1761
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1762
-	else
1763
-		$db_collation = '';
1861
+	if ($db_type == 'mysql') {
1862
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1863
+	} else {
1864
+			$db_collation = '';
1865
+	}
1764 1866
 
1765 1867
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1766 1868
 
@@ -1772,8 +1874,9 @@  discard block
 block discarded – undo
1772 1874
 	$last_step = '';
1773 1875
 
1774 1876
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1775
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1776
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1877
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1878
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1879
+	}
1777 1880
 
1778 1881
 	// Count the total number of steps within this file - for progress.
1779 1882
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1793,15 +1896,18 @@  discard block
 block discarded – undo
1793 1896
 		$do_current = $substep >= $_GET['substep'];
1794 1897
 
1795 1898
 		// Get rid of any comments in the beginning of the line...
1796
-		if (substr(trim($line), 0, 2) === '/*')
1797
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1899
+		if (substr(trim($line), 0, 2) === '/*') {
1900
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1901
+		}
1798 1902
 
1799 1903
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1800
-		if ($is_debug && !$support_js && $command_line)
1801
-			flush();
1904
+		if ($is_debug && !$support_js && $command_line) {
1905
+					flush();
1906
+		}
1802 1907
 
1803
-		if (trim($line) === '')
1804
-			continue;
1908
+		if (trim($line) === '') {
1909
+					continue;
1910
+		}
1805 1911
 
1806 1912
 		if (trim(substr($line, 0, 3)) === '---')
1807 1913
 		{
@@ -1811,8 +1917,9 @@  discard block
 block discarded – undo
1811 1917
 			if (trim($current_data) != '' && $type !== '}')
1812 1918
 			{
1813 1919
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1814
-				if ($command_line)
1815
-					echo $upcontext['error_message'];
1920
+				if ($command_line) {
1921
+									echo $upcontext['error_message'];
1922
+				}
1816 1923
 			}
1817 1924
 
1818 1925
 			if ($type == ' ')
@@ -1830,17 +1937,18 @@  discard block
 block discarded – undo
1830 1937
 				if ($do_current)
1831 1938
 				{
1832 1939
 					$upcontext['actioned_items'][] = $last_step;
1833
-					if ($command_line)
1834
-						echo ' * ';
1940
+					if ($command_line) {
1941
+											echo ' * ';
1942
+					}
1835 1943
 				}
1836
-			}
1837
-			elseif ($type == '#')
1944
+			} elseif ($type == '#')
1838 1945
 			{
1839 1946
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1840 1947
 
1841 1948
 				$upcontext['current_debug_item_num']++;
1842
-				if (trim($line) != '---#')
1843
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1949
+				if (trim($line) != '---#') {
1950
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1951
+				}
1844 1952
 
1845 1953
 				// Have we already done something?
1846 1954
 				if (isset($_GET['xml']) && $done_something)
@@ -1851,34 +1959,36 @@  discard block
 block discarded – undo
1851 1959
 
1852 1960
 				if ($do_current)
1853 1961
 				{
1854
-					if (trim($line) == '---#' && $command_line)
1855
-						echo ' done.', $endl;
1856
-					elseif ($command_line)
1857
-						echo ' +++ ', rtrim(substr($line, 4));
1858
-					elseif (trim($line) != '---#')
1962
+					if (trim($line) == '---#' && $command_line) {
1963
+											echo ' done.', $endl;
1964
+					} elseif ($command_line) {
1965
+											echo ' +++ ', rtrim(substr($line, 4));
1966
+					} elseif (trim($line) != '---#')
1859 1967
 					{
1860
-						if ($is_debug)
1861
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1968
+						if ($is_debug) {
1969
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1970
+						}
1862 1971
 					}
1863 1972
 				}
1864 1973
 
1865 1974
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1866 1975
 				{
1867
-					if ($command_line)
1868
-						echo ' * ';
1869
-					else
1870
-						$upcontext['actioned_items'][] = $last_step;
1976
+					if ($command_line) {
1977
+											echo ' * ';
1978
+					} else {
1979
+											$upcontext['actioned_items'][] = $last_step;
1980
+					}
1871 1981
 				}
1872 1982
 
1873 1983
 				// Small step - only if we're actually doing stuff.
1874
-				if ($do_current)
1875
-					nextSubstep(++$substep);
1876
-				else
1877
-					$substep++;
1878
-			}
1879
-			elseif ($type == '{')
1880
-				$current_type = 'code';
1881
-			elseif ($type == '}')
1984
+				if ($do_current) {
1985
+									nextSubstep(++$substep);
1986
+				} else {
1987
+									$substep++;
1988
+				}
1989
+			} elseif ($type == '{') {
1990
+							$current_type = 'code';
1991
+			} elseif ($type == '}')
1882 1992
 			{
1883 1993
 				$current_type = 'sql';
1884 1994
 
@@ -1891,8 +2001,9 @@  discard block
 block discarded – undo
1891 2001
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1892 2002
 				{
1893 2003
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1894
-					if ($command_line)
1895
-						echo $upcontext['error_message'];
2004
+					if ($command_line) {
2005
+											echo $upcontext['error_message'];
2006
+					}
1896 2007
 				}
1897 2008
 
1898 2009
 				// Done with code!
@@ -1972,8 +2083,9 @@  discard block
 block discarded – undo
1972 2083
 	$db_unbuffered = false;
1973 2084
 
1974 2085
 	// Failure?!
1975
-	if ($result !== false)
1976
-		return $result;
2086
+	if ($result !== false) {
2087
+			return $result;
2088
+	}
1977 2089
 
1978 2090
 	$db_error_message = $smcFunc['db_error']($db_connection);
1979 2091
 	// If MySQL we do something more clever.
@@ -2001,54 +2113,61 @@  discard block
 block discarded – undo
2001 2113
 			{
2002 2114
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2003 2115
 				$result = mysqli_query($db_connection, $string);
2004
-				if ($result !== false)
2005
-					return $result;
2116
+				if ($result !== false) {
2117
+									return $result;
2118
+				}
2006 2119
 			}
2007
-		}
2008
-		elseif ($mysqli_errno == 2013)
2120
+		} elseif ($mysqli_errno == 2013)
2009 2121
 		{
2010 2122
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2011 2123
 			mysqli_select_db($db_connection, $db_name);
2012 2124
 			if ($db_connection)
2013 2125
 			{
2014 2126
 				$result = mysqli_query($db_connection, $string);
2015
-				if ($result !== false)
2016
-					return $result;
2127
+				if ($result !== false) {
2128
+									return $result;
2129
+				}
2017 2130
 			}
2018 2131
 		}
2019 2132
 		// Duplicate column name... should be okay ;).
2020
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2021
-			return false;
2133
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2134
+					return false;
2135
+		}
2022 2136
 		// Duplicate insert... make sure it's the proper type of query ;).
2023
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2024
-			return false;
2137
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2138
+					return false;
2139
+		}
2025 2140
 		// Creating an index on a non-existent column.
2026
-		elseif ($mysqli_errno == 1072)
2027
-			return false;
2028
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2029
-			return false;
2141
+		elseif ($mysqli_errno == 1072) {
2142
+					return false;
2143
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2144
+					return false;
2145
+		}
2030 2146
 	}
2031 2147
 	// If a table already exists don't go potty.
2032 2148
 	else
2033 2149
 	{
2034 2150
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2035 2151
 		{
2036
-			if (strpos($db_error_message, 'exist') !== false)
2037
-				return true;
2038
-		}
2039
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2152
+			if (strpos($db_error_message, 'exist') !== false) {
2153
+							return true;
2154
+			}
2155
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2040 2156
 		{
2041
-			if (strpos($db_error_message, 'duplicate') !== false)
2042
-				return true;
2157
+			if (strpos($db_error_message, 'duplicate') !== false) {
2158
+							return true;
2159
+			}
2043 2160
 		}
2044 2161
 	}
2045 2162
 
2046 2163
 	// Get the query string so we pass everything.
2047 2164
 	$query_string = '';
2048
-	foreach ($_GET as $k => $v)
2049
-		$query_string .= ';' . $k . '=' . $v;
2050
-	if (strlen($query_string) != 0)
2051
-		$query_string = '?' . substr($query_string, 1);
2165
+	foreach ($_GET as $k => $v) {
2166
+			$query_string .= ';' . $k . '=' . $v;
2167
+	}
2168
+	if (strlen($query_string) != 0) {
2169
+			$query_string = '?' . substr($query_string, 1);
2170
+	}
2052 2171
 
2053 2172
 	if ($command_line)
2054 2173
 	{
@@ -2103,16 +2222,18 @@  discard block
 block discarded – undo
2103 2222
 			{
2104 2223
 				$found |= 1;
2105 2224
 				// Do some checks on the data if we have it set.
2106
-				if (isset($change['col_type']))
2107
-					$found &= $change['col_type'] === $column['type'];
2108
-				if (isset($change['null_allowed']))
2109
-					$found &= $column['null'] == $change['null_allowed'];
2110
-				if (isset($change['default']))
2111
-					$found &= $change['default'] === $column['default'];
2225
+				if (isset($change['col_type'])) {
2226
+									$found &= $change['col_type'] === $column['type'];
2227
+				}
2228
+				if (isset($change['null_allowed'])) {
2229
+									$found &= $column['null'] == $change['null_allowed'];
2230
+				}
2231
+				if (isset($change['default'])) {
2232
+									$found &= $change['default'] === $column['default'];
2233
+				}
2112 2234
 			}
2113 2235
 		}
2114
-	}
2115
-	elseif ($change['type'] === 'index')
2236
+	} elseif ($change['type'] === 'index')
2116 2237
 	{
2117 2238
 		$request = upgrade_query('
2118 2239
 			SHOW INDEX
@@ -2121,9 +2242,10 @@  discard block
 block discarded – undo
2121 2242
 		{
2122 2243
 			$cur_index = array();
2123 2244
 
2124
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2125
-				if ($row['Key_name'] === $change['name'])
2245
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2246
+							if ($row['Key_name'] === $change['name'])
2126 2247
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2248
+			}
2127 2249
 
2128 2250
 			ksort($cur_index, SORT_NUMERIC);
2129 2251
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2133,14 +2255,17 @@  discard block
 block discarded – undo
2133 2255
 	}
2134 2256
 
2135 2257
 	// If we're trying to add and it's added, we're done.
2136
-	if ($found && in_array($change['method'], array('add', 'change')))
2137
-		return true;
2258
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2259
+			return true;
2260
+	}
2138 2261
 	// Otherwise if we're removing and it wasn't found we're also done.
2139
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2140
-		return true;
2262
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2263
+			return true;
2264
+	}
2141 2265
 	// Otherwise is it just a test?
2142
-	elseif ($is_test)
2143
-		return false;
2266
+	elseif ($is_test) {
2267
+			return false;
2268
+	}
2144 2269
 
2145 2270
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2146 2271
 	$running = false;
@@ -2151,8 +2276,9 @@  discard block
 block discarded – undo
2151 2276
 			SHOW FULL PROCESSLIST');
2152 2277
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2153 2278
 		{
2154
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2155
-				$found = true;
2279
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2280
+							$found = true;
2281
+			}
2156 2282
 		}
2157 2283
 
2158 2284
 		// Can't find it? Then we need to run it fools!
@@ -2164,8 +2290,9 @@  discard block
 block discarded – undo
2164 2290
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2165 2291
 				' . $change['text'], true) !== false;
2166 2292
 
2167
-			if (!$success)
2168
-				return false;
2293
+			if (!$success) {
2294
+							return false;
2295
+			}
2169 2296
 
2170 2297
 			// Return
2171 2298
 			$running = true;
@@ -2207,8 +2334,9 @@  discard block
 block discarded – undo
2207 2334
 			'db_error_skip' => true,
2208 2335
 		)
2209 2336
 	);
2210
-	if ($smcFunc['db_num_rows']($request) === 0)
2211
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2337
+	if ($smcFunc['db_num_rows']($request) === 0) {
2338
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2339
+	}
2212 2340
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2213 2341
 	$smcFunc['db_free_result']($request);
2214 2342
 
@@ -2230,18 +2358,19 @@  discard block
 block discarded – undo
2230 2358
 			)
2231 2359
 		);
2232 2360
 		// No results? Just forget it all together.
2233
-		if ($smcFunc['db_num_rows']($request) === 0)
2234
-			unset($table_row['Collation']);
2235
-		else
2236
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2361
+		if ($smcFunc['db_num_rows']($request) === 0) {
2362
+					unset($table_row['Collation']);
2363
+		} else {
2364
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2365
+		}
2237 2366
 		$smcFunc['db_free_result']($request);
2238 2367
 	}
2239 2368
 
2240 2369
 	if ($column_fix)
2241 2370
 	{
2242 2371
 		// Make sure there are no NULL's left.
2243
-		if ($null_fix)
2244
-			$smcFunc['db_query']('', '
2372
+		if ($null_fix) {
2373
+					$smcFunc['db_query']('', '
2245 2374
 				UPDATE {db_prefix}' . $change['table'] . '
2246 2375
 				SET ' . $change['column'] . ' = {string:default}
2247 2376
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2250,6 +2379,7 @@  discard block
 block discarded – undo
2250 2379
 					'db_error_skip' => true,
2251 2380
 				)
2252 2381
 			);
2382
+		}
2253 2383
 
2254 2384
 		// Do the actual alteration.
2255 2385
 		$smcFunc['db_query']('', '
@@ -2278,8 +2408,9 @@  discard block
 block discarded – undo
2278 2408
 	}
2279 2409
 
2280 2410
 	// Not a column we need to check on?
2281
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2282
-		return;
2411
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2412
+			return;
2413
+	}
2283 2414
 
2284 2415
 	// Break it up you (six|seven).
2285 2416
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2298,13 +2429,13 @@  discard block
 block discarded – undo
2298 2429
 				'new_name' => $temp[2],
2299 2430
 		));
2300 2431
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2301
-		if ($smcFunc['db_num_rows'] != 1)
2302
-			return;
2432
+		if ($smcFunc['db_num_rows'] != 1) {
2433
+					return;
2434
+		}
2303 2435
 
2304 2436
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2305 2437
 		$smcFunc['db_free_result']($request);
2306
-	}
2307
-	else
2438
+	} else
2308 2439
 	{
2309 2440
 		// Do this the old fashion, sure method way.
2310 2441
 		$request = $smcFunc['db_query']('', '
@@ -2315,21 +2446,24 @@  discard block
 block discarded – undo
2315 2446
 		));
2316 2447
 		// Mayday!
2317 2448
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2318
-		if ($smcFunc['db_num_rows'] == 0)
2319
-			return;
2449
+		if ($smcFunc['db_num_rows'] == 0) {
2450
+					return;
2451
+		}
2320 2452
 
2321 2453
 		// Oh where, oh where has my little field gone. Oh where can it be...
2322
-		while ($row = $smcFunc['db_query']($request))
2323
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2454
+		while ($row = $smcFunc['db_query']($request)) {
2455
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2324 2456
 			{
2325 2457
 				$current_type = $row['Type'];
2458
+		}
2326 2459
 				break;
2327 2460
 			}
2328 2461
 	}
2329 2462
 
2330 2463
 	// If this doesn't match, the column may of been altered for a reason.
2331
-	if (trim($current_type) != trim($temp[3]))
2332
-		$temp[3] = $current_type;
2464
+	if (trim($current_type) != trim($temp[3])) {
2465
+			$temp[3] = $current_type;
2466
+	}
2333 2467
 
2334 2468
 	// Piece this back together.
2335 2469
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2341,8 +2475,9 @@  discard block
 block discarded – undo
2341 2475
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2342 2476
 	global $step_progress, $is_debug, $upcontext;
2343 2477
 
2344
-	if ($_GET['substep'] < $substep)
2345
-		$_GET['substep'] = $substep;
2478
+	if ($_GET['substep'] < $substep) {
2479
+			$_GET['substep'] = $substep;
2480
+	}
2346 2481
 
2347 2482
 	if ($command_line)
2348 2483
 	{
@@ -2355,29 +2490,33 @@  discard block
 block discarded – undo
2355 2490
 	}
2356 2491
 
2357 2492
 	@set_time_limit(300);
2358
-	if (function_exists('apache_reset_timeout'))
2359
-		@apache_reset_timeout();
2493
+	if (function_exists('apache_reset_timeout')) {
2494
+			@apache_reset_timeout();
2495
+	}
2360 2496
 
2361
-	if (time() - $start_time <= $timeLimitThreshold)
2362
-		return;
2497
+	if (time() - $start_time <= $timeLimitThreshold) {
2498
+			return;
2499
+	}
2363 2500
 
2364 2501
 	// Do we have some custom step progress stuff?
2365 2502
 	if (!empty($step_progress))
2366 2503
 	{
2367 2504
 		$upcontext['substep_progress'] = 0;
2368 2505
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2369
-		if ($step_progress['current'] > $step_progress['total'])
2370
-			$upcontext['substep_progress'] = 99.9;
2371
-		else
2372
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2506
+		if ($step_progress['current'] > $step_progress['total']) {
2507
+					$upcontext['substep_progress'] = 99.9;
2508
+		} else {
2509
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2510
+		}
2373 2511
 
2374 2512
 		// Make it nicely rounded.
2375 2513
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2376 2514
 	}
2377 2515
 
2378 2516
 	// If this is XML we just exit right away!
2379
-	if (isset($_GET['xml']))
2380
-		return upgradeExit();
2517
+	if (isset($_GET['xml'])) {
2518
+			return upgradeExit();
2519
+	}
2381 2520
 
2382 2521
 	// We're going to pause after this!
2383 2522
 	$upcontext['pause'] = true;
@@ -2385,13 +2524,15 @@  discard block
 block discarded – undo
2385 2524
 	$upcontext['query_string'] = '';
2386 2525
 	foreach ($_GET as $k => $v)
2387 2526
 	{
2388
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2389
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2527
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2528
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2529
+		}
2390 2530
 	}
2391 2531
 
2392 2532
 	// Custom warning?
2393
-	if (!empty($custom_warning))
2394
-		$upcontext['custom_warning'] = $custom_warning;
2533
+	if (!empty($custom_warning)) {
2534
+			$upcontext['custom_warning'] = $custom_warning;
2535
+	}
2395 2536
 
2396 2537
 	upgradeExit();
2397 2538
 }
@@ -2406,25 +2547,26 @@  discard block
 block discarded – undo
2406 2547
 	ob_implicit_flush(true);
2407 2548
 	@set_time_limit(600);
2408 2549
 
2409
-	if (!isset($_SERVER['argv']))
2410
-		$_SERVER['argv'] = array();
2550
+	if (!isset($_SERVER['argv'])) {
2551
+			$_SERVER['argv'] = array();
2552
+	}
2411 2553
 	$_GET['maint'] = 1;
2412 2554
 
2413 2555
 	foreach ($_SERVER['argv'] as $i => $arg)
2414 2556
 	{
2415
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2416
-			$_GET['lang'] = $match[1];
2417
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2418
-			continue;
2419
-		elseif ($arg == '--no-maintenance')
2420
-			$_GET['maint'] = 0;
2421
-		elseif ($arg == '--debug')
2422
-			$is_debug = true;
2423
-		elseif ($arg == '--backup')
2424
-			$_POST['backup'] = 1;
2425
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2426
-			$_GET['conv'] = 1;
2427
-		elseif ($i != 0)
2557
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2558
+					$_GET['lang'] = $match[1];
2559
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2560
+					continue;
2561
+		} elseif ($arg == '--no-maintenance') {
2562
+					$_GET['maint'] = 0;
2563
+		} elseif ($arg == '--debug') {
2564
+					$is_debug = true;
2565
+		} elseif ($arg == '--backup') {
2566
+					$_POST['backup'] = 1;
2567
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2568
+					$_GET['conv'] = 1;
2569
+		} elseif ($i != 0)
2428 2570
 		{
2429 2571
 			echo 'SMF Command-line Upgrader
2430 2572
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2438,10 +2580,12 @@  discard block
 block discarded – undo
2438 2580
 		}
2439 2581
 	}
2440 2582
 
2441
-	if (!php_version_check())
2442
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2443
-	if (!db_version_check())
2444
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2583
+	if (!php_version_check()) {
2584
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2585
+	}
2586
+	if (!db_version_check()) {
2587
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2588
+	}
2445 2589
 
2446 2590
 	// Do some checks to make sure they have proper privileges
2447 2591
 	db_extend('packages');
@@ -2456,34 +2600,39 @@  discard block
 block discarded – undo
2456 2600
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2457 2601
 
2458 2602
 	// Sorry... we need CREATE, ALTER and DROP
2459
-	if (!$create || !$alter || !$drop)
2460
-		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);
2603
+	if (!$create || !$alter || !$drop) {
2604
+			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);
2605
+	}
2461 2606
 
2462 2607
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2463 2608
 		&& @file_exists($sourcedir . '/QueryString.php')
2464 2609
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2465
-	if (!$check && !isset($modSettings['smfVersion']))
2466
-		print_error('Error: Some files are missing or out-of-date.', true);
2610
+	if (!$check && !isset($modSettings['smfVersion'])) {
2611
+			print_error('Error: Some files are missing or out-of-date.', true);
2612
+	}
2467 2613
 
2468 2614
 	// Do a quick version spot check.
2469 2615
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2470 2616
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2471
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2472
-		print_error('Error: Some files have not yet been updated properly.');
2617
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2618
+			print_error('Error: Some files have not yet been updated properly.');
2619
+	}
2473 2620
 
2474 2621
 	// Make sure Settings.php is writable.
2475 2622
 	quickFileWritable($boarddir . '/Settings.php');
2476
-	if (!is_writable($boarddir . '/Settings.php'))
2477
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2623
+	if (!is_writable($boarddir . '/Settings.php')) {
2624
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2625
+	}
2478 2626
 
2479 2627
 	// Make sure Settings_bak.php is writable.
2480 2628
 	quickFileWritable($boarddir . '/Settings_bak.php');
2481
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2482
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2629
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2630
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2631
+	}
2483 2632
 
2484
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2485
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2486
-	elseif (isset($modSettings['agreement']))
2633
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2634
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2635
+	} elseif (isset($modSettings['agreement']))
2487 2636
 	{
2488 2637
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2489 2638
 		fwrite($fp, $modSettings['agreement']);
@@ -2493,36 +2642,42 @@  discard block
 block discarded – undo
2493 2642
 	// Make sure Themes is writable.
2494 2643
 	quickFileWritable($modSettings['theme_dir']);
2495 2644
 
2496
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2497
-		print_error('Error: Unable to obtain write access to "Themes".');
2645
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2646
+			print_error('Error: Unable to obtain write access to "Themes".');
2647
+	}
2498 2648
 
2499 2649
 	// Make sure cache directory exists and is writable!
2500 2650
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2501
-	if (!file_exists($cachedir_temp))
2502
-		@mkdir($cachedir_temp);
2651
+	if (!file_exists($cachedir_temp)) {
2652
+			@mkdir($cachedir_temp);
2653
+	}
2503 2654
 
2504 2655
 	// Make sure the cache temp dir is writable.
2505 2656
 	quickFileWritable($cachedir_temp);
2506 2657
 
2507
-	if (!is_writable($cachedir_temp))
2508
-		print_error('Error: Unable to obtain write access to "cache".', true);
2658
+	if (!is_writable($cachedir_temp)) {
2659
+			print_error('Error: Unable to obtain write access to "cache".', true);
2660
+	}
2509 2661
 
2510 2662
 	// Make sure db_last_error.php is writable.
2511 2663
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2512
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2513
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2664
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2665
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2666
+	}
2514 2667
 
2515
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2516
-		print_error('Error: Unable to find language files!', true);
2517
-	else
2668
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2669
+			print_error('Error: Unable to find language files!', true);
2670
+	} else
2518 2671
 	{
2519 2672
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2520 2673
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2521 2674
 
2522
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2523
-			print_error('Error: Language files out of date.', true);
2524
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2525
-			print_error('Error: Install language is missing for selected language.', true);
2675
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2676
+					print_error('Error: Language files out of date.', true);
2677
+		}
2678
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2679
+					print_error('Error: Install language is missing for selected language.', true);
2680
+		}
2526 2681
 
2527 2682
 		// Otherwise include it!
2528 2683
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2542,8 +2697,9 @@  discard block
 block discarded – undo
2542 2697
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2543 2698
 
2544 2699
 	// Done it already?
2545
-	if (!empty($_POST['utf8_done']))
2546
-		return true;
2700
+	if (!empty($_POST['utf8_done'])) {
2701
+			return true;
2702
+	}
2547 2703
 
2548 2704
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2549 2705
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2556,8 +2712,7 @@  discard block
 block discarded – undo
2556 2712
 		);
2557 2713
 
2558 2714
 		return true;
2559
-	}
2560
-	else
2715
+	} else
2561 2716
 	{
2562 2717
 		$upcontext['page_title'] = $txt['converting_utf8'];
2563 2718
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2601,8 +2756,9 @@  discard block
 block discarded – undo
2601 2756
 			)
2602 2757
 		);
2603 2758
 		$db_charsets = array();
2604
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2605
-			$db_charsets[] = $row['Charset'];
2759
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2760
+					$db_charsets[] = $row['Charset'];
2761
+		}
2606 2762
 
2607 2763
 		$smcFunc['db_free_result']($request);
2608 2764
 
@@ -2638,13 +2794,15 @@  discard block
 block discarded – undo
2638 2794
 		// If there's a fulltext index, we need to drop it first...
2639 2795
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2640 2796
 		{
2641
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2642
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2797
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2798
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2643 2799
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2800
+			}
2644 2801
 			$smcFunc['db_free_result']($request);
2645 2802
 
2646
-			if (isset($upcontext['fulltext_index']))
2647
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2803
+			if (isset($upcontext['fulltext_index'])) {
2804
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2805
+			}
2648 2806
 		}
2649 2807
 
2650 2808
 		// Drop it and make a note...
@@ -2834,8 +2992,9 @@  discard block
 block discarded – undo
2834 2992
 			$replace = '%field%';
2835 2993
 
2836 2994
 			// Build a huge REPLACE statement...
2837
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2838
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2995
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2996
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2997
+			}
2839 2998
 		}
2840 2999
 
2841 3000
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2845,9 +3004,10 @@  discard block
 block discarded – undo
2845 3004
 		$upcontext['table_count'] = count($queryTables);
2846 3005
 
2847 3006
 		// What ones have we already done?
2848
-		foreach ($queryTables as $id => $table)
2849
-			if ($id < $_GET['substep'])
3007
+		foreach ($queryTables as $id => $table) {
3008
+					if ($id < $_GET['substep'])
2850 3009
 				$upcontext['previous_tables'][] = $table;
3010
+		}
2851 3011
 
2852 3012
 		$upcontext['cur_table_num'] = $_GET['substep'];
2853 3013
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2884,8 +3044,9 @@  discard block
 block discarded – undo
2884 3044
 			nextSubstep($substep);
2885 3045
 
2886 3046
 			// Just to make sure it doesn't time out.
2887
-			if (function_exists('apache_reset_timeout'))
2888
-				@apache_reset_timeout();
3047
+			if (function_exists('apache_reset_timeout')) {
3048
+							@apache_reset_timeout();
3049
+			}
2889 3050
 
2890 3051
 			$table_charsets = array();
2891 3052
 
@@ -2908,8 +3069,9 @@  discard block
 block discarded – undo
2908 3069
 
2909 3070
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2910 3071
 						if ($charset != 'utf8') {
2911
-							if (!isset($table_charsets[$charset]))
2912
-								$table_charsets[$charset] = array();
3072
+							if (!isset($table_charsets[$charset])) {
3073
+															$table_charsets[$charset] = array();
3074
+							}
2913 3075
 
2914 3076
 							$table_charsets[$charset][] = $column_info;
2915 3077
 						}
@@ -2950,10 +3112,11 @@  discard block
 block discarded – undo
2950 3112
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2951 3113
 				{
2952 3114
 					$update = '';
2953
-					foreach ($table_charsets as $charset => $columns)
2954
-						foreach ($columns as $column)
3115
+					foreach ($table_charsets as $charset => $columns) {
3116
+											foreach ($columns as $column)
2955 3117
 							$update .= '
2956 3118
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3119
+					}
2957 3120
 
2958 3121
 					$smcFunc['db_query']('', '
2959 3122
 						UPDATE {raw:table_name}
@@ -2978,8 +3141,9 @@  discard block
 block discarded – undo
2978 3141
 			// Now do the actual conversion (if still needed).
2979 3142
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2980 3143
 			{
2981
-				if ($command_line)
2982
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3144
+				if ($command_line) {
3145
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3146
+				}
2983 3147
 
2984 3148
 				$smcFunc['db_query']('', '
2985 3149
 					ALTER TABLE {raw:table_name}
@@ -2989,12 +3153,14 @@  discard block
 block discarded – undo
2989 3153
 					)
2990 3154
 				);
2991 3155
 
2992
-				if ($command_line)
2993
-					echo " done.\n";
3156
+				if ($command_line) {
3157
+									echo " done.\n";
3158
+				}
2994 3159
 			}
2995 3160
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2996
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2997
-				return upgradeExit();
3161
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3162
+							return upgradeExit();
3163
+			}
2998 3164
 		}
2999 3165
 
3000 3166
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3023,8 +3189,8 @@  discard block
 block discarded – undo
3023 3189
 		);
3024 3190
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3025 3191
 		{
3026
-			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)
3027
-				$smcFunc['db_query']('', '
3192
+			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) {
3193
+							$smcFunc['db_query']('', '
3028 3194
 					UPDATE {db_prefix}log_actions
3029 3195
 					SET extra = {string:extra}
3030 3196
 					WHERE id_action = {int:current_action}',
@@ -3033,6 +3199,7 @@  discard block
 block discarded – undo
3033 3199
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3034 3200
 					)
3035 3201
 				);
3202
+			}
3036 3203
 		}
3037 3204
 		$smcFunc['db_free_result']($request);
3038 3205
 
@@ -3054,15 +3221,17 @@  discard block
 block discarded – undo
3054 3221
 	// First thing's first - did we already do this?
3055 3222
 	if (!empty($modSettings['json_done']))
3056 3223
 	{
3057
-		if ($command_line)
3058
-			return DeleteUpgrade();
3059
-		else
3060
-			return true;
3224
+		if ($command_line) {
3225
+					return DeleteUpgrade();
3226
+		} else {
3227
+					return true;
3228
+		}
3061 3229
 	}
3062 3230
 
3063 3231
 	// Done it already - js wise?
3064
-	if (!empty($_POST['json_done']))
3065
-		return true;
3232
+	if (!empty($_POST['json_done'])) {
3233
+			return true;
3234
+	}
3066 3235
 
3067 3236
 	// List of tables affected by this function
3068 3237
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3094,12 +3263,14 @@  discard block
 block discarded – undo
3094 3263
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3095 3264
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3096 3265
 
3097
-	foreach ($keys as $id => $table)
3098
-		if ($id < $_GET['substep'])
3266
+	foreach ($keys as $id => $table) {
3267
+			if ($id < $_GET['substep'])
3099 3268
 			$upcontext['previous_tables'][] = $table;
3269
+	}
3100 3270
 
3101
-	if ($command_line)
3102
-		echo 'Converting data from serialize() to json_encode().';
3271
+	if ($command_line) {
3272
+			echo 'Converting data from serialize() to json_encode().';
3273
+	}
3103 3274
 
3104 3275
 	if (!$support_js || isset($_GET['xml']))
3105 3276
 	{
@@ -3139,8 +3310,9 @@  discard block
 block discarded – undo
3139 3310
 
3140 3311
 				// Loop through and fix these...
3141 3312
 				$new_settings = array();
3142
-				if ($command_line)
3143
-					echo "\n" . 'Fixing some settings...';
3313
+				if ($command_line) {
3314
+									echo "\n" . 'Fixing some settings...';
3315
+				}
3144 3316
 
3145 3317
 				foreach ($serialized_settings as $var)
3146 3318
 				{
@@ -3148,22 +3320,24 @@  discard block
 block discarded – undo
3148 3320
 					{
3149 3321
 						// Attempt to unserialize the setting
3150 3322
 						$temp = @safe_unserialize($modSettings[$var]);
3151
-						if (!$temp && $command_line)
3152
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3153
-						elseif ($temp !== false)
3154
-							$new_settings[$var] = json_encode($temp);
3323
+						if (!$temp && $command_line) {
3324
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3325
+						} elseif ($temp !== false) {
3326
+													$new_settings[$var] = json_encode($temp);
3327
+						}
3155 3328
 					}
3156 3329
 				}
3157 3330
 
3158 3331
 				// Update everything at once
3159
-				if (!function_exists('cache_put_data'))
3160
-					require_once($sourcedir . '/Load.php');
3332
+				if (!function_exists('cache_put_data')) {
3333
+									require_once($sourcedir . '/Load.php');
3334
+				}
3161 3335
 				updateSettings($new_settings, true);
3162 3336
 
3163
-				if ($command_line)
3164
-					echo ' done.';
3165
-			}
3166
-			elseif ($table == 'themes')
3337
+				if ($command_line) {
3338
+									echo ' done.';
3339
+				}
3340
+			} elseif ($table == 'themes')
3167 3341
 			{
3168 3342
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3169 3343
 				$query = $smcFunc['db_query']('', '
@@ -3182,10 +3356,11 @@  discard block
 block discarded – undo
3182 3356
 
3183 3357
 						if ($command_line)
3184 3358
 						{
3185
-							if ($temp === false)
3186
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3187
-							else
3188
-								echo "\n" . 'Fixing admin preferences...';
3359
+							if ($temp === false) {
3360
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3361
+							} else {
3362
+															echo "\n" . 'Fixing admin preferences...';
3363
+							}
3189 3364
 						}
3190 3365
 
3191 3366
 						if ($temp !== false)
@@ -3207,15 +3382,15 @@  discard block
 block discarded – undo
3207 3382
 								)
3208 3383
 							);
3209 3384
 
3210
-							if ($command_line)
3211
-								echo ' done.';
3385
+							if ($command_line) {
3386
+															echo ' done.';
3387
+							}
3212 3388
 						}
3213 3389
 					}
3214 3390
 
3215 3391
 					$smcFunc['db_free_result']($query);
3216 3392
 				}
3217
-			}
3218
-			else
3393
+			} else
3219 3394
 			{
3220 3395
 				// First item is always the key...
3221 3396
 				$key = $info[0];
@@ -3226,8 +3401,7 @@  discard block
 block discarded – undo
3226 3401
 				{
3227 3402
 					$col_select = $info[1];
3228 3403
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3229
-				}
3230
-				else
3404
+				} else
3231 3405
 				{
3232 3406
 					$col_select = implode(', ', $info);
3233 3407
 				}
@@ -3260,8 +3434,7 @@  discard block
 block discarded – undo
3260 3434
 								if ($temp === false && $command_line)
3261 3435
 								{
3262 3436
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3263
-								}
3264
-								else
3437
+								} else
3265 3438
 								{
3266 3439
 									$row[$col] = json_encode($temp);
3267 3440
 
@@ -3286,16 +3459,18 @@  discard block
 block discarded – undo
3286 3459
 						}
3287 3460
 					}
3288 3461
 
3289
-					if ($command_line)
3290
-						echo ' done.';
3462
+					if ($command_line) {
3463
+											echo ' done.';
3464
+					}
3291 3465
 
3292 3466
 					// Free up some memory...
3293 3467
 					$smcFunc['db_free_result']($query);
3294 3468
 				}
3295 3469
 			}
3296 3470
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3297
-			if (isset($_GET['xml']))
3298
-				return upgradeExit();
3471
+			if (isset($_GET['xml'])) {
3472
+							return upgradeExit();
3473
+			}
3299 3474
 		}
3300 3475
 
3301 3476
 		if ($command_line)
@@ -3310,8 +3485,9 @@  discard block
 block discarded – undo
3310 3485
 
3311 3486
 		$_GET['substep'] = 0;
3312 3487
 		// Make sure we move on!
3313
-		if ($command_line)
3314
-			return DeleteUpgrade();
3488
+		if ($command_line) {
3489
+					return DeleteUpgrade();
3490
+		}
3315 3491
 
3316 3492
 		return true;
3317 3493
 	}
@@ -3368,14 +3544,16 @@  discard block
 block discarded – undo
3368 3544
 	global $upcontext, $txt, $settings;
3369 3545
 
3370 3546
 	// Don't call me twice!
3371
-	if (!empty($upcontext['chmod_called']))
3372
-		return;
3547
+	if (!empty($upcontext['chmod_called'])) {
3548
+			return;
3549
+	}
3373 3550
 
3374 3551
 	$upcontext['chmod_called'] = true;
3375 3552
 
3376 3553
 	// Nothing?
3377
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3378
-		return;
3554
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3555
+			return;
3556
+	}
3379 3557
 
3380 3558
 	// Was it a problem with Windows?
3381 3559
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3407,11 +3585,12 @@  discard block
 block discarded – undo
3407 3585
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3408 3586
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3409 3587
 
3410
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3411
-		echo '
3588
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3589
+			echo '
3412 3590
 					content.write(\'<hr>\n\t\t\t\');
3413 3591
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3414 3592
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3593
+	}
3415 3594
 
3416 3595
 	echo '
3417 3596
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3419,17 +3598,19 @@  discard block
 block discarded – undo
3419 3598
 				}
3420 3599
 			</script>';
3421 3600
 
3422
-	if (!empty($upcontext['chmod']['ftp_error']))
3423
-		echo '
3601
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3602
+			echo '
3424 3603
 			<div class="error_message red">
3425 3604
 				', $txt['upgrade_ftp_error'], '<br><br>
3426 3605
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3427 3606
 			</div>
3428 3607
 			<br>';
3608
+	}
3429 3609
 
3430
-	if (empty($upcontext['chmod_in_form']))
3431
-		echo '
3610
+	if (empty($upcontext['chmod_in_form'])) {
3611
+			echo '
3432 3612
 	<form action="', $upcontext['form_url'], '" method="post">';
3613
+	}
3433 3614
 
3434 3615
 	echo '
3435 3616
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3464,10 +3645,11 @@  discard block
 block discarded – undo
3464 3645
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3465 3646
 	</div>';
3466 3647
 
3467
-	if (empty($upcontext['chmod_in_form']))
3468
-		echo '
3648
+	if (empty($upcontext['chmod_in_form'])) {
3649
+			echo '
3469 3650
 	</form>';
3470
-}
3651
+	}
3652
+	}
3471 3653
 
3472 3654
 function template_upgrade_above()
3473 3655
 {
@@ -3527,9 +3709,10 @@  discard block
 block discarded – undo
3527 3709
 				<h2>', $txt['upgrade_progress'], '</h2>
3528 3710
 				<ul>';
3529 3711
 
3530
-	foreach ($upcontext['steps'] as $num => $step)
3531
-		echo '
3712
+	foreach ($upcontext['steps'] as $num => $step) {
3713
+			echo '
3532 3714
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3715
+	}
3533 3716
 
3534 3717
 	echo '
3535 3718
 					</ul>
@@ -3542,8 +3725,8 @@  discard block
 block discarded – undo
3542 3725
 				</div>
3543 3726
 			</div>';
3544 3727
 
3545
-	if (isset($upcontext['step_progress']))
3546
-		echo '
3728
+	if (isset($upcontext['step_progress'])) {
3729
+			echo '
3547 3730
 				<br>
3548 3731
 				<br>
3549 3732
 				<div id="progress_bar_step">
@@ -3552,6 +3735,7 @@  discard block
 block discarded – undo
3552 3735
 						<span>', $txt['upgrade_step_progress'], '</span>
3553 3736
 					</div>
3554 3737
 				</div>';
3738
+	}
3555 3739
 
3556 3740
 	echo '
3557 3741
 				<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>
@@ -3582,32 +3766,36 @@  discard block
 block discarded – undo
3582 3766
 {
3583 3767
 	global $upcontext, $txt;
3584 3768
 
3585
-	if (!empty($upcontext['pause']))
3586
-		echo '
3769
+	if (!empty($upcontext['pause'])) {
3770
+			echo '
3587 3771
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3588 3772
 
3589 3773
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3590 3774
 								<h3>
3591 3775
 									', $txt['upgrade_paused_overload'], '
3592 3776
 								</h3>';
3777
+	}
3593 3778
 
3594
-	if (!empty($upcontext['custom_warning']))
3595
-		echo '
3779
+	if (!empty($upcontext['custom_warning'])) {
3780
+			echo '
3596 3781
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3597 3782
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3598 3783
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3599 3784
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3600 3785
 								</div>';
3786
+	}
3601 3787
 
3602 3788
 	echo '
3603 3789
 								<div class="righttext" style="margin: 1ex;">';
3604 3790
 
3605
-	if (!empty($upcontext['continue']))
3606
-		echo '
3791
+	if (!empty($upcontext['continue'])) {
3792
+			echo '
3607 3793
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3608
-	if (!empty($upcontext['skip']))
3609
-		echo '
3794
+	}
3795
+	if (!empty($upcontext['skip'])) {
3796
+			echo '
3610 3797
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3798
+	}
3611 3799
 
3612 3800
 	echo '
3613 3801
 								</div>
@@ -3657,11 +3845,12 @@  discard block
 block discarded – undo
3657 3845
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3658 3846
 	<smf>';
3659 3847
 
3660
-	if (!empty($upcontext['get_data']))
3661
-		foreach ($upcontext['get_data'] as $k => $v)
3848
+	if (!empty($upcontext['get_data'])) {
3849
+			foreach ($upcontext['get_data'] as $k => $v)
3662 3850
 			echo '
3663 3851
 		<get key="', $k, '">', $v, '</get>';
3664
-}
3852
+	}
3853
+	}
3665 3854
 
3666 3855
 function template_xml_below()
3667 3856
 {
@@ -3702,8 +3891,8 @@  discard block
 block discarded – undo
3702 3891
 	template_chmod();
3703 3892
 
3704 3893
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3705
-	if ($upcontext['is_large_forum'])
3706
-		echo '
3894
+	if ($upcontext['is_large_forum']) {
3895
+			echo '
3707 3896
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3708 3897
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3709 3898
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3711,10 +3900,11 @@  discard block
 block discarded – undo
3711 3900
 				', $txt['upgrade_warning_lots_data'], '
3712 3901
 			</div>
3713 3902
 		</div>';
3903
+	}
3714 3904
 
3715 3905
 	// A warning message?
3716
-	if (!empty($upcontext['warning']))
3717
-		echo '
3906
+	if (!empty($upcontext['warning'])) {
3907
+			echo '
3718 3908
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3719 3909
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3720 3910
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3722,6 +3912,7 @@  discard block
 block discarded – undo
3722 3912
 				', $upcontext['warning'], '
3723 3913
 			</div>
3724 3914
 		</div>';
3915
+	}
3725 3916
 
3726 3917
 	// Paths are incorrect?
3727 3918
 	echo '
@@ -3737,20 +3928,22 @@  discard block
 block discarded – undo
3737 3928
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3738 3929
 	{
3739 3930
 		$ago = time() - $upcontext['started'];
3740
-		if ($ago < 60)
3741
-			$ago = $ago . ' seconds';
3742
-		elseif ($ago < 3600)
3743
-			$ago = (int) ($ago / 60) . ' minutes';
3744
-		else
3745
-			$ago = (int) ($ago / 3600) . ' hours';
3931
+		if ($ago < 60) {
3932
+					$ago = $ago . ' seconds';
3933
+		} elseif ($ago < 3600) {
3934
+					$ago = (int) ($ago / 60) . ' minutes';
3935
+		} else {
3936
+					$ago = (int) ($ago / 3600) . ' hours';
3937
+		}
3746 3938
 
3747 3939
 		$active = time() - $upcontext['updated'];
3748
-		if ($active < 60)
3749
-			$updated = $active . ' seconds';
3750
-		elseif ($active < 3600)
3751
-			$updated = (int) ($active / 60) . ' minutes';
3752
-		else
3753
-			$updated = (int) ($active / 3600) . ' hours';
3940
+		if ($active < 60) {
3941
+					$updated = $active . ' seconds';
3942
+		} elseif ($active < 3600) {
3943
+					$updated = (int) ($active / 60) . ' minutes';
3944
+		} else {
3945
+					$updated = (int) ($active / 3600) . ' hours';
3946
+		}
3754 3947
 
3755 3948
 		echo '
3756 3949
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3759,16 +3952,18 @@  discard block
 block discarded – undo
3759 3952
 			<div style="padding-left: 6ex;">
3760 3953
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3761 3954
 
3762
-		if ($active < 600)
3763
-			echo '
3955
+		if ($active < 600) {
3956
+					echo '
3764 3957
 				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '';
3958
+		}
3765 3959
 
3766
-		if ($active > $upcontext['inactive_timeout'])
3767
-			echo '
3960
+		if ($active > $upcontext['inactive_timeout']) {
3961
+					echo '
3768 3962
 				<br><br>',$txt['upgrade_run'], '';
3769
-		else
3770
-			echo '
3963
+		} else {
3964
+					echo '
3771 3965
 				<br><br>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3966
+		}
3772 3967
 
3773 3968
 		echo '
3774 3969
 			</div>
@@ -3784,9 +3979,10 @@  discard block
 block discarded – undo
3784 3979
 					<td>
3785 3980
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3786 3981
 
3787
-	if (!empty($upcontext['username_incorrect']))
3788
-		echo '
3982
+	if (!empty($upcontext['username_incorrect'])) {
3983
+			echo '
3789 3984
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>';
3985
+	}
3790 3986
 
3791 3987
 	echo '
3792 3988
 					</td>
@@ -3797,9 +3993,10 @@  discard block
 block discarded – undo
3797 3993
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3798 3994
 						<input type="hidden" name="hash_passwrd" value="">';
3799 3995
 
3800
-	if (!empty($upcontext['password_failed']))
3801
-		echo '
3996
+	if (!empty($upcontext['password_failed'])) {
3997
+			echo '
3802 3998
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>';
3999
+	}
3803 4000
 
3804 4001
 	echo '
3805 4002
 					</td>
@@ -3870,8 +4067,8 @@  discard block
 block discarded – undo
3870 4067
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3871 4068
 
3872 4069
 	// Warning message?
3873
-	if (!empty($upcontext['upgrade_options_warning']))
3874
-		echo '
4070
+	if (!empty($upcontext['upgrade_options_warning'])) {
4071
+			echo '
3875 4072
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3876 4073
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3877 4074
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3879,6 +4076,7 @@  discard block
 block discarded – undo
3879 4076
 				', $upcontext['upgrade_options_warning'], '
3880 4077
 			</div>
3881 4078
 		</div>';
4079
+	}
3882 4080
 
3883 4081
 	echo '
3884 4082
 				<table>
@@ -3921,8 +4119,8 @@  discard block
 block discarded – undo
3921 4119
 						</td>
3922 4120
 					</tr>';
3923 4121
 
3924
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3925
-		echo '
4122
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4123
+			echo '
3926 4124
 					<tr valign="top">
3927 4125
 						<td width="2%">
3928 4126
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3931,6 +4129,7 @@  discard block
 block discarded – undo
3931 4129
 							<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3932 4130
 						</td>
3933 4131
 					</tr>';
4132
+	}
3934 4133
 
3935 4134
 	echo '
3936 4135
 					<tr valign="top">
@@ -3968,10 +4167,11 @@  discard block
 block discarded – undo
3968 4167
 			</div>';
3969 4168
 
3970 4169
 	// Dont any tables so far?
3971
-	if (!empty($upcontext['previous_tables']))
3972
-		foreach ($upcontext['previous_tables'] as $table)
4170
+	if (!empty($upcontext['previous_tables'])) {
4171
+			foreach ($upcontext['previous_tables'] as $table)
3973 4172
 			echo '
3974 4173
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4174
+	}
3975 4175
 
3976 4176
 	echo '
3977 4177
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4008,12 +4208,13 @@  discard block
 block discarded – undo
4008 4208
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4009 4209
 
4010 4210
 		// If debug flood the screen.
4011
-		if ($is_debug)
4012
-			echo '
4211
+		if ($is_debug) {
4212
+					echo '
4013 4213
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4014 4214
 
4015 4215
 				if (document.getElementById(\'debug_section\').scrollHeight)
4016 4216
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4217
+		}
4017 4218
 
4018 4219
 		echo '
4019 4220
 				// Get the next update...
@@ -4046,8 +4247,9 @@  discard block
 block discarded – undo
4046 4247
 {
4047 4248
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4048 4249
 
4049
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4050
-		$is_debug = true;
4250
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4251
+			$is_debug = true;
4252
+	}
4051 4253
 
4052 4254
 	echo '
4053 4255
 		<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4062,8 +4264,9 @@  discard block
 block discarded – undo
4062 4264
 	{
4063 4265
 		foreach ($upcontext['actioned_items'] as $num => $item)
4064 4266
 		{
4065
-			if ($num != 0)
4066
-				echo ' Successful!';
4267
+			if ($num != 0) {
4268
+							echo ' Successful!';
4269
+			}
4067 4270
 			echo '<br>' . $item;
4068 4271
 		}
4069 4272
 		if (!empty($upcontext['changes_complete']))
@@ -4076,28 +4279,32 @@  discard block
 block discarded – undo
4076 4279
 				$seconds = intval($active % 60);
4077 4280
 
4078 4281
 				$totalTime = '';
4079
-				if ($hours > 0)
4080
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4081
-				if ($minutes > 0)
4082
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4083
-				if ($seconds > 0)
4084
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4282
+				if ($hours > 0) {
4283
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4284
+				}
4285
+				if ($minutes > 0) {
4286
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4287
+				}
4288
+				if ($seconds > 0) {
4289
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4290
+				}
4085 4291
 			}
4086 4292
 
4087
-			if ($is_debug && !empty($totalTime))
4088
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4089
-			else
4090
-				echo ' Successful!<br><br>';
4293
+			if ($is_debug && !empty($totalTime)) {
4294
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4295
+			} else {
4296
+							echo ' Successful!<br><br>';
4297
+			}
4091 4298
 
4092 4299
 			echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>';
4093 4300
 		}
4094
-	}
4095
-	else
4301
+	} else
4096 4302
 	{
4097 4303
 		// Tell them how many files we have in total.
4098
-		if ($upcontext['file_count'] > 1)
4099
-			echo '
4304
+		if ($upcontext['file_count'] > 1) {
4305
+					echo '
4100 4306
 		<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4307
+		}
4101 4308
 
4102 4309
 		echo '
4103 4310
 		<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>
@@ -4113,19 +4320,23 @@  discard block
 block discarded – undo
4113 4320
 				$seconds = intval($active % 60);
4114 4321
 
4115 4322
 				$totalTime = '';
4116
-				if ($hours > 0)
4117
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4118
-				if ($minutes > 0)
4119
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4120
-				if ($seconds > 0)
4121
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4323
+				if ($hours > 0) {
4324
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4325
+				}
4326
+				if ($minutes > 0) {
4327
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4328
+				}
4329
+				if ($seconds > 0) {
4330
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4331
+				}
4122 4332
 			}
4123 4333
 
4124 4334
 			echo '
4125 4335
 			<br><span id="upgradeCompleted">';
4126 4336
 
4127
-			if (!empty($totalTime))
4128
-				echo 'Completed in ', $totalTime, '<br>';
4337
+			if (!empty($totalTime)) {
4338
+							echo 'Completed in ', $totalTime, '<br>';
4339
+			}
4129 4340
 
4130 4341
 			echo '</span>
4131 4342
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4162,9 +4373,10 @@  discard block
 block discarded – undo
4162 4373
 			var getData = "";
4163 4374
 			var debugItems = ', $upcontext['debug_items'], ';';
4164 4375
 
4165
-		if ($is_debug)
4166
-			echo '
4376
+		if ($is_debug) {
4377
+					echo '
4167 4378
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4379
+		}
4168 4380
 
4169 4381
 		echo '
4170 4382
 			function getNextItem()
@@ -4204,9 +4416,10 @@  discard block
 block discarded – undo
4204 4416
 						document.getElementById("error_block").style.display = "";
4205 4417
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4206 4418
 
4207
-	if ($is_debug)
4208
-		echo '
4419
+	if ($is_debug) {
4420
+			echo '
4209 4421
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4422
+	}
4210 4423
 
4211 4424
 	echo '
4212 4425
 					}
@@ -4227,9 +4440,10 @@  discard block
 block discarded – undo
4227 4440
 						document.getElementById("error_block").style.display = "";
4228 4441
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4229 4442
 
4230
-	if ($is_debug)
4231
-		echo '
4443
+	if ($is_debug) {
4444
+			echo '
4232 4445
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4446
+	}
4233 4447
 
4234 4448
 	echo '
4235 4449
 					}
@@ -4288,8 +4502,8 @@  discard block
 block discarded – undo
4288 4502
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4289 4503
 				{';
4290 4504
 
4291
-		if ($is_debug)
4292
-			echo '
4505
+		if ($is_debug) {
4506
+					echo '
4293 4507
 					document.getElementById(\'debug_section\').style.display = "none";
4294 4508
 
4295 4509
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4307,6 +4521,7 @@  discard block
 block discarded – undo
4307 4521
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4308 4522
 
4309 4523
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4524
+		}
4310 4525
 
4311 4526
 		echo '
4312 4527
 
@@ -4314,9 +4529,10 @@  discard block
 block discarded – undo
4314 4529
 					document.getElementById(\'contbutt\').disabled = 0;
4315 4530
 					document.getElementById(\'database_done\').value = 1;';
4316 4531
 
4317
-		if ($upcontext['file_count'] > 1)
4318
-			echo '
4532
+		if ($upcontext['file_count'] > 1) {
4533
+					echo '
4319 4534
 					document.getElementById(\'info1\').style.display = "none";';
4535
+		}
4320 4536
 
4321 4537
 		echo '
4322 4538
 					document.getElementById(\'info2\').style.display = "none";
@@ -4329,9 +4545,10 @@  discard block
 block discarded – undo
4329 4545
 					lastItem = 0;
4330 4546
 					prevFile = curFile;';
4331 4547
 
4332
-		if ($is_debug)
4333
-			echo '
4548
+		if ($is_debug) {
4549
+					echo '
4334 4550
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4551
+		}
4335 4552
 
4336 4553
 		echo '
4337 4554
 					getNextItem();
@@ -4339,8 +4556,8 @@  discard block
 block discarded – undo
4339 4556
 				}';
4340 4557
 
4341 4558
 		// If debug scroll the screen.
4342
-		if ($is_debug)
4343
-			echo '
4559
+		if ($is_debug) {
4560
+					echo '
4344 4561
 				if (iLastSubStepProgress == -1)
4345 4562
 				{
4346 4563
 					// Give it consistent dots.
@@ -4359,6 +4576,7 @@  discard block
 block discarded – undo
4359 4576
 
4360 4577
 				if (document.getElementById(\'debug_section\').scrollHeight)
4361 4578
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4579
+		}
4362 4580
 
4363 4581
 		echo '
4364 4582
 				// Update the page.
@@ -4419,9 +4637,10 @@  discard block
 block discarded – undo
4419 4637
 			}';
4420 4638
 
4421 4639
 		// Start things off assuming we've not errored.
4422
-		if (empty($upcontext['error_message']))
4423
-			echo '
4640
+		if (empty($upcontext['error_message'])) {
4641
+					echo '
4424 4642
 			getNextItem();';
4643
+		}
4425 4644
 
4426 4645
 		echo '
4427 4646
 		//# sourceURL=dynamicScript-dbch.js
@@ -4439,18 +4658,21 @@  discard block
 block discarded – undo
4439 4658
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4440 4659
 	<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>';
4441 4660
 
4442
-	if (!empty($upcontext['error_message']))
4443
-		echo '
4661
+	if (!empty($upcontext['error_message'])) {
4662
+			echo '
4444 4663
 	<error>', $upcontext['error_message'], '</error>';
4664
+	}
4445 4665
 
4446
-	if (!empty($upcontext['error_string']))
4447
-		echo '
4666
+	if (!empty($upcontext['error_string'])) {
4667
+			echo '
4448 4668
 	<sql>', $upcontext['error_string'], '</sql>';
4669
+	}
4449 4670
 
4450
-	if ($is_debug)
4451
-		echo '
4671
+	if ($is_debug) {
4672
+			echo '
4452 4673
 	<curtime>', time(), '</curtime>';
4453
-}
4674
+	}
4675
+	}
4454 4676
 
4455 4677
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4456 4678
 function template_convert_utf8()
@@ -4469,18 +4691,20 @@  discard block
 block discarded – undo
4469 4691
 			</div>';
4470 4692
 
4471 4693
 	// Done any tables so far?
4472
-	if (!empty($upcontext['previous_tables']))
4473
-		foreach ($upcontext['previous_tables'] as $table)
4694
+	if (!empty($upcontext['previous_tables'])) {
4695
+			foreach ($upcontext['previous_tables'] as $table)
4474 4696
 			echo '
4475 4697
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4698
+	}
4476 4699
 
4477 4700
 	echo '
4478 4701
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4479 4702
 
4480 4703
 	// If we dropped their index, let's let them know
4481
-	if ($upcontext['dropping_index'])
4482
-		echo '
4704
+	if ($upcontext['dropping_index']) {
4705
+			echo '
4483 4706
 				<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>';
4707
+	}
4484 4708
 
4485 4709
 	// Completion notification
4486 4710
 	echo '
@@ -4517,12 +4741,13 @@  discard block
 block discarded – undo
4517 4741
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4518 4742
 
4519 4743
 		// If debug flood the screen.
4520
-		if ($is_debug)
4521
-			echo '
4744
+		if ($is_debug) {
4745
+					echo '
4522 4746
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4523 4747
 
4524 4748
 				if (document.getElementById(\'debug_section\').scrollHeight)
4525 4749
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4750
+		}
4526 4751
 
4527 4752
 		echo '
4528 4753
 				// Get the next update...
@@ -4570,19 +4795,21 @@  discard block
 block discarded – undo
4570 4795
 			</div>';
4571 4796
 
4572 4797
 	// Dont any tables so far?
4573
-	if (!empty($upcontext['previous_tables']))
4574
-		foreach ($upcontext['previous_tables'] as $table)
4798
+	if (!empty($upcontext['previous_tables'])) {
4799
+			foreach ($upcontext['previous_tables'] as $table)
4575 4800
 			echo '
4576 4801
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4802
+	}
4577 4803
 
4578 4804
 	echo '
4579 4805
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4580 4806
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>';
4581 4807
 
4582 4808
 	// Try to make sure substep was reset.
4583
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4584
-		echo '
4809
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4810
+			echo '
4585 4811
 			<input type="hidden" name="substep" id="substep" value="0">';
4812
+	}
4586 4813
 
4587 4814
 	// Continue please!
4588 4815
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4615,12 +4842,13 @@  discard block
 block discarded – undo
4615 4842
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4616 4843
 
4617 4844
 		// If debug flood the screen.
4618
-		if ($is_debug)
4619
-			echo '
4845
+		if ($is_debug) {
4846
+					echo '
4620 4847
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4621 4848
 
4622 4849
 				if (document.getElementById(\'debug_section\').scrollHeight)
4623 4850
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4851
+		}
4624 4852
 
4625 4853
 		echo '
4626 4854
 				// Get the next update...
@@ -4656,8 +4884,8 @@  discard block
 block discarded – undo
4656 4884
 	<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4657 4885
 	<form action="', $boardurl, '/index.php">';
4658 4886
 
4659
-	if (!empty($upcontext['can_delete_script']))
4660
-		echo '
4887
+	if (!empty($upcontext['can_delete_script'])) {
4888
+			echo '
4661 4889
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> <em>', $txt['upgrade_delete_server'], '</em>
4662 4890
 			<script>
4663 4891
 				function doTheDelete(theCheck)
@@ -4669,6 +4897,7 @@  discard block
 block discarded – undo
4669 4897
 				}
4670 4898
 			</script>
4671 4899
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4900
+	}
4672 4901
 
4673 4902
 	$active = time() - $upcontext['started'];
4674 4903
 	$hours = floor($active / 3600);
@@ -4678,16 +4907,20 @@  discard block
 block discarded – undo
4678 4907
 	if ($is_debug)
4679 4908
 	{
4680 4909
 		$totalTime = '';
4681
-		if ($hours > 0)
4682
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4683
-		if ($minutes > 0)
4684
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4685
-		if ($seconds > 0)
4686
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4910
+		if ($hours > 0) {
4911
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4912
+		}
4913
+		if ($minutes > 0) {
4914
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4915
+		}
4916
+		if ($seconds > 0) {
4917
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4918
+		}
4687 4919
 	}
4688 4920
 
4689
-	if ($is_debug && !empty($totalTime))
4690
-		echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4921
+	if ($is_debug && !empty($totalTime)) {
4922
+			echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4923
+	}
4691 4924
 
4692 4925
 	echo '<br>
4693 4926
 			', sprintf($txt['upgrade_problems'], 'http://simplemachines.org'), '<br>
@@ -4714,8 +4947,9 @@  discard block
 block discarded – undo
4714 4947
 
4715 4948
 	$current_substep = $_GET['substep'];
4716 4949
 
4717
-	if (empty($_GET['a']))
4718
-		$_GET['a'] = 0;
4950
+	if (empty($_GET['a'])) {
4951
+			$_GET['a'] = 0;
4952
+	}
4719 4953
 	$step_progress['name'] = 'Converting ips';
4720 4954
 	$step_progress['current'] = $_GET['a'];
4721 4955
 
@@ -4758,16 +4992,19 @@  discard block
 block discarded – undo
4758 4992
 				'empty' => '',
4759 4993
 				'limit' => $limit,
4760 4994
 		));
4761
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4762
-			$arIp[] = $row[$oldCol];
4995
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4996
+					$arIp[] = $row[$oldCol];
4997
+		}
4763 4998
 		$smcFunc['db_free_result']($request);
4764 4999
 
4765 5000
 		// Special case, null ip could keep us in a loop.
4766
-		if (is_null($arIp[0]))
4767
-			unset($arIp[0]);
5001
+		if (is_null($arIp[0])) {
5002
+					unset($arIp[0]);
5003
+		}
4768 5004
 
4769
-		if (empty($arIp))
4770
-			$is_done = true;
5005
+		if (empty($arIp)) {
5006
+					$is_done = true;
5007
+		}
4771 5008
 
4772 5009
 		$updates = array();
4773 5010
 		$cases = array();
@@ -4776,16 +5013,18 @@  discard block
 block discarded – undo
4776 5013
 		{
4777 5014
 			$arIp[$i] = trim($arIp[$i]);
4778 5015
 
4779
-			if (empty($arIp[$i]))
4780
-				continue;
5016
+			if (empty($arIp[$i])) {
5017
+							continue;
5018
+			}
4781 5019
 
4782 5020
 			$updates['ip' . $i] = $arIp[$i];
4783 5021
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4784 5022
 
4785 5023
 			if ($setSize > 0 && $i % $setSize === 0)
4786 5024
 			{
4787
-				if (count($updates) == 1)
4788
-					continue;
5025
+				if (count($updates) == 1) {
5026
+									continue;
5027
+				}
4789 5028
 
4790 5029
 				$updates['whereSet'] = array_values($updates);
4791 5030
 				$smcFunc['db_query']('', '
@@ -4819,8 +5058,7 @@  discard block
 block discarded – undo
4819 5058
 							'ip' => $ip
4820 5059
 					));
4821 5060
 				}
4822
-			}
4823
-			else
5061
+			} else
4824 5062
 			{
4825 5063
 				$updates['whereSet'] = array_values($updates);
4826 5064
 				$smcFunc['db_query']('', '
@@ -4834,9 +5072,9 @@  discard block
 block discarded – undo
4834 5072
 					$updates
4835 5073
 				);
4836 5074
 			}
5075
+		} else {
5076
+					$is_done = true;
4837 5077
 		}
4838
-		else
4839
-			$is_done = true;
4840 5078
 
4841 5079
 		$_GET['a'] += $limit;
4842 5080
 		$step_progress['current'] = $_GET['a'];
@@ -4862,10 +5100,11 @@  discard block
 block discarded – undo
4862 5100
 
4863 5101
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4864 5102
 
4865
-	if (isset($columns[$column]))
4866
-		return $columns[$column];
4867
-	else
4868
-		return null;
4869
-}
5103
+	if (isset($columns[$column])) {
5104
+			return $columns[$column];
5105
+	} else {
5106
+			return null;
5107
+	}
5108
+	}
4870 5109
 
4871 5110
 ?>
4872 5111
\ No newline at end of file
Please login to merge, or discard this patch.