Completed
Push — release-2.1 ( a0ed2c...a3d3e2 )
by Mert
14s
created
other/upgrade.php 1 patch
Braces   +909 added lines, -666 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,14 +223,17 @@  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
 // This is needed in case someone invokes the upgrader using https when upgrading an http forum
224
-if (httpsOn())
234
+if (httpsOn()) {
225 235
 	$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
236
+}
226 237
 
227 238
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
228 239
 // Default title...
@@ -240,13 +251,15 @@  discard block
 block discarded – undo
240 251
 	$support_js = $upcontext['upgrade_status']['js'];
241 252
 
242 253
 	// Only set this if the upgrader status says so.
243
-	if (empty($is_debug))
244
-		$is_debug = $upcontext['upgrade_status']['debug'];
254
+	if (empty($is_debug)) {
255
+			$is_debug = $upcontext['upgrade_status']['debug'];
256
+	}
245 257
 
246 258
 	// Load the language.
247
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
248
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
249
-}
259
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
260
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
261
+	}
262
+	}
250 263
 // Set the defaults.
251 264
 else
252 265
 {
@@ -264,15 +277,18 @@  discard block
 block discarded – undo
264 277
 }
265 278
 
266 279
 // If this isn't the first stage see whether they are logging in and resuming.
267
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
280
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
268 281
 	checkLogin();
282
+}
269 283
 
270
-if ($command_line)
284
+if ($command_line) {
271 285
 	cmdStep0();
286
+}
272 287
 
273 288
 // Don't error if we're using xml.
274
-if (isset($_GET['xml']))
289
+if (isset($_GET['xml'])) {
275 290
 	$upcontext['return_error'] = true;
291
+}
276 292
 
277 293
 // Loop through all the steps doing each one as required.
278 294
 $upcontext['overall_percent'] = 0;
@@ -293,9 +309,9 @@  discard block
 block discarded – undo
293 309
 		}
294 310
 
295 311
 		// Call the step and if it returns false that means pause!
296
-		if (function_exists($step[2]) && $step[2]() === false)
297
-			break;
298
-		elseif (function_exists($step[2])) {
312
+		if (function_exists($step[2]) && $step[2]() === false) {
313
+					break;
314
+		} elseif (function_exists($step[2])) {
299 315
 			//Start each new step with this unset, so the 'normal' template is called first
300 316
 			unset($_GET['xml']);
301 317
 			//Clear out warnings at the start of each step
@@ -341,17 +357,18 @@  discard block
 block discarded – undo
341 357
 		// This should not happen my dear... HELP ME DEVELOPERS!!
342 358
 		if (!empty($command_line))
343 359
 		{
344
-			if (function_exists('debug_print_backtrace'))
345
-				debug_print_backtrace();
360
+			if (function_exists('debug_print_backtrace')) {
361
+							debug_print_backtrace();
362
+			}
346 363
 
347 364
 			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.';
348 365
 			flush();
349 366
 			die();
350 367
 		}
351 368
 
352
-		if (!isset($_GET['xml']))
353
-			template_upgrade_above();
354
-		else
369
+		if (!isset($_GET['xml'])) {
370
+					template_upgrade_above();
371
+		} else
355 372
 		{
356 373
 			header('content-type: text/xml; charset=UTF-8');
357 374
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -373,25 +390,29 @@  discard block
 block discarded – undo
373 390
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
374 391
 
375 392
 			// Custom stuff to pass back?
376
-			if (!empty($upcontext['query_string']))
377
-				$upcontext['form_url'] .= $upcontext['query_string'];
393
+			if (!empty($upcontext['query_string'])) {
394
+							$upcontext['form_url'] .= $upcontext['query_string'];
395
+			}
378 396
 
379 397
 			// Call the appropriate subtemplate
380
-			if (is_callable('template_' . $upcontext['sub_template']))
381
-				call_user_func('template_' . $upcontext['sub_template']);
382
-			else
383
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
398
+			if (is_callable('template_' . $upcontext['sub_template'])) {
399
+							call_user_func('template_' . $upcontext['sub_template']);
400
+			} else {
401
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
402
+			}
384 403
 		}
385 404
 
386 405
 		// Was there an error?
387
-		if (!empty($upcontext['forced_error_message']))
388
-			echo $upcontext['forced_error_message'];
406
+		if (!empty($upcontext['forced_error_message'])) {
407
+					echo $upcontext['forced_error_message'];
408
+		}
389 409
 
390 410
 		// Show the footer.
391
-		if (!isset($_GET['xml']))
392
-			template_upgrade_below();
393
-		else
394
-			template_xml_below();
411
+		if (!isset($_GET['xml'])) {
412
+					template_upgrade_below();
413
+		} else {
414
+					template_xml_below();
415
+		}
395 416
 	}
396 417
 
397 418
 
@@ -403,15 +424,19 @@  discard block
 block discarded – undo
403 424
 		$seconds = intval($active % 60);
404 425
 
405 426
 		$totalTime = '';
406
-		if ($hours > 0)
407
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
408
-		if ($minutes > 0)
409
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
410
-		if ($seconds > 0)
411
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
427
+		if ($hours > 0) {
428
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
429
+		}
430
+		if ($minutes > 0) {
431
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
432
+		}
433
+		if ($seconds > 0) {
434
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
435
+		}
412 436
 
413
-		if (!empty($totalTime))
414
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
437
+		if (!empty($totalTime)) {
438
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
439
+		}
415 440
 	}
416 441
 
417 442
 	// Bang - gone!
@@ -432,8 +457,9 @@  discard block
 block discarded – undo
432 457
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
433 458
 		while ($entry = $dir->read())
434 459
 		{
435
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
436
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
460
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
461
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
462
+			}
437 463
 		}
438 464
 		$dir->close();
439 465
 	}
@@ -468,10 +494,11 @@  discard block
 block discarded – undo
468 494
 	}
469 495
 
470 496
 	// Override the language file?
471
-	if (isset($_GET['lang_file']))
472
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
473
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
474
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
497
+	if (isset($_GET['lang_file'])) {
498
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
499
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
500
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
501
+	}
475 502
 
476 503
 	// Make sure it exists, if it doesn't reset it.
477 504
 	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']))
@@ -480,12 +507,14 @@  discard block
 block discarded – undo
480 507
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
481 508
 
482 509
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
483
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
484
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
510
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
511
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
512
+		}
485 513
 
486 514
 		// For backup we load the english at first -> second language overwrite the english one
487
-		if (count($incontext['detected_languages']) > 1)
488
-			require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
515
+		if (count($incontext['detected_languages']) > 1) {
516
+					require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
517
+		}
489 518
 	}
490 519
 
491 520
 	// And now include the actual language file itself.
@@ -493,11 +522,12 @@  discard block
 block discarded – undo
493 522
 
494 523
 	// Which language did we load? Assume that he likes his language.
495 524
 	preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches);
496
-	if (empty($matches[1]))
497
-		$matches = [
525
+	if (empty($matches[1])) {
526
+			$matches = [
498 527
 			0 => 'nothing',
499 528
 			1 => 'english',
500 529
 		];
530
+	}
501 531
 	$user_info['language'] = $matches[1];
502 532
 }
503 533
 
@@ -507,8 +537,9 @@  discard block
 block discarded – undo
507 537
 	global $upgradeurl, $upcontext, $command_line;
508 538
 
509 539
 	// Command line users can't be redirected.
510
-	if ($command_line)
511
-		upgradeExit(true);
540
+	if ($command_line) {
541
+			upgradeExit(true);
542
+	}
512 543
 
513 544
 	// Are we providing the core info?
514 545
 	if ($addForm)
@@ -534,12 +565,14 @@  discard block
 block discarded – undo
534 565
 	define('SMF', 1);
535 566
 
536 567
 	// Start the session.
537
-	if (@ini_get('session.save_handler') == 'user')
538
-		@ini_set('session.save_handler', 'files');
568
+	if (@ini_get('session.save_handler') == 'user') {
569
+			@ini_set('session.save_handler', 'files');
570
+	}
539 571
 	@session_start();
540 572
 
541
-	if (empty($smcFunc))
542
-		$smcFunc = array();
573
+	if (empty($smcFunc)) {
574
+			$smcFunc = array();
575
+	}
543 576
 
544 577
 	// We need this for authentication and some upgrade code
545 578
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -566,24 +599,27 @@  discard block
 block discarded – undo
566 599
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
567 600
 
568 601
 		// Make the connection...
569
-		if (empty($db_connection))
570
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
571
-		else
572
-			// If we've returned here, ping/reconnect to be safe
602
+		if (empty($db_connection)) {
603
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
604
+		} else {
605
+					// If we've returned here, ping/reconnect to be safe
573 606
 			$smcFunc['db_ping']($db_connection);
607
+		}
574 608
 
575 609
 		// Oh dear god!!
576
-		if ($db_connection === null)
577
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
610
+		if ($db_connection === null) {
611
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
612
+		}
578 613
 
579
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
580
-			$smcFunc['db_query']('', '
614
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
615
+					$smcFunc['db_query']('', '
581 616
 			SET NAMES {string:db_character_set}',
582 617
 			array(
583 618
 				'db_error_skip' => true,
584 619
 				'db_character_set' => $db_character_set,
585 620
 			)
586 621
 		);
622
+		}
587 623
 
588 624
 		// Load the modSettings data...
589 625
 		$request = $smcFunc['db_query']('', '
@@ -594,11 +630,11 @@  discard block
 block discarded – undo
594 630
 			)
595 631
 		);
596 632
 		$modSettings = array();
597
-		while ($row = $smcFunc['db_fetch_assoc']($request))
598
-			$modSettings[$row['variable']] = $row['value'];
633
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
634
+					$modSettings[$row['variable']] = $row['value'];
635
+		}
599 636
 		$smcFunc['db_free_result']($request);
600
-	}
601
-	else
637
+	} else
602 638
 	{
603 639
 		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.');
604 640
 	}
@@ -612,9 +648,10 @@  discard block
 block discarded – undo
612 648
 		cleanRequest();
613 649
 	}
614 650
 
615
-	if (!isset($_GET['substep']))
616
-		$_GET['substep'] = 0;
617
-}
651
+	if (!isset($_GET['substep'])) {
652
+			$_GET['substep'] = 0;
653
+	}
654
+	}
618 655
 
619 656
 function initialize_inputs()
620 657
 {
@@ -644,8 +681,9 @@  discard block
 block discarded – undo
644 681
 		$dh = opendir(dirname(__FILE__));
645 682
 		while ($file = readdir($dh))
646 683
 		{
647
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
648
-				@unlink(dirname(__FILE__) . '/' . $file);
684
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
685
+							@unlink(dirname(__FILE__) . '/' . $file);
686
+			}
649 687
 		}
650 688
 		closedir($dh);
651 689
 
@@ -674,8 +712,9 @@  discard block
 block discarded – undo
674 712
 	$temp = 'upgrade_php?step';
675 713
 	while (strlen($temp) > 4)
676 714
 	{
677
-		if (isset($_GET[$temp]))
678
-			unset($_GET[$temp]);
715
+		if (isset($_GET[$temp])) {
716
+					unset($_GET[$temp]);
717
+		}
679 718
 		$temp = substr($temp, 1);
680 719
 	}
681 720
 
@@ -702,32 +741,39 @@  discard block
 block discarded – undo
702 741
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
703 742
 
704 743
 	// Need legacy scripts?
705
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
706
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
707
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
708
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
709
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
710
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
744
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
745
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
746
+	}
747
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
748
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
749
+	}
750
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
751
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
752
+	}
711 753
 
712 754
 	// We don't need "-utf8" files anymore...
713 755
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
714 756
 
715 757
 	// This needs to exist!
716
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
717
-		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>]');
718
-	else
719
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
758
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
759
+			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>]');
760
+	} else {
761
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
762
+	}
720 763
 
721
-	if (!$check)
722
-		// 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.
764
+	if (!$check) {
765
+			// 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.
723 766
 		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.');
767
+	}
724 768
 
725 769
 	// Do they meet the install requirements?
726
-	if (!php_version_check())
727
-		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.');
770
+	if (!php_version_check()) {
771
+			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.');
772
+	}
728 773
 
729
-	if (!db_version_check())
730
-		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.');
774
+	if (!db_version_check()) {
775
+			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.');
776
+	}
731 777
 
732 778
 	// Do some checks to make sure they have proper privileges
733 779
 	db_extend('packages');
@@ -742,14 +788,16 @@  discard block
 block discarded – undo
742 788
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
743 789
 
744 790
 	// Sorry... we need CREATE, ALTER and DROP
745
-	if (!$create || !$alter || !$drop)
746
-		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.');
791
+	if (!$create || !$alter || !$drop) {
792
+			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.');
793
+	}
747 794
 
748 795
 	// Do a quick version spot check.
749 796
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
750 797
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
751
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
752
-		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.');
798
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
799
+			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.');
800
+	}
753 801
 
754 802
 	// What absolutely needs to be writable?
755 803
 	$writable_files = array(
@@ -758,12 +806,13 @@  discard block
 block discarded – undo
758 806
 	);
759 807
 
760 808
 	// Only check for minified writable files if we have it enabled or not set.
761
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
762
-		$writable_files += array(
809
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
810
+			$writable_files += array(
763 811
 			$modSettings['theme_dir'] . '/css/minified.css',
764 812
 			$modSettings['theme_dir'] . '/scripts/minified.js',
765 813
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
766 814
 		);
815
+	}
767 816
 
768 817
 	// Do we need to add this setting?
769 818
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -775,12 +824,13 @@  discard block
 block discarded – undo
775 824
 	quickFileWritable($custom_av_dir);
776 825
 
777 826
 	// Are we good now?
778
-	if (!is_writable($custom_av_dir))
779
-		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));
780
-	elseif ($need_settings_update)
827
+	if (!is_writable($custom_av_dir)) {
828
+			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));
829
+	} elseif ($need_settings_update)
781 830
 	{
782
-		if (!function_exists('cache_put_data'))
783
-			require_once($sourcedir . '/Load.php');
831
+		if (!function_exists('cache_put_data')) {
832
+					require_once($sourcedir . '/Load.php');
833
+		}
784 834
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
785 835
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
786 836
 	}
@@ -789,28 +839,33 @@  discard block
 block discarded – undo
789 839
 
790 840
 	// Check the cache directory.
791 841
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
792
-	if (!file_exists($cachedir_temp))
793
-		@mkdir($cachedir_temp);
794
-	if (!file_exists($cachedir_temp))
795
-		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.');
796
-
797
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
798
-		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>.');
799
-	elseif (!isset($_GET['skiplang']))
842
+	if (!file_exists($cachedir_temp)) {
843
+			@mkdir($cachedir_temp);
844
+	}
845
+	if (!file_exists($cachedir_temp)) {
846
+			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.');
847
+	}
848
+
849
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
850
+			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>.');
851
+	} elseif (!isset($_GET['skiplang']))
800 852
 	{
801 853
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
802 854
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
803 855
 
804
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
805
-			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>]');
856
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
857
+					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>]');
858
+		}
806 859
 	}
807 860
 
808
-	if (!makeFilesWritable($writable_files))
809
-		return false;
861
+	if (!makeFilesWritable($writable_files)) {
862
+			return false;
863
+	}
810 864
 
811 865
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
812
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
813
-		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.');
866
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
867
+			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.');
868
+	}
814 869
 
815 870
 	// Upgrade the agreement.
816 871
 	elseif (isset($modSettings['agreement']))
@@ -821,8 +876,8 @@  discard block
 block discarded – undo
821 876
 	}
822 877
 
823 878
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
824
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
825
-		$upcontext['warning'] = '
879
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
880
+			$upcontext['warning'] = '
826 881
 			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>
827 882
 			<ul>
828 883
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -830,19 +885,23 @@  discard block
 block discarded – undo
830 885
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
831 886
 			</ul>
832 887
 			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.';
888
+	}
833 889
 
834 890
 	// Confirm mbstring is loaded...
835
-	if (!extension_loaded('mbstring'))
836
-		return throw_error($txt['install_no_mbstring']);
891
+	if (!extension_loaded('mbstring')) {
892
+			return throw_error($txt['install_no_mbstring']);
893
+	}
837 894
 
838 895
 	// Check for https stream support.
839 896
 	$supported_streams = stream_get_wrappers();
840
-	if (!in_array('https', $supported_streams))
841
-		$upcontext['custom_warning'] = $txt['install_no_https'];
897
+	if (!in_array('https', $supported_streams)) {
898
+			$upcontext['custom_warning'] = $txt['install_no_https'];
899
+	}
842 900
 
843 901
 	// Either we're logged in or we're going to present the login.
844
-	if (checkLogin())
845
-		return true;
902
+	if (checkLogin()) {
903
+			return true;
904
+	}
846 905
 
847 906
 	$upcontext += createToken('login');
848 907
 
@@ -856,15 +915,17 @@  discard block
 block discarded – undo
856 915
 	global $smcFunc, $db_type, $support_js;
857 916
 
858 917
 	// Don't bother if the security is disabled.
859
-	if ($disable_security)
860
-		return true;
918
+	if ($disable_security) {
919
+			return true;
920
+	}
861 921
 
862 922
 	// Are we trying to login?
863 923
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
864 924
 	{
865 925
 		// If we've disabled security pick a suitable name!
866
-		if (empty($_POST['user']))
867
-			$_POST['user'] = 'Administrator';
926
+		if (empty($_POST['user'])) {
927
+					$_POST['user'] = 'Administrator';
928
+		}
868 929
 
869 930
 		// Before 2.0 these column names were different!
870 931
 		$oldDB = false;
@@ -879,16 +940,17 @@  discard block
 block discarded – undo
879 940
 					'db_error_skip' => true,
880 941
 				)
881 942
 			);
882
-			if ($smcFunc['db_num_rows']($request) != 0)
883
-				$oldDB = true;
943
+			if ($smcFunc['db_num_rows']($request) != 0) {
944
+							$oldDB = true;
945
+			}
884 946
 			$smcFunc['db_free_result']($request);
885 947
 		}
886 948
 
887 949
 		// Get what we believe to be their details.
888 950
 		if (!$disable_security)
889 951
 		{
890
-			if ($oldDB)
891
-				$request = $smcFunc['db_query']('', '
952
+			if ($oldDB) {
953
+							$request = $smcFunc['db_query']('', '
892 954
 					SELECT id_member, memberName AS member_name, passwd, id_group,
893 955
 					additionalGroups AS additional_groups, lngfile
894 956
 					FROM {db_prefix}members
@@ -898,8 +960,8 @@  discard block
 block discarded – undo
898 960
 						'db_error_skip' => true,
899 961
 					)
900 962
 				);
901
-			else
902
-				$request = $smcFunc['db_query']('', '
963
+			} else {
964
+							$request = $smcFunc['db_query']('', '
903 965
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
904 966
 					FROM {db_prefix}members
905 967
 					WHERE member_name = {string:member_name}',
@@ -908,6 +970,7 @@  discard block
 block discarded – undo
908 970
 						'db_error_skip' => true,
909 971
 					)
910 972
 				);
973
+			}
911 974
 			if ($smcFunc['db_num_rows']($request) != 0)
912 975
 			{
913 976
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -915,16 +978,17 @@  discard block
 block discarded – undo
915 978
 				$groups = explode(',', $addGroups);
916 979
 				$groups[] = $id_group;
917 980
 
918
-				foreach ($groups as $k => $v)
919
-					$groups[$k] = (int) $v;
981
+				foreach ($groups as $k => $v) {
982
+									$groups[$k] = (int) $v;
983
+				}
920 984
 
921 985
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
922 986
 
923 987
 				// We don't use "-utf8" anymore...
924 988
 				$user_language = str_ireplace('-utf8', '', $user_language);
989
+			} else {
990
+							$upcontext['username_incorrect'] = true;
925 991
 			}
926
-			else
927
-				$upcontext['username_incorrect'] = true;
928 992
 			$smcFunc['db_free_result']($request);
929 993
 		}
930 994
 		$upcontext['username'] = $_POST['user'];
@@ -934,13 +998,14 @@  discard block
 block discarded – undo
934 998
 		{
935 999
 			$upcontext['upgrade_status']['js'] = 1;
936 1000
 			$support_js = 1;
1001
+		} else {
1002
+					$support_js = 0;
937 1003
 		}
938
-		else
939
-			$support_js = 0;
940 1004
 
941 1005
 		// Note down the version we are coming from.
942
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
943
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
1006
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
1007
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
1008
+		}
944 1009
 
945 1010
 		// Didn't get anywhere?
946 1011
 		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']))
@@ -974,15 +1039,15 @@  discard block
 block discarded – undo
974 1039
 							'db_error_skip' => true,
975 1040
 						)
976 1041
 					);
977
-					if ($smcFunc['db_num_rows']($request) == 0)
978
-						return throw_error('You need to be an admin to perform an upgrade!');
1042
+					if ($smcFunc['db_num_rows']($request) == 0) {
1043
+											return throw_error('You need to be an admin to perform an upgrade!');
1044
+					}
979 1045
 					$smcFunc['db_free_result']($request);
980 1046
 				}
981 1047
 
982 1048
 				$upcontext['user']['id'] = $id_member;
983 1049
 				$upcontext['user']['name'] = $name;
984
-			}
985
-			else
1050
+			} else
986 1051
 			{
987 1052
 				$upcontext['user']['id'] = 1;
988 1053
 				$upcontext['user']['name'] = 'Administrator';
@@ -998,11 +1063,11 @@  discard block
 block discarded – undo
998 1063
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
999 1064
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
1000 1065
 
1001
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
1002
-					$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'] . '.';
1003
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
1004
-					$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'] . '.';
1005
-				else
1066
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1067
+									$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'] . '.';
1068
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1069
+									$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'] . '.';
1070
+				} else
1006 1071
 				{
1007 1072
 					// Set this as the new language.
1008 1073
 					$upcontext['language'] = $user_language;
@@ -1046,8 +1111,9 @@  discard block
 block discarded – undo
1046 1111
 	unset($member_columns);
1047 1112
 
1048 1113
 	// If we've not submitted then we're done.
1049
-	if (empty($_POST['upcont']))
1050
-		return false;
1114
+	if (empty($_POST['upcont'])) {
1115
+			return false;
1116
+	}
1051 1117
 
1052 1118
 	// Firstly, if they're enabling SM stat collection just do it.
1053 1119
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1067,16 +1133,17 @@  discard block
 block discarded – undo
1067 1133
 				fwrite($fp, $out);
1068 1134
 
1069 1135
 				$return_data = '';
1070
-				while (!feof($fp))
1071
-					$return_data .= fgets($fp, 128);
1136
+				while (!feof($fp)) {
1137
+									$return_data .= fgets($fp, 128);
1138
+				}
1072 1139
 
1073 1140
 				fclose($fp);
1074 1141
 
1075 1142
 				// Get the unique site ID.
1076 1143
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1077 1144
 
1078
-				if (!empty($ID[1]))
1079
-					$smcFunc['db_insert']('replace',
1145
+				if (!empty($ID[1])) {
1146
+									$smcFunc['db_insert']('replace',
1080 1147
 						$db_prefix . 'settings',
1081 1148
 						array('variable' => 'string', 'value' => 'string'),
1082 1149
 						array(
@@ -1085,9 +1152,9 @@  discard block
 block discarded – undo
1085 1152
 						),
1086 1153
 						array('variable')
1087 1154
 					);
1155
+				}
1088 1156
 			}
1089
-		}
1090
-		else
1157
+		} else
1091 1158
 		{
1092 1159
 			$smcFunc['db_insert']('replace',
1093 1160
 				$db_prefix . 'settings',
@@ -1098,8 +1165,8 @@  discard block
 block discarded – undo
1098 1165
 		}
1099 1166
 	}
1100 1167
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1101
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1102
-		$smcFunc['db_query']('', '
1168
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1169
+			$smcFunc['db_query']('', '
1103 1170
 			DELETE FROM {db_prefix}settings
1104 1171
 			WHERE variable = {string:enable_sm_stats}',
1105 1172
 			array(
@@ -1107,6 +1174,7 @@  discard block
 block discarded – undo
1107 1174
 				'db_error_skip' => true,
1108 1175
 			)
1109 1176
 		);
1177
+	}
1110 1178
 
1111 1179
 	// Deleting old karma stuff?
1112 1180
 	if (!empty($_POST['delete_karma']))
@@ -1121,20 +1189,22 @@  discard block
 block discarded – undo
1121 1189
 		);
1122 1190
 
1123 1191
 		// Cleaning up old karma member settings.
1124
-		if ($upcontext['karma_installed']['good'])
1125
-			$smcFunc['db_query']('', '
1192
+		if ($upcontext['karma_installed']['good']) {
1193
+					$smcFunc['db_query']('', '
1126 1194
 				ALTER TABLE {db_prefix}members
1127 1195
 				DROP karma_good',
1128 1196
 				array()
1129 1197
 			);
1198
+		}
1130 1199
 
1131 1200
 		// Does karma bad was enable?
1132
-		if ($upcontext['karma_installed']['bad'])
1133
-			$smcFunc['db_query']('', '
1201
+		if ($upcontext['karma_installed']['bad']) {
1202
+					$smcFunc['db_query']('', '
1134 1203
 				ALTER TABLE {db_prefix}members
1135 1204
 				DROP karma_bad',
1136 1205
 				array()
1137 1206
 			);
1207
+		}
1138 1208
 
1139 1209
 		// Cleaning up old karma permissions.
1140 1210
 		$smcFunc['db_query']('', '
@@ -1152,32 +1222,37 @@  discard block
 block discarded – undo
1152 1222
 	}
1153 1223
 
1154 1224
 	// Emptying the error log?
1155
-	if (!empty($_POST['empty_error']))
1156
-		$smcFunc['db_query']('truncate_table', '
1225
+	if (!empty($_POST['empty_error'])) {
1226
+			$smcFunc['db_query']('truncate_table', '
1157 1227
 			TRUNCATE {db_prefix}log_errors',
1158 1228
 			array(
1159 1229
 			)
1160 1230
 		);
1231
+	}
1161 1232
 
1162 1233
 	$changes = array();
1163 1234
 
1164 1235
 	// Add proxy settings.
1165
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1166
-		$changes += array(
1236
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1237
+			$changes += array(
1167 1238
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1168 1239
 			'image_proxy_maxsize' => 5190,
1169 1240
 			'image_proxy_enabled' => 0,
1170 1241
 		);
1242
+	}
1171 1243
 
1172 1244
 	// If $boardurl reflects https, set force_ssl
1173
-	if (!function_exists('cache_put_data'))
1174
-		require_once($sourcedir . '/Load.php');
1175
-	if (stripos($boardurl, 'https://') !== false)
1176
-		updateSettings(array('force_ssl' => '1'));
1245
+	if (!function_exists('cache_put_data')) {
1246
+			require_once($sourcedir . '/Load.php');
1247
+	}
1248
+	if (stripos($boardurl, 'https://') !== false) {
1249
+			updateSettings(array('force_ssl' => '1'));
1250
+	}
1177 1251
 
1178 1252
 	// If we're overriding the language follow it through.
1179
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1180
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1253
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1254
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1255
+	}
1181 1256
 
1182 1257
 	if (!empty($_POST['maint']))
1183 1258
 	{
@@ -1189,26 +1264,29 @@  discard block
 block discarded – undo
1189 1264
 		{
1190 1265
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1191 1266
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1192
-		}
1193
-		else
1267
+		} else
1194 1268
 		{
1195 1269
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1196 1270
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1197 1271
 		}
1198 1272
 	}
1199 1273
 
1200
-	if ($command_line)
1201
-		echo ' * Updating Settings.php...';
1274
+	if ($command_line) {
1275
+			echo ' * Updating Settings.php...';
1276
+	}
1202 1277
 
1203 1278
 	// Fix some old paths.
1204
-	if (substr($boarddir, 0, 1) == '.')
1205
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1279
+	if (substr($boarddir, 0, 1) == '.') {
1280
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1281
+	}
1206 1282
 
1207
-	if (substr($sourcedir, 0, 1) == '.')
1208
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1283
+	if (substr($sourcedir, 0, 1) == '.') {
1284
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1285
+	}
1209 1286
 
1210
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1211
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1287
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1288
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1289
+	}
1212 1290
 
1213 1291
 	// If they have a "host:port" setup for the host, split that into separate values
1214 1292
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1219,32 +1297,36 @@  discard block
 block discarded – undo
1219 1297
 		$changes['db_server'] = '\'' . $db_server . '\'';
1220 1298
 
1221 1299
 		// Only set this if we're not using the default port
1222
-		if ($db_port != ini_get('mysqli.default_port'))
1223
-			$changes['db_port'] = (int) $db_port;
1224
-	}
1225
-	elseif (!empty($db_port))
1300
+		if ($db_port != ini_get('mysqli.default_port')) {
1301
+					$changes['db_port'] = (int) $db_port;
1302
+		}
1303
+	} elseif (!empty($db_port))
1226 1304
 	{
1227 1305
 		// If db_port is set and is the same as the default, set it to ''
1228 1306
 		if ($db_type == 'mysql')
1229 1307
 		{
1230
-			if ($db_port == ini_get('mysqli.default_port'))
1231
-				$changes['db_port'] = '\'\'';
1232
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1233
-				$changes['db_port'] = '\'\'';
1308
+			if ($db_port == ini_get('mysqli.default_port')) {
1309
+							$changes['db_port'] = '\'\'';
1310
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1311
+							$changes['db_port'] = '\'\'';
1312
+			}
1234 1313
 		}
1235 1314
 	}
1236 1315
 
1237 1316
 	// Maybe we haven't had this option yet?
1238
-	if (empty($packagesdir))
1239
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1317
+	if (empty($packagesdir)) {
1318
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1319
+	}
1240 1320
 
1241 1321
 	// Add support for $tasksdir var.
1242
-	if (empty($tasksdir))
1243
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1322
+	if (empty($tasksdir)) {
1323
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1324
+	}
1244 1325
 
1245 1326
 	// Make sure we fix the language as well.
1246
-	if (stristr($language, '-utf8'))
1247
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1327
+	if (stristr($language, '-utf8')) {
1328
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1329
+	}
1248 1330
 
1249 1331
 	// @todo Maybe change the cookie name if going to 1.1, too?
1250 1332
 
@@ -1255,8 +1337,9 @@  discard block
 block discarded – undo
1255 1337
 	// Tell Settings.php to store db_last_error.php in the cache
1256 1338
 	move_db_last_error_to_cachedir();
1257 1339
 
1258
-	if ($command_line)
1259
-		echo ' Successful.' . "\n";
1340
+	if ($command_line) {
1341
+			echo ' Successful.' . "\n";
1342
+	}
1260 1343
 
1261 1344
 	// Are we doing debug?
1262 1345
 	if (isset($_POST['debug']))
@@ -1266,8 +1349,9 @@  discard block
 block discarded – undo
1266 1349
 	}
1267 1350
 
1268 1351
 	// If we're not backing up then jump one.
1269
-	if (empty($_POST['backup']))
1270
-		$upcontext['current_step']++;
1352
+	if (empty($_POST['backup'])) {
1353
+			$upcontext['current_step']++;
1354
+	}
1271 1355
 
1272 1356
 	// If we've got here then let's proceed to the next step!
1273 1357
 	return true;
@@ -1282,8 +1366,9 @@  discard block
 block discarded – undo
1282 1366
 	$upcontext['page_title'] = $txt['backup_database'];
1283 1367
 
1284 1368
 	// Done it already - js wise?
1285
-	if (!empty($_POST['backup_done']))
1286
-		return true;
1369
+	if (!empty($_POST['backup_done'])) {
1370
+			return true;
1371
+	}
1287 1372
 
1288 1373
 	// Some useful stuff here.
1289 1374
 	db_extend();
@@ -1297,9 +1382,10 @@  discard block
 block discarded – undo
1297 1382
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1298 1383
 
1299 1384
 	$table_names = array();
1300
-	foreach ($tables as $table)
1301
-		if (substr($table, 0, 7) !== 'backup_')
1385
+	foreach ($tables as $table) {
1386
+			if (substr($table, 0, 7) !== 'backup_')
1302 1387
 			$table_names[] = $table;
1388
+	}
1303 1389
 
1304 1390
 	$upcontext['table_count'] = count($table_names);
1305 1391
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1309,12 +1395,14 @@  discard block
 block discarded – undo
1309 1395
 	$file_steps = $upcontext['table_count'];
1310 1396
 
1311 1397
 	// What ones have we already done?
1312
-	foreach ($table_names as $id => $table)
1313
-		if ($id < $_GET['substep'])
1398
+	foreach ($table_names as $id => $table) {
1399
+			if ($id < $_GET['substep'])
1314 1400
 			$upcontext['previous_tables'][] = $table;
1401
+	}
1315 1402
 
1316
-	if ($command_line)
1317
-		echo 'Backing Up Tables.';
1403
+	if ($command_line) {
1404
+			echo 'Backing Up Tables.';
1405
+	}
1318 1406
 
1319 1407
 	// If we don't support javascript we backup here.
1320 1408
 	if (!$support_js || isset($_GET['xml']))
@@ -1333,8 +1421,9 @@  discard block
 block discarded – undo
1333 1421
 			backupTable($table_names[$substep]);
1334 1422
 
1335 1423
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1336
-			if (isset($_GET['xml']))
1337
-				return upgradeExit();
1424
+			if (isset($_GET['xml'])) {
1425
+							return upgradeExit();
1426
+			}
1338 1427
 		}
1339 1428
 
1340 1429
 		if ($command_line)
@@ -1367,9 +1456,10 @@  discard block
 block discarded – undo
1367 1456
 
1368 1457
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1369 1458
 
1370
-	if ($command_line)
1371
-		echo ' done.';
1372
-}
1459
+	if ($command_line) {
1460
+			echo ' done.';
1461
+	}
1462
+	}
1373 1463
 
1374 1464
 // Step 2: Everything.
1375 1465
 function DatabaseChanges()
@@ -1378,8 +1468,9 @@  discard block
 block discarded – undo
1378 1468
 	global $upcontext, $support_js, $db_type;
1379 1469
 
1380 1470
 	// Have we just completed this?
1381
-	if (!empty($_POST['database_done']))
1382
-		return true;
1471
+	if (!empty($_POST['database_done'])) {
1472
+			return true;
1473
+	}
1383 1474
 
1384 1475
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1385 1476
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1394,15 +1485,16 @@  discard block
 block discarded – undo
1394 1485
 	);
1395 1486
 
1396 1487
 	// How many files are there in total?
1397
-	if (isset($_GET['filecount']))
1398
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1399
-	else
1488
+	if (isset($_GET['filecount'])) {
1489
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1490
+	} else
1400 1491
 	{
1401 1492
 		$upcontext['file_count'] = 0;
1402 1493
 		foreach ($files as $file)
1403 1494
 		{
1404
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1405
-				$upcontext['file_count']++;
1495
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1496
+							$upcontext['file_count']++;
1497
+			}
1406 1498
 		}
1407 1499
 	}
1408 1500
 
@@ -1412,9 +1504,9 @@  discard block
 block discarded – undo
1412 1504
 	$upcontext['cur_file_num'] = 0;
1413 1505
 	foreach ($files as $file)
1414 1506
 	{
1415
-		if ($did_not_do)
1416
-			$did_not_do--;
1417
-		else
1507
+		if ($did_not_do) {
1508
+					$did_not_do--;
1509
+		} else
1418 1510
 		{
1419 1511
 			$upcontext['cur_file_num']++;
1420 1512
 			$upcontext['cur_file_name'] = $file[0];
@@ -1441,12 +1533,13 @@  discard block
 block discarded – undo
1441 1533
 					// Flag to move on to the next.
1442 1534
 					$upcontext['completed_step'] = true;
1443 1535
 					// Did we complete the whole file?
1444
-					if ($nextFile)
1445
-						$upcontext['current_debug_item_num'] = -1;
1536
+					if ($nextFile) {
1537
+											$upcontext['current_debug_item_num'] = -1;
1538
+					}
1446 1539
 					return upgradeExit();
1540
+				} elseif ($support_js) {
1541
+									break;
1447 1542
 				}
1448
-				elseif ($support_js)
1449
-					break;
1450 1543
 			}
1451 1544
 			// Set the progress bar to be right as if we had - even if we hadn't...
1452 1545
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1472,8 +1565,9 @@  discard block
 block discarded – undo
1472 1565
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt, $settings;
1473 1566
 
1474 1567
 	// Now it's nice to have some of the basic SMF source files.
1475
-	if (!isset($_GET['ssi']) && !$command_line)
1476
-		redirectLocation('&ssi=1');
1568
+	if (!isset($_GET['ssi']) && !$command_line) {
1569
+			redirectLocation('&ssi=1');
1570
+	}
1477 1571
 
1478 1572
 	$upcontext['sub_template'] = 'upgrade_complete';
1479 1573
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1489,14 +1583,16 @@  discard block
 block discarded – undo
1489 1583
 	// Are we in maintenance mode?
1490 1584
 	if (isset($upcontext['user']['main']))
1491 1585
 	{
1492
-		if ($command_line)
1493
-			echo ' * ';
1586
+		if ($command_line) {
1587
+					echo ' * ';
1588
+		}
1494 1589
 		$upcontext['removed_maintenance'] = true;
1495 1590
 		$changes['maintenance'] = $upcontext['user']['main'];
1496 1591
 	}
1497 1592
 	// Otherwise if somehow we are in 2 let's go to 1.
1498
-	elseif (!empty($maintenance) && $maintenance == 2)
1499
-		$changes['maintenance'] = 1;
1593
+	elseif (!empty($maintenance) && $maintenance == 2) {
1594
+			$changes['maintenance'] = 1;
1595
+	}
1500 1596
 
1501 1597
 	// Wipe this out...
1502 1598
 	$upcontext['user'] = array();
@@ -1511,21 +1607,23 @@  discard block
 block discarded – undo
1511 1607
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1512 1608
 
1513 1609
 	// Now is the perfect time to fetch the SM files.
1514
-	if ($command_line)
1515
-		cli_scheduled_fetchSMfiles();
1516
-	else
1610
+	if ($command_line) {
1611
+			cli_scheduled_fetchSMfiles();
1612
+	} else
1517 1613
 	{
1518 1614
 		require_once($sourcedir . '/ScheduledTasks.php');
1519 1615
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
1520 1616
 		scheduled_fetchSMfiles(); // Now go get those files!
1521 1617
 		// This is needed in case someone invokes the upgrader using https when upgrading an http forum
1522
-		if (httpsOn())
1523
-			$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1618
+		if (httpsOn()) {
1619
+					$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1620
+		}
1524 1621
 	}
1525 1622
 
1526 1623
 	// Log what we've done.
1527
-	if (empty($user_info['id']))
1528
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1624
+	if (empty($user_info['id'])) {
1625
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1626
+	}
1529 1627
 
1530 1628
 	// Log the action manually, so CLI still works.
1531 1629
 	$smcFunc['db_insert']('',
@@ -1544,8 +1642,9 @@  discard block
 block discarded – undo
1544 1642
 
1545 1643
 	// Save the current database version.
1546 1644
 	$server_version = $smcFunc['db_server_info']();
1547
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1548
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1645
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1646
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1647
+	}
1549 1648
 
1550 1649
 	if ($command_line)
1551 1650
 	{
@@ -1557,8 +1656,9 @@  discard block
 block discarded – undo
1557 1656
 
1558 1657
 	// Make sure it says we're done.
1559 1658
 	$upcontext['overall_percent'] = 100;
1560
-	if (isset($upcontext['step_progress']))
1561
-		unset($upcontext['step_progress']);
1659
+	if (isset($upcontext['step_progress'])) {
1660
+			unset($upcontext['step_progress']);
1661
+	}
1562 1662
 
1563 1663
 	$_GET['substep'] = 0;
1564 1664
 	return false;
@@ -1569,8 +1669,9 @@  discard block
 block discarded – undo
1569 1669
 {
1570 1670
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1571 1671
 
1572
-	if (empty($modSettings['time_format']))
1573
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1672
+	if (empty($modSettings['time_format'])) {
1673
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1674
+	}
1574 1675
 
1575 1676
 	// What files do we want to get
1576 1677
 	$request = $smcFunc['db_query']('', '
@@ -1604,8 +1705,9 @@  discard block
 block discarded – undo
1604 1705
 		$file_data = fetch_web_data($url);
1605 1706
 
1606 1707
 		// If we got an error - give up - the site might be down.
1607
-		if ($file_data === false)
1608
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1708
+		if ($file_data === false) {
1709
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1710
+		}
1609 1711
 
1610 1712
 		// Save the file to the database.
1611 1713
 		$smcFunc['db_query']('substring', '
@@ -1647,8 +1749,9 @@  discard block
 block discarded – undo
1647 1749
 	$themeData = array();
1648 1750
 	foreach ($values as $variable => $value)
1649 1751
 	{
1650
-		if (!isset($value) || $value === null)
1651
-			$value = 0;
1752
+		if (!isset($value) || $value === null) {
1753
+					$value = 0;
1754
+		}
1652 1755
 
1653 1756
 		$themeData[] = array(0, 1, $variable, $value);
1654 1757
 	}
@@ -1677,8 +1780,9 @@  discard block
 block discarded – undo
1677 1780
 
1678 1781
 	foreach ($values as $variable => $value)
1679 1782
 	{
1680
-		if (empty($modSettings[$value[0]]))
1681
-			continue;
1783
+		if (empty($modSettings[$value[0]])) {
1784
+					continue;
1785
+		}
1682 1786
 
1683 1787
 		$smcFunc['db_query']('', '
1684 1788
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1764,19 +1868,21 @@  discard block
 block discarded – undo
1764 1868
 	set_error_handler(
1765 1869
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1766 1870
 		{
1767
-			if ($support_js)
1768
-				return true;
1769
-			else
1770
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1871
+			if ($support_js) {
1872
+							return true;
1873
+			} else {
1874
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1875
+			}
1771 1876
 		}
1772 1877
 	);
1773 1878
 
1774 1879
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1775 1880
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1776
-	if ($db_type == 'mysql')
1777
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1778
-	else
1779
-		$db_collation = '';
1881
+	if ($db_type == 'mysql') {
1882
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1883
+	} else {
1884
+			$db_collation = '';
1885
+	}
1780 1886
 
1781 1887
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1782 1888
 
@@ -1788,8 +1894,9 @@  discard block
 block discarded – undo
1788 1894
 	$last_step = '';
1789 1895
 
1790 1896
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1791
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1792
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1897
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1898
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1899
+	}
1793 1900
 
1794 1901
 	// Count the total number of steps within this file - for progress.
1795 1902
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1809,15 +1916,18 @@  discard block
 block discarded – undo
1809 1916
 		$do_current = $substep >= $_GET['substep'];
1810 1917
 
1811 1918
 		// Get rid of any comments in the beginning of the line...
1812
-		if (substr(trim($line), 0, 2) === '/*')
1813
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1919
+		if (substr(trim($line), 0, 2) === '/*') {
1920
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1921
+		}
1814 1922
 
1815 1923
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1816
-		if ($is_debug && !$support_js && $command_line)
1817
-			flush();
1924
+		if ($is_debug && !$support_js && $command_line) {
1925
+					flush();
1926
+		}
1818 1927
 
1819
-		if (trim($line) === '')
1820
-			continue;
1928
+		if (trim($line) === '') {
1929
+					continue;
1930
+		}
1821 1931
 
1822 1932
 		if (trim(substr($line, 0, 3)) === '---')
1823 1933
 		{
@@ -1827,8 +1937,9 @@  discard block
 block discarded – undo
1827 1937
 			if (trim($current_data) != '' && $type !== '}')
1828 1938
 			{
1829 1939
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1830
-				if ($command_line)
1831
-					echo $upcontext['error_message'];
1940
+				if ($command_line) {
1941
+									echo $upcontext['error_message'];
1942
+				}
1832 1943
 			}
1833 1944
 
1834 1945
 			if ($type == ' ')
@@ -1846,17 +1957,18 @@  discard block
 block discarded – undo
1846 1957
 				if ($do_current)
1847 1958
 				{
1848 1959
 					$upcontext['actioned_items'][] = $last_step;
1849
-					if ($command_line)
1850
-						echo ' * ';
1960
+					if ($command_line) {
1961
+											echo ' * ';
1962
+					}
1851 1963
 				}
1852
-			}
1853
-			elseif ($type == '#')
1964
+			} elseif ($type == '#')
1854 1965
 			{
1855 1966
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1856 1967
 
1857 1968
 				$upcontext['current_debug_item_num']++;
1858
-				if (trim($line) != '---#')
1859
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1969
+				if (trim($line) != '---#') {
1970
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1971
+				}
1860 1972
 
1861 1973
 				// Have we already done something?
1862 1974
 				if (isset($_GET['xml']) && $done_something)
@@ -1867,34 +1979,36 @@  discard block
 block discarded – undo
1867 1979
 
1868 1980
 				if ($do_current)
1869 1981
 				{
1870
-					if (trim($line) == '---#' && $command_line)
1871
-						echo ' done.', $endl;
1872
-					elseif ($command_line)
1873
-						echo ' +++ ', rtrim(substr($line, 4));
1874
-					elseif (trim($line) != '---#')
1982
+					if (trim($line) == '---#' && $command_line) {
1983
+											echo ' done.', $endl;
1984
+					} elseif ($command_line) {
1985
+											echo ' +++ ', rtrim(substr($line, 4));
1986
+					} elseif (trim($line) != '---#')
1875 1987
 					{
1876
-						if ($is_debug)
1877
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1988
+						if ($is_debug) {
1989
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1990
+						}
1878 1991
 					}
1879 1992
 				}
1880 1993
 
1881 1994
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1882 1995
 				{
1883
-					if ($command_line)
1884
-						echo ' * ';
1885
-					else
1886
-						$upcontext['actioned_items'][] = $last_step;
1996
+					if ($command_line) {
1997
+											echo ' * ';
1998
+					} else {
1999
+											$upcontext['actioned_items'][] = $last_step;
2000
+					}
1887 2001
 				}
1888 2002
 
1889 2003
 				// Small step - only if we're actually doing stuff.
1890
-				if ($do_current)
1891
-					nextSubstep(++$substep);
1892
-				else
1893
-					$substep++;
1894
-			}
1895
-			elseif ($type == '{')
1896
-				$current_type = 'code';
1897
-			elseif ($type == '}')
2004
+				if ($do_current) {
2005
+									nextSubstep(++$substep);
2006
+				} else {
2007
+									$substep++;
2008
+				}
2009
+			} elseif ($type == '{') {
2010
+							$current_type = 'code';
2011
+			} elseif ($type == '}')
1898 2012
 			{
1899 2013
 				$current_type = 'sql';
1900 2014
 
@@ -1907,8 +2021,9 @@  discard block
 block discarded – undo
1907 2021
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1908 2022
 				{
1909 2023
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1910
-					if ($command_line)
1911
-						echo $upcontext['error_message'];
2024
+					if ($command_line) {
2025
+											echo $upcontext['error_message'];
2026
+					}
1912 2027
 				}
1913 2028
 
1914 2029
 				// Done with code!
@@ -1995,8 +2110,9 @@  discard block
 block discarded – undo
1995 2110
 	$db_unbuffered = false;
1996 2111
 
1997 2112
 	// Failure?!
1998
-	if ($result !== false)
1999
-		return $result;
2113
+	if ($result !== false) {
2114
+			return $result;
2115
+	}
2000 2116
 
2001 2117
 	$db_error_message = $smcFunc['db_error']($db_connection);
2002 2118
 	// If MySQL we do something more clever.
@@ -2024,54 +2140,61 @@  discard block
 block discarded – undo
2024 2140
 			{
2025 2141
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2026 2142
 				$result = mysqli_query($db_connection, $string);
2027
-				if ($result !== false)
2028
-					return $result;
2143
+				if ($result !== false) {
2144
+									return $result;
2145
+				}
2029 2146
 			}
2030
-		}
2031
-		elseif ($mysqli_errno == 2013)
2147
+		} elseif ($mysqli_errno == 2013)
2032 2148
 		{
2033 2149
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2034 2150
 			mysqli_select_db($db_connection, $db_name);
2035 2151
 			if ($db_connection)
2036 2152
 			{
2037 2153
 				$result = mysqli_query($db_connection, $string);
2038
-				if ($result !== false)
2039
-					return $result;
2154
+				if ($result !== false) {
2155
+									return $result;
2156
+				}
2040 2157
 			}
2041 2158
 		}
2042 2159
 		// Duplicate column name... should be okay ;).
2043
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2044
-			return false;
2160
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2161
+					return false;
2162
+		}
2045 2163
 		// Duplicate insert... make sure it's the proper type of query ;).
2046
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2047
-			return false;
2164
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2165
+					return false;
2166
+		}
2048 2167
 		// Creating an index on a non-existent column.
2049
-		elseif ($mysqli_errno == 1072)
2050
-			return false;
2051
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2052
-			return false;
2168
+		elseif ($mysqli_errno == 1072) {
2169
+					return false;
2170
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2171
+					return false;
2172
+		}
2053 2173
 	}
2054 2174
 	// If a table already exists don't go potty.
2055 2175
 	else
2056 2176
 	{
2057 2177
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2058 2178
 		{
2059
-			if (strpos($db_error_message, 'exist') !== false)
2060
-				return true;
2061
-		}
2062
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2179
+			if (strpos($db_error_message, 'exist') !== false) {
2180
+							return true;
2181
+			}
2182
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2063 2183
 		{
2064
-			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error)
2065
-				return true;
2184
+			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) {
2185
+							return true;
2186
+			}
2066 2187
 		}
2067 2188
 	}
2068 2189
 
2069 2190
 	// Get the query string so we pass everything.
2070 2191
 	$query_string = '';
2071
-	foreach ($_GET as $k => $v)
2072
-		$query_string .= ';' . $k . '=' . $v;
2073
-	if (strlen($query_string) != 0)
2074
-		$query_string = '?' . substr($query_string, 1);
2192
+	foreach ($_GET as $k => $v) {
2193
+			$query_string .= ';' . $k . '=' . $v;
2194
+	}
2195
+	if (strlen($query_string) != 0) {
2196
+			$query_string = '?' . substr($query_string, 1);
2197
+	}
2075 2198
 
2076 2199
 	if ($command_line)
2077 2200
 	{
@@ -2126,16 +2249,18 @@  discard block
 block discarded – undo
2126 2249
 			{
2127 2250
 				$found |= 1;
2128 2251
 				// Do some checks on the data if we have it set.
2129
-				if (isset($change['col_type']))
2130
-					$found &= $change['col_type'] === $column['type'];
2131
-				if (isset($change['null_allowed']))
2132
-					$found &= $column['null'] == $change['null_allowed'];
2133
-				if (isset($change['default']))
2134
-					$found &= $change['default'] === $column['default'];
2252
+				if (isset($change['col_type'])) {
2253
+									$found &= $change['col_type'] === $column['type'];
2254
+				}
2255
+				if (isset($change['null_allowed'])) {
2256
+									$found &= $column['null'] == $change['null_allowed'];
2257
+				}
2258
+				if (isset($change['default'])) {
2259
+									$found &= $change['default'] === $column['default'];
2260
+				}
2135 2261
 			}
2136 2262
 		}
2137
-	}
2138
-	elseif ($change['type'] === 'index')
2263
+	} elseif ($change['type'] === 'index')
2139 2264
 	{
2140 2265
 		$request = upgrade_query('
2141 2266
 			SHOW INDEX
@@ -2144,9 +2269,10 @@  discard block
 block discarded – undo
2144 2269
 		{
2145 2270
 			$cur_index = array();
2146 2271
 
2147
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2148
-				if ($row['Key_name'] === $change['name'])
2272
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2273
+							if ($row['Key_name'] === $change['name'])
2149 2274
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2275
+			}
2150 2276
 
2151 2277
 			ksort($cur_index, SORT_NUMERIC);
2152 2278
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2156,14 +2282,17 @@  discard block
 block discarded – undo
2156 2282
 	}
2157 2283
 
2158 2284
 	// If we're trying to add and it's added, we're done.
2159
-	if ($found && in_array($change['method'], array('add', 'change')))
2160
-		return true;
2285
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2286
+			return true;
2287
+	}
2161 2288
 	// Otherwise if we're removing and it wasn't found we're also done.
2162
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2163
-		return true;
2289
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2290
+			return true;
2291
+	}
2164 2292
 	// Otherwise is it just a test?
2165
-	elseif ($is_test)
2166
-		return false;
2293
+	elseif ($is_test) {
2294
+			return false;
2295
+	}
2167 2296
 
2168 2297
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2169 2298
 	$running = false;
@@ -2174,8 +2303,9 @@  discard block
 block discarded – undo
2174 2303
 			SHOW FULL PROCESSLIST');
2175 2304
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2176 2305
 		{
2177
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2178
-				$found = true;
2306
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2307
+							$found = true;
2308
+			}
2179 2309
 		}
2180 2310
 
2181 2311
 		// Can't find it? Then we need to run it fools!
@@ -2187,8 +2317,9 @@  discard block
 block discarded – undo
2187 2317
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2188 2318
 				' . $change['text'], true) !== false;
2189 2319
 
2190
-			if (!$success)
2191
-				return false;
2320
+			if (!$success) {
2321
+							return false;
2322
+			}
2192 2323
 
2193 2324
 			// Return
2194 2325
 			$running = true;
@@ -2230,8 +2361,9 @@  discard block
 block discarded – undo
2230 2361
 			'db_error_skip' => true,
2231 2362
 		)
2232 2363
 	);
2233
-	if ($smcFunc['db_num_rows']($request) === 0)
2234
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2364
+	if ($smcFunc['db_num_rows']($request) === 0) {
2365
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2366
+	}
2235 2367
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2236 2368
 	$smcFunc['db_free_result']($request);
2237 2369
 
@@ -2253,18 +2385,19 @@  discard block
 block discarded – undo
2253 2385
 			)
2254 2386
 		);
2255 2387
 		// No results? Just forget it all together.
2256
-		if ($smcFunc['db_num_rows']($request) === 0)
2257
-			unset($table_row['Collation']);
2258
-		else
2259
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2388
+		if ($smcFunc['db_num_rows']($request) === 0) {
2389
+					unset($table_row['Collation']);
2390
+		} else {
2391
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2392
+		}
2260 2393
 		$smcFunc['db_free_result']($request);
2261 2394
 	}
2262 2395
 
2263 2396
 	if ($column_fix)
2264 2397
 	{
2265 2398
 		// Make sure there are no NULL's left.
2266
-		if ($null_fix)
2267
-			$smcFunc['db_query']('', '
2399
+		if ($null_fix) {
2400
+					$smcFunc['db_query']('', '
2268 2401
 				UPDATE {db_prefix}' . $change['table'] . '
2269 2402
 				SET ' . $change['column'] . ' = {string:default}
2270 2403
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2273,6 +2406,7 @@  discard block
 block discarded – undo
2273 2406
 					'db_error_skip' => true,
2274 2407
 				)
2275 2408
 			);
2409
+		}
2276 2410
 
2277 2411
 		// Do the actual alteration.
2278 2412
 		$smcFunc['db_query']('', '
@@ -2301,8 +2435,9 @@  discard block
 block discarded – undo
2301 2435
 	}
2302 2436
 
2303 2437
 	// Not a column we need to check on?
2304
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2305
-		return;
2438
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2439
+			return;
2440
+	}
2306 2441
 
2307 2442
 	// Break it up you (six|seven).
2308 2443
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2321,13 +2456,13 @@  discard block
 block discarded – undo
2321 2456
 				'new_name' => $temp[2],
2322 2457
 		));
2323 2458
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2324
-		if ($smcFunc['db_num_rows'] != 1)
2325
-			return;
2459
+		if ($smcFunc['db_num_rows'] != 1) {
2460
+					return;
2461
+		}
2326 2462
 
2327 2463
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2328 2464
 		$smcFunc['db_free_result']($request);
2329
-	}
2330
-	else
2465
+	} else
2331 2466
 	{
2332 2467
 		// Do this the old fashion, sure method way.
2333 2468
 		$request = $smcFunc['db_query']('', '
@@ -2338,21 +2473,24 @@  discard block
 block discarded – undo
2338 2473
 		));
2339 2474
 		// Mayday!
2340 2475
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2341
-		if ($smcFunc['db_num_rows'] == 0)
2342
-			return;
2476
+		if ($smcFunc['db_num_rows'] == 0) {
2477
+					return;
2478
+		}
2343 2479
 
2344 2480
 		// Oh where, oh where has my little field gone. Oh where can it be...
2345
-		while ($row = $smcFunc['db_query']($request))
2346
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2481
+		while ($row = $smcFunc['db_query']($request)) {
2482
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2347 2483
 			{
2348 2484
 				$current_type = $row['Type'];
2485
+		}
2349 2486
 				break;
2350 2487
 			}
2351 2488
 	}
2352 2489
 
2353 2490
 	// If this doesn't match, the column may of been altered for a reason.
2354
-	if (trim($current_type) != trim($temp[3]))
2355
-		$temp[3] = $current_type;
2491
+	if (trim($current_type) != trim($temp[3])) {
2492
+			$temp[3] = $current_type;
2493
+	}
2356 2494
 
2357 2495
 	// Piece this back together.
2358 2496
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2364,8 +2502,9 @@  discard block
 block discarded – undo
2364 2502
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2365 2503
 	global $step_progress, $is_debug, $upcontext;
2366 2504
 
2367
-	if ($_GET['substep'] < $substep)
2368
-		$_GET['substep'] = $substep;
2505
+	if ($_GET['substep'] < $substep) {
2506
+			$_GET['substep'] = $substep;
2507
+	}
2369 2508
 
2370 2509
 	if ($command_line)
2371 2510
 	{
@@ -2378,29 +2517,33 @@  discard block
 block discarded – undo
2378 2517
 	}
2379 2518
 
2380 2519
 	@set_time_limit(300);
2381
-	if (function_exists('apache_reset_timeout'))
2382
-		@apache_reset_timeout();
2520
+	if (function_exists('apache_reset_timeout')) {
2521
+			@apache_reset_timeout();
2522
+	}
2383 2523
 
2384
-	if (time() - $start_time <= $timeLimitThreshold)
2385
-		return;
2524
+	if (time() - $start_time <= $timeLimitThreshold) {
2525
+			return;
2526
+	}
2386 2527
 
2387 2528
 	// Do we have some custom step progress stuff?
2388 2529
 	if (!empty($step_progress))
2389 2530
 	{
2390 2531
 		$upcontext['substep_progress'] = 0;
2391 2532
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2392
-		if ($step_progress['current'] > $step_progress['total'])
2393
-			$upcontext['substep_progress'] = 99.9;
2394
-		else
2395
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2533
+		if ($step_progress['current'] > $step_progress['total']) {
2534
+					$upcontext['substep_progress'] = 99.9;
2535
+		} else {
2536
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2537
+		}
2396 2538
 
2397 2539
 		// Make it nicely rounded.
2398 2540
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2399 2541
 	}
2400 2542
 
2401 2543
 	// If this is XML we just exit right away!
2402
-	if (isset($_GET['xml']))
2403
-		return upgradeExit();
2544
+	if (isset($_GET['xml'])) {
2545
+			return upgradeExit();
2546
+	}
2404 2547
 
2405 2548
 	// We're going to pause after this!
2406 2549
 	$upcontext['pause'] = true;
@@ -2408,13 +2551,15 @@  discard block
 block discarded – undo
2408 2551
 	$upcontext['query_string'] = '';
2409 2552
 	foreach ($_GET as $k => $v)
2410 2553
 	{
2411
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2412
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2554
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2555
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2556
+		}
2413 2557
 	}
2414 2558
 
2415 2559
 	// Custom warning?
2416
-	if (!empty($custom_warning))
2417
-		$upcontext['custom_warning'] = $custom_warning;
2560
+	if (!empty($custom_warning)) {
2561
+			$upcontext['custom_warning'] = $custom_warning;
2562
+	}
2418 2563
 
2419 2564
 	upgradeExit();
2420 2565
 }
@@ -2429,25 +2574,26 @@  discard block
 block discarded – undo
2429 2574
 	ob_implicit_flush(true);
2430 2575
 	@set_time_limit(600);
2431 2576
 
2432
-	if (!isset($_SERVER['argv']))
2433
-		$_SERVER['argv'] = array();
2577
+	if (!isset($_SERVER['argv'])) {
2578
+			$_SERVER['argv'] = array();
2579
+	}
2434 2580
 	$_GET['maint'] = 1;
2435 2581
 
2436 2582
 	foreach ($_SERVER['argv'] as $i => $arg)
2437 2583
 	{
2438
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2439
-			$_GET['lang'] = $match[1];
2440
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2441
-			continue;
2442
-		elseif ($arg == '--no-maintenance')
2443
-			$_GET['maint'] = 0;
2444
-		elseif ($arg == '--debug')
2445
-			$is_debug = true;
2446
-		elseif ($arg == '--backup')
2447
-			$_POST['backup'] = 1;
2448
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2449
-			$_GET['conv'] = 1;
2450
-		elseif ($i != 0)
2584
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2585
+					$_GET['lang'] = $match[1];
2586
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2587
+					continue;
2588
+		} elseif ($arg == '--no-maintenance') {
2589
+					$_GET['maint'] = 0;
2590
+		} elseif ($arg == '--debug') {
2591
+					$is_debug = true;
2592
+		} elseif ($arg == '--backup') {
2593
+					$_POST['backup'] = 1;
2594
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2595
+					$_GET['conv'] = 1;
2596
+		} elseif ($i != 0)
2451 2597
 		{
2452 2598
 			echo 'SMF Command-line Upgrader
2453 2599
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2461,10 +2607,12 @@  discard block
 block discarded – undo
2461 2607
 		}
2462 2608
 	}
2463 2609
 
2464
-	if (!php_version_check())
2465
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2466
-	if (!db_version_check())
2467
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2610
+	if (!php_version_check()) {
2611
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2612
+	}
2613
+	if (!db_version_check()) {
2614
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2615
+	}
2468 2616
 
2469 2617
 	// Do some checks to make sure they have proper privileges
2470 2618
 	db_extend('packages');
@@ -2479,34 +2627,39 @@  discard block
 block discarded – undo
2479 2627
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2480 2628
 
2481 2629
 	// Sorry... we need CREATE, ALTER and DROP
2482
-	if (!$create || !$alter || !$drop)
2483
-		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);
2630
+	if (!$create || !$alter || !$drop) {
2631
+			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);
2632
+	}
2484 2633
 
2485 2634
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2486 2635
 		&& @file_exists($sourcedir . '/QueryString.php')
2487 2636
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2488
-	if (!$check && !isset($modSettings['smfVersion']))
2489
-		print_error('Error: Some files are missing or out-of-date.', true);
2637
+	if (!$check && !isset($modSettings['smfVersion'])) {
2638
+			print_error('Error: Some files are missing or out-of-date.', true);
2639
+	}
2490 2640
 
2491 2641
 	// Do a quick version spot check.
2492 2642
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2493 2643
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2494
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2495
-		print_error('Error: Some files have not yet been updated properly.');
2644
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2645
+			print_error('Error: Some files have not yet been updated properly.');
2646
+	}
2496 2647
 
2497 2648
 	// Make sure Settings.php is writable.
2498 2649
 	quickFileWritable($boarddir . '/Settings.php');
2499
-	if (!is_writable($boarddir . '/Settings.php'))
2500
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2650
+	if (!is_writable($boarddir . '/Settings.php')) {
2651
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2652
+	}
2501 2653
 
2502 2654
 	// Make sure Settings_bak.php is writable.
2503 2655
 	quickFileWritable($boarddir . '/Settings_bak.php');
2504
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2505
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2656
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2657
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2658
+	}
2506 2659
 
2507
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2508
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2509
-	elseif (isset($modSettings['agreement']))
2660
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2661
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2662
+	} elseif (isset($modSettings['agreement']))
2510 2663
 	{
2511 2664
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2512 2665
 		fwrite($fp, $modSettings['agreement']);
@@ -2516,36 +2669,42 @@  discard block
 block discarded – undo
2516 2669
 	// Make sure Themes is writable.
2517 2670
 	quickFileWritable($modSettings['theme_dir']);
2518 2671
 
2519
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2520
-		print_error('Error: Unable to obtain write access to "Themes".');
2672
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2673
+			print_error('Error: Unable to obtain write access to "Themes".');
2674
+	}
2521 2675
 
2522 2676
 	// Make sure cache directory exists and is writable!
2523 2677
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2524
-	if (!file_exists($cachedir_temp))
2525
-		@mkdir($cachedir_temp);
2678
+	if (!file_exists($cachedir_temp)) {
2679
+			@mkdir($cachedir_temp);
2680
+	}
2526 2681
 
2527 2682
 	// Make sure the cache temp dir is writable.
2528 2683
 	quickFileWritable($cachedir_temp);
2529 2684
 
2530
-	if (!is_writable($cachedir_temp))
2531
-		print_error('Error: Unable to obtain write access to "cache".', true);
2685
+	if (!is_writable($cachedir_temp)) {
2686
+			print_error('Error: Unable to obtain write access to "cache".', true);
2687
+	}
2532 2688
 
2533 2689
 	// Make sure db_last_error.php is writable.
2534 2690
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2535
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2536
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2691
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2692
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2693
+	}
2537 2694
 
2538
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2539
-		print_error('Error: Unable to find language files!', true);
2540
-	else
2695
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2696
+			print_error('Error: Unable to find language files!', true);
2697
+	} else
2541 2698
 	{
2542 2699
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2543 2700
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2544 2701
 
2545
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2546
-			print_error('Error: Language files out of date.', true);
2547
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2548
-			print_error('Error: Install language is missing for selected language.', true);
2702
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2703
+					print_error('Error: Language files out of date.', true);
2704
+		}
2705
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2706
+					print_error('Error: Install language is missing for selected language.', true);
2707
+		}
2549 2708
 
2550 2709
 		// Otherwise include it!
2551 2710
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2565,8 +2724,9 @@  discard block
 block discarded – undo
2565 2724
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2566 2725
 
2567 2726
 	// Done it already?
2568
-	if (!empty($_POST['utf8_done']))
2569
-		return true;
2727
+	if (!empty($_POST['utf8_done'])) {
2728
+			return true;
2729
+	}
2570 2730
 
2571 2731
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2572 2732
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2579,8 +2739,7 @@  discard block
 block discarded – undo
2579 2739
 		);
2580 2740
 
2581 2741
 		return true;
2582
-	}
2583
-	else
2742
+	} else
2584 2743
 	{
2585 2744
 		$upcontext['page_title'] = $txt['converting_utf8'];
2586 2745
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2624,8 +2783,9 @@  discard block
 block discarded – undo
2624 2783
 			)
2625 2784
 		);
2626 2785
 		$db_charsets = array();
2627
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2628
-			$db_charsets[] = $row['Charset'];
2786
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2787
+					$db_charsets[] = $row['Charset'];
2788
+		}
2629 2789
 
2630 2790
 		$smcFunc['db_free_result']($request);
2631 2791
 
@@ -2661,13 +2821,15 @@  discard block
 block discarded – undo
2661 2821
 		// If there's a fulltext index, we need to drop it first...
2662 2822
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2663 2823
 		{
2664
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2665
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2824
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2825
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2666 2826
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2827
+			}
2667 2828
 			$smcFunc['db_free_result']($request);
2668 2829
 
2669
-			if (isset($upcontext['fulltext_index']))
2670
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2830
+			if (isset($upcontext['fulltext_index'])) {
2831
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2832
+			}
2671 2833
 		}
2672 2834
 
2673 2835
 		// Drop it and make a note...
@@ -2857,8 +3019,9 @@  discard block
 block discarded – undo
2857 3019
 			$replace = '%field%';
2858 3020
 
2859 3021
 			// Build a huge REPLACE statement...
2860
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2861
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3022
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3023
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3024
+			}
2862 3025
 		}
2863 3026
 
2864 3027
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2868,9 +3031,10 @@  discard block
 block discarded – undo
2868 3031
 		$upcontext['table_count'] = count($queryTables);
2869 3032
 
2870 3033
 		// What ones have we already done?
2871
-		foreach ($queryTables as $id => $table)
2872
-			if ($id < $_GET['substep'])
3034
+		foreach ($queryTables as $id => $table) {
3035
+					if ($id < $_GET['substep'])
2873 3036
 				$upcontext['previous_tables'][] = $table;
3037
+		}
2874 3038
 
2875 3039
 		$upcontext['cur_table_num'] = $_GET['substep'];
2876 3040
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2907,8 +3071,9 @@  discard block
 block discarded – undo
2907 3071
 			nextSubstep($substep);
2908 3072
 
2909 3073
 			// Just to make sure it doesn't time out.
2910
-			if (function_exists('apache_reset_timeout'))
2911
-				@apache_reset_timeout();
3074
+			if (function_exists('apache_reset_timeout')) {
3075
+							@apache_reset_timeout();
3076
+			}
2912 3077
 
2913 3078
 			$table_charsets = array();
2914 3079
 
@@ -2931,8 +3096,9 @@  discard block
 block discarded – undo
2931 3096
 
2932 3097
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2933 3098
 						if ($charset != 'utf8') {
2934
-							if (!isset($table_charsets[$charset]))
2935
-								$table_charsets[$charset] = array();
3099
+							if (!isset($table_charsets[$charset])) {
3100
+															$table_charsets[$charset] = array();
3101
+							}
2936 3102
 
2937 3103
 							$table_charsets[$charset][] = $column_info;
2938 3104
 						}
@@ -2973,10 +3139,11 @@  discard block
 block discarded – undo
2973 3139
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2974 3140
 				{
2975 3141
 					$update = '';
2976
-					foreach ($table_charsets as $charset => $columns)
2977
-						foreach ($columns as $column)
3142
+					foreach ($table_charsets as $charset => $columns) {
3143
+											foreach ($columns as $column)
2978 3144
 							$update .= '
2979 3145
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3146
+					}
2980 3147
 
2981 3148
 					$smcFunc['db_query']('', '
2982 3149
 						UPDATE {raw:table_name}
@@ -3001,8 +3168,9 @@  discard block
 block discarded – undo
3001 3168
 			// Now do the actual conversion (if still needed).
3002 3169
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
3003 3170
 			{
3004
-				if ($command_line)
3005
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3171
+				if ($command_line) {
3172
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3173
+				}
3006 3174
 
3007 3175
 				$smcFunc['db_query']('', '
3008 3176
 					ALTER TABLE {raw:table_name}
@@ -3012,12 +3180,14 @@  discard block
 block discarded – undo
3012 3180
 					)
3013 3181
 				);
3014 3182
 
3015
-				if ($command_line)
3016
-					echo " done.\n";
3183
+				if ($command_line) {
3184
+									echo " done.\n";
3185
+				}
3017 3186
 			}
3018 3187
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3019
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
3020
-				return upgradeExit();
3188
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3189
+							return upgradeExit();
3190
+			}
3021 3191
 		}
3022 3192
 
3023 3193
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3046,8 +3216,8 @@  discard block
 block discarded – undo
3046 3216
 		);
3047 3217
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3048 3218
 		{
3049
-			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)
3050
-				$smcFunc['db_query']('', '
3219
+			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) {
3220
+							$smcFunc['db_query']('', '
3051 3221
 					UPDATE {db_prefix}log_actions
3052 3222
 					SET extra = {string:extra}
3053 3223
 					WHERE id_action = {int:current_action}',
@@ -3056,6 +3226,7 @@  discard block
 block discarded – undo
3056 3226
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3057 3227
 					)
3058 3228
 				);
3229
+			}
3059 3230
 		}
3060 3231
 		$smcFunc['db_free_result']($request);
3061 3232
 
@@ -3077,15 +3248,17 @@  discard block
 block discarded – undo
3077 3248
 	// First thing's first - did we already do this?
3078 3249
 	if (!empty($modSettings['json_done']))
3079 3250
 	{
3080
-		if ($command_line)
3081
-			return DeleteUpgrade();
3082
-		else
3083
-			return true;
3251
+		if ($command_line) {
3252
+					return DeleteUpgrade();
3253
+		} else {
3254
+					return true;
3255
+		}
3084 3256
 	}
3085 3257
 
3086 3258
 	// Done it already - js wise?
3087
-	if (!empty($_POST['json_done']))
3088
-		return true;
3259
+	if (!empty($_POST['json_done'])) {
3260
+			return true;
3261
+	}
3089 3262
 
3090 3263
 	// List of tables affected by this function
3091 3264
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3117,12 +3290,14 @@  discard block
 block discarded – undo
3117 3290
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3118 3291
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3119 3292
 
3120
-	foreach ($keys as $id => $table)
3121
-		if ($id < $_GET['substep'])
3293
+	foreach ($keys as $id => $table) {
3294
+			if ($id < $_GET['substep'])
3122 3295
 			$upcontext['previous_tables'][] = $table;
3296
+	}
3123 3297
 
3124
-	if ($command_line)
3125
-		echo 'Converting data from serialize() to json_encode().';
3298
+	if ($command_line) {
3299
+			echo 'Converting data from serialize() to json_encode().';
3300
+	}
3126 3301
 
3127 3302
 	if (!$support_js || isset($_GET['xml']))
3128 3303
 	{
@@ -3162,8 +3337,9 @@  discard block
 block discarded – undo
3162 3337
 
3163 3338
 				// Loop through and fix these...
3164 3339
 				$new_settings = array();
3165
-				if ($command_line)
3166
-					echo "\n" . 'Fixing some settings...';
3340
+				if ($command_line) {
3341
+									echo "\n" . 'Fixing some settings...';
3342
+				}
3167 3343
 
3168 3344
 				foreach ($serialized_settings as $var)
3169 3345
 				{
@@ -3171,22 +3347,24 @@  discard block
 block discarded – undo
3171 3347
 					{
3172 3348
 						// Attempt to unserialize the setting
3173 3349
 						$temp = @safe_unserialize($modSettings[$var]);
3174
-						if (!$temp && $command_line)
3175
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3176
-						elseif ($temp !== false)
3177
-							$new_settings[$var] = json_encode($temp);
3350
+						if (!$temp && $command_line) {
3351
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3352
+						} elseif ($temp !== false) {
3353
+													$new_settings[$var] = json_encode($temp);
3354
+						}
3178 3355
 					}
3179 3356
 				}
3180 3357
 
3181 3358
 				// Update everything at once
3182
-				if (!function_exists('cache_put_data'))
3183
-					require_once($sourcedir . '/Load.php');
3359
+				if (!function_exists('cache_put_data')) {
3360
+									require_once($sourcedir . '/Load.php');
3361
+				}
3184 3362
 				updateSettings($new_settings, true);
3185 3363
 
3186
-				if ($command_line)
3187
-					echo ' done.';
3188
-			}
3189
-			elseif ($table == 'themes')
3364
+				if ($command_line) {
3365
+									echo ' done.';
3366
+				}
3367
+			} elseif ($table == 'themes')
3190 3368
 			{
3191 3369
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3192 3370
 				$query = $smcFunc['db_query']('', '
@@ -3205,10 +3383,11 @@  discard block
 block discarded – undo
3205 3383
 
3206 3384
 						if ($command_line)
3207 3385
 						{
3208
-							if ($temp === false)
3209
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3210
-							else
3211
-								echo "\n" . 'Fixing admin preferences...';
3386
+							if ($temp === false) {
3387
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3388
+							} else {
3389
+															echo "\n" . 'Fixing admin preferences...';
3390
+							}
3212 3391
 						}
3213 3392
 
3214 3393
 						if ($temp !== false)
@@ -3230,15 +3409,15 @@  discard block
 block discarded – undo
3230 3409
 								)
3231 3410
 							);
3232 3411
 
3233
-							if ($command_line)
3234
-								echo ' done.';
3412
+							if ($command_line) {
3413
+															echo ' done.';
3414
+							}
3235 3415
 						}
3236 3416
 					}
3237 3417
 
3238 3418
 					$smcFunc['db_free_result']($query);
3239 3419
 				}
3240
-			}
3241
-			else
3420
+			} else
3242 3421
 			{
3243 3422
 				// First item is always the key...
3244 3423
 				$key = $info[0];
@@ -3249,8 +3428,7 @@  discard block
 block discarded – undo
3249 3428
 				{
3250 3429
 					$col_select = $info[1];
3251 3430
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3252
-				}
3253
-				else
3431
+				} else
3254 3432
 				{
3255 3433
 					$col_select = implode(', ', $info);
3256 3434
 				}
@@ -3283,8 +3461,7 @@  discard block
 block discarded – undo
3283 3461
 								if ($temp === false && $command_line)
3284 3462
 								{
3285 3463
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3286
-								}
3287
-								else
3464
+								} else
3288 3465
 								{
3289 3466
 									$row[$col] = json_encode($temp);
3290 3467
 
@@ -3309,16 +3486,18 @@  discard block
 block discarded – undo
3309 3486
 						}
3310 3487
 					}
3311 3488
 
3312
-					if ($command_line)
3313
-						echo ' done.';
3489
+					if ($command_line) {
3490
+											echo ' done.';
3491
+					}
3314 3492
 
3315 3493
 					// Free up some memory...
3316 3494
 					$smcFunc['db_free_result']($query);
3317 3495
 				}
3318 3496
 			}
3319 3497
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3320
-			if (isset($_GET['xml']))
3321
-				return upgradeExit();
3498
+			if (isset($_GET['xml'])) {
3499
+							return upgradeExit();
3500
+			}
3322 3501
 		}
3323 3502
 
3324 3503
 		if ($command_line)
@@ -3333,8 +3512,9 @@  discard block
 block discarded – undo
3333 3512
 
3334 3513
 		$_GET['substep'] = 0;
3335 3514
 		// Make sure we move on!
3336
-		if ($command_line)
3337
-			return DeleteUpgrade();
3515
+		if ($command_line) {
3516
+					return DeleteUpgrade();
3517
+		}
3338 3518
 
3339 3519
 		return true;
3340 3520
 	}
@@ -3391,14 +3571,16 @@  discard block
 block discarded – undo
3391 3571
 	global $upcontext, $txt, $settings;
3392 3572
 
3393 3573
 	// Don't call me twice!
3394
-	if (!empty($upcontext['chmod_called']))
3395
-		return;
3574
+	if (!empty($upcontext['chmod_called'])) {
3575
+			return;
3576
+	}
3396 3577
 
3397 3578
 	$upcontext['chmod_called'] = true;
3398 3579
 
3399 3580
 	// Nothing?
3400
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3401
-		return;
3581
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3582
+			return;
3583
+	}
3402 3584
 
3403 3585
 	// Was it a problem with Windows?
3404 3586
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3430,11 +3612,12 @@  discard block
 block discarded – undo
3430 3612
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3431 3613
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3432 3614
 
3433
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3434
-		echo '
3615
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3616
+			echo '
3435 3617
 					content.write(\'<hr>\n\t\t\t\');
3436 3618
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3437 3619
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3620
+	}
3438 3621
 
3439 3622
 	echo '
3440 3623
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3442,17 +3625,19 @@  discard block
 block discarded – undo
3442 3625
 				}
3443 3626
 			</script>';
3444 3627
 
3445
-	if (!empty($upcontext['chmod']['ftp_error']))
3446
-		echo '
3628
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3629
+			echo '
3447 3630
 			<div class="error_message red">
3448 3631
 				', $txt['upgrade_ftp_error'], '<br><br>
3449 3632
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3450 3633
 			</div>
3451 3634
 			<br>';
3635
+	}
3452 3636
 
3453
-	if (empty($upcontext['chmod_in_form']))
3454
-		echo '
3637
+	if (empty($upcontext['chmod_in_form'])) {
3638
+			echo '
3455 3639
 	<form action="', $upcontext['form_url'], '" method="post">';
3640
+	}
3456 3641
 
3457 3642
 	echo '
3458 3643
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3487,10 +3672,11 @@  discard block
 block discarded – undo
3487 3672
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3488 3673
 	</div>';
3489 3674
 
3490
-	if (empty($upcontext['chmod_in_form']))
3491
-		echo '
3675
+	if (empty($upcontext['chmod_in_form'])) {
3676
+			echo '
3492 3677
 	</form>';
3493
-}
3678
+	}
3679
+	}
3494 3680
 
3495 3681
 function template_upgrade_above()
3496 3682
 {
@@ -3550,9 +3736,10 @@  discard block
 block discarded – undo
3550 3736
 				<h2>', $txt['upgrade_progress'], '</h2>
3551 3737
 				<ul>';
3552 3738
 
3553
-	foreach ($upcontext['steps'] as $num => $step)
3554
-		echo '
3739
+	foreach ($upcontext['steps'] as $num => $step) {
3740
+			echo '
3555 3741
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3742
+	}
3556 3743
 
3557 3744
 	echo '
3558 3745
 					</ul>
@@ -3565,8 +3752,8 @@  discard block
 block discarded – undo
3565 3752
 				</div>
3566 3753
 			</div>';
3567 3754
 
3568
-	if (isset($upcontext['step_progress']))
3569
-		echo '
3755
+	if (isset($upcontext['step_progress'])) {
3756
+			echo '
3570 3757
 				<br>
3571 3758
 				<br>
3572 3759
 				<div id="progress_bar_step">
@@ -3575,6 +3762,7 @@  discard block
 block discarded – undo
3575 3762
 						<span>', $txt['upgrade_step_progress'], '</span>
3576 3763
 					</div>
3577 3764
 				</div>';
3765
+	}
3578 3766
 
3579 3767
 	echo '
3580 3768
 				<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>
@@ -3605,32 +3793,36 @@  discard block
 block discarded – undo
3605 3793
 {
3606 3794
 	global $upcontext, $txt;
3607 3795
 
3608
-	if (!empty($upcontext['pause']))
3609
-		echo '
3796
+	if (!empty($upcontext['pause'])) {
3797
+			echo '
3610 3798
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3611 3799
 
3612 3800
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3613 3801
 								<h3>
3614 3802
 									', $txt['upgrade_paused_overload'], '
3615 3803
 								</h3>';
3804
+	}
3616 3805
 
3617
-	if (!empty($upcontext['custom_warning']))
3618
-		echo '
3806
+	if (!empty($upcontext['custom_warning'])) {
3807
+			echo '
3619 3808
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3620 3809
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3621 3810
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3622 3811
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3623 3812
 								</div>';
3813
+	}
3624 3814
 
3625 3815
 	echo '
3626 3816
 								<div class="righttext" style="margin: 1ex;">';
3627 3817
 
3628
-	if (!empty($upcontext['continue']))
3629
-		echo '
3818
+	if (!empty($upcontext['continue'])) {
3819
+			echo '
3630 3820
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3631
-	if (!empty($upcontext['skip']))
3632
-		echo '
3821
+	}
3822
+	if (!empty($upcontext['skip'])) {
3823
+			echo '
3633 3824
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3825
+	}
3634 3826
 
3635 3827
 	echo '
3636 3828
 								</div>
@@ -3680,11 +3872,12 @@  discard block
 block discarded – undo
3680 3872
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3681 3873
 	<smf>';
3682 3874
 
3683
-	if (!empty($upcontext['get_data']))
3684
-		foreach ($upcontext['get_data'] as $k => $v)
3875
+	if (!empty($upcontext['get_data'])) {
3876
+			foreach ($upcontext['get_data'] as $k => $v)
3685 3877
 			echo '
3686 3878
 		<get key="', $k, '">', $v, '</get>';
3687
-}
3879
+	}
3880
+	}
3688 3881
 
3689 3882
 function template_xml_below()
3690 3883
 {
@@ -3725,8 +3918,8 @@  discard block
 block discarded – undo
3725 3918
 	template_chmod();
3726 3919
 
3727 3920
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3728
-	if ($upcontext['is_large_forum'])
3729
-		echo '
3921
+	if ($upcontext['is_large_forum']) {
3922
+			echo '
3730 3923
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3731 3924
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3732 3925
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3734,10 +3927,11 @@  discard block
 block discarded – undo
3734 3927
 				', $txt['upgrade_warning_lots_data'], '
3735 3928
 			</div>
3736 3929
 		</div>';
3930
+	}
3737 3931
 
3738 3932
 	// A warning message?
3739
-	if (!empty($upcontext['warning']))
3740
-		echo '
3933
+	if (!empty($upcontext['warning'])) {
3934
+			echo '
3741 3935
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3742 3936
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3743 3937
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3745,6 +3939,7 @@  discard block
 block discarded – undo
3745 3939
 				', $upcontext['warning'], '
3746 3940
 			</div>
3747 3941
 		</div>';
3942
+	}
3748 3943
 
3749 3944
 	// Paths are incorrect?
3750 3945
 	echo '
@@ -3760,20 +3955,22 @@  discard block
 block discarded – undo
3760 3955
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3761 3956
 	{
3762 3957
 		$ago = time() - $upcontext['started'];
3763
-		if ($ago < 60)
3764
-			$ago = $ago . ' seconds';
3765
-		elseif ($ago < 3600)
3766
-			$ago = (int) ($ago / 60) . ' minutes';
3767
-		else
3768
-			$ago = (int) ($ago / 3600) . ' hours';
3958
+		if ($ago < 60) {
3959
+					$ago = $ago . ' seconds';
3960
+		} elseif ($ago < 3600) {
3961
+					$ago = (int) ($ago / 60) . ' minutes';
3962
+		} else {
3963
+					$ago = (int) ($ago / 3600) . ' hours';
3964
+		}
3769 3965
 
3770 3966
 		$active = time() - $upcontext['updated'];
3771
-		if ($active < 60)
3772
-			$updated = $active . ' seconds';
3773
-		elseif ($active < 3600)
3774
-			$updated = (int) ($active / 60) . ' minutes';
3775
-		else
3776
-			$updated = (int) ($active / 3600) . ' hours';
3967
+		if ($active < 60) {
3968
+					$updated = $active . ' seconds';
3969
+		} elseif ($active < 3600) {
3970
+					$updated = (int) ($active / 60) . ' minutes';
3971
+		} else {
3972
+					$updated = (int) ($active / 3600) . ' hours';
3973
+		}
3777 3974
 
3778 3975
 		echo '
3779 3976
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3782,16 +3979,18 @@  discard block
 block discarded – undo
3782 3979
 			<div style="padding-left: 6ex;">
3783 3980
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3784 3981
 
3785
-		if ($active < 600)
3786
-			echo '
3982
+		if ($active < 600) {
3983
+					echo '
3787 3984
 				', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '';
3985
+		}
3788 3986
 
3789
-		if ($active > $upcontext['inactive_timeout'])
3790
-			echo '
3987
+		if ($active > $upcontext['inactive_timeout']) {
3988
+					echo '
3791 3989
 				<br><br>',$txt['upgrade_run'], '';
3792
-		else
3793
-			echo '
3990
+		} else {
3991
+					echo '
3794 3992
 				<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!');
3993
+		}
3795 3994
 
3796 3995
 		echo '
3797 3996
 			</div>
@@ -3807,9 +4006,10 @@  discard block
 block discarded – undo
3807 4006
 					<td>
3808 4007
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3809 4008
 
3810
-	if (!empty($upcontext['username_incorrect']))
3811
-		echo '
4009
+	if (!empty($upcontext['username_incorrect'])) {
4010
+			echo '
3812 4011
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>';
4012
+	}
3813 4013
 
3814 4014
 	echo '
3815 4015
 					</td>
@@ -3820,9 +4020,10 @@  discard block
 block discarded – undo
3820 4020
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3821 4021
 						<input type="hidden" name="hash_passwrd" value="">';
3822 4022
 
3823
-	if (!empty($upcontext['password_failed']))
3824
-		echo '
4023
+	if (!empty($upcontext['password_failed'])) {
4024
+			echo '
3825 4025
 						<div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>';
4026
+	}
3826 4027
 
3827 4028
 	echo '
3828 4029
 					</td>
@@ -3893,8 +4094,8 @@  discard block
 block discarded – undo
3893 4094
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3894 4095
 
3895 4096
 	// Warning message?
3896
-	if (!empty($upcontext['upgrade_options_warning']))
3897
-		echo '
4097
+	if (!empty($upcontext['upgrade_options_warning'])) {
4098
+			echo '
3898 4099
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3899 4100
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3900 4101
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3902,6 +4103,7 @@  discard block
 block discarded – undo
3902 4103
 				', $upcontext['upgrade_options_warning'], '
3903 4104
 			</div>
3904 4105
 		</div>';
4106
+	}
3905 4107
 
3906 4108
 	echo '
3907 4109
 				<table>
@@ -3944,8 +4146,8 @@  discard block
 block discarded – undo
3944 4146
 						</td>
3945 4147
 					</tr>';
3946 4148
 
3947
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3948
-		echo '
4149
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4150
+			echo '
3949 4151
 					<tr valign="top">
3950 4152
 						<td width="2%">
3951 4153
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3954,6 +4156,7 @@  discard block
 block discarded – undo
3954 4156
 							<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3955 4157
 						</td>
3956 4158
 					</tr>';
4159
+	}
3957 4160
 
3958 4161
 	echo '
3959 4162
 					<tr valign="top">
@@ -3991,10 +4194,11 @@  discard block
 block discarded – undo
3991 4194
 			</div>';
3992 4195
 
3993 4196
 	// Dont any tables so far?
3994
-	if (!empty($upcontext['previous_tables']))
3995
-		foreach ($upcontext['previous_tables'] as $table)
4197
+	if (!empty($upcontext['previous_tables'])) {
4198
+			foreach ($upcontext['previous_tables'] as $table)
3996 4199
 			echo '
3997 4200
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4201
+	}
3998 4202
 
3999 4203
 	echo '
4000 4204
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4031,12 +4235,13 @@  discard block
 block discarded – undo
4031 4235
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4032 4236
 
4033 4237
 		// If debug flood the screen.
4034
-		if ($is_debug)
4035
-			echo '
4238
+		if ($is_debug) {
4239
+					echo '
4036 4240
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4037 4241
 
4038 4242
 				if (document.getElementById(\'debug_section\').scrollHeight)
4039 4243
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4244
+		}
4040 4245
 
4041 4246
 		echo '
4042 4247
 				// Get the next update...
@@ -4069,8 +4274,9 @@  discard block
 block discarded – undo
4069 4274
 {
4070 4275
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4071 4276
 
4072
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4073
-		$is_debug = true;
4277
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4278
+			$is_debug = true;
4279
+	}
4074 4280
 
4075 4281
 	echo '
4076 4282
 		<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4085,8 +4291,9 @@  discard block
 block discarded – undo
4085 4291
 	{
4086 4292
 		foreach ($upcontext['actioned_items'] as $num => $item)
4087 4293
 		{
4088
-			if ($num != 0)
4089
-				echo ' Successful!';
4294
+			if ($num != 0) {
4295
+							echo ' Successful!';
4296
+			}
4090 4297
 			echo '<br>' . $item;
4091 4298
 		}
4092 4299
 		if (!empty($upcontext['changes_complete']))
@@ -4099,28 +4306,32 @@  discard block
 block discarded – undo
4099 4306
 				$seconds = intval($active % 60);
4100 4307
 
4101 4308
 				$totalTime = '';
4102
-				if ($hours > 0)
4103
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4104
-				if ($minutes > 0)
4105
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4106
-				if ($seconds > 0)
4107
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4309
+				if ($hours > 0) {
4310
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4311
+				}
4312
+				if ($minutes > 0) {
4313
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4314
+				}
4315
+				if ($seconds > 0) {
4316
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4317
+				}
4108 4318
 			}
4109 4319
 
4110
-			if ($is_debug && !empty($totalTime))
4111
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4112
-			else
4113
-				echo ' Successful!<br><br>';
4320
+			if ($is_debug && !empty($totalTime)) {
4321
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4322
+			} else {
4323
+							echo ' Successful!<br><br>';
4324
+			}
4114 4325
 
4115 4326
 			echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>';
4116 4327
 		}
4117
-	}
4118
-	else
4328
+	} else
4119 4329
 	{
4120 4330
 		// Tell them how many files we have in total.
4121
-		if ($upcontext['file_count'] > 1)
4122
-			echo '
4331
+		if ($upcontext['file_count'] > 1) {
4332
+					echo '
4123 4333
 		<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4334
+		}
4124 4335
 
4125 4336
 		echo '
4126 4337
 		<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>
@@ -4136,19 +4347,23 @@  discard block
 block discarded – undo
4136 4347
 				$seconds = intval($active % 60);
4137 4348
 
4138 4349
 				$totalTime = '';
4139
-				if ($hours > 0)
4140
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4141
-				if ($minutes > 0)
4142
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4143
-				if ($seconds > 0)
4144
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4350
+				if ($hours > 0) {
4351
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4352
+				}
4353
+				if ($minutes > 0) {
4354
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4355
+				}
4356
+				if ($seconds > 0) {
4357
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4358
+				}
4145 4359
 			}
4146 4360
 
4147 4361
 			echo '
4148 4362
 			<br><span id="upgradeCompleted">';
4149 4363
 
4150
-			if (!empty($totalTime))
4151
-				echo 'Completed in ', $totalTime, '<br>';
4364
+			if (!empty($totalTime)) {
4365
+							echo 'Completed in ', $totalTime, '<br>';
4366
+			}
4152 4367
 
4153 4368
 			echo '</span>
4154 4369
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4185,9 +4400,10 @@  discard block
 block discarded – undo
4185 4400
 			var getData = "";
4186 4401
 			var debugItems = ', $upcontext['debug_items'], ';';
4187 4402
 
4188
-		if ($is_debug)
4189
-			echo '
4403
+		if ($is_debug) {
4404
+					echo '
4190 4405
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4406
+		}
4191 4407
 
4192 4408
 		echo '
4193 4409
 			function getNextItem()
@@ -4227,9 +4443,10 @@  discard block
 block discarded – undo
4227 4443
 						document.getElementById("error_block").style.display = "";
4228 4444
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4229 4445
 
4230
-	if ($is_debug)
4231
-		echo '
4446
+	if ($is_debug) {
4447
+			echo '
4232 4448
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4449
+	}
4233 4450
 
4234 4451
 	echo '
4235 4452
 					}
@@ -4250,9 +4467,10 @@  discard block
 block discarded – undo
4250 4467
 						document.getElementById("error_block").style.display = "";
4251 4468
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4252 4469
 
4253
-	if ($is_debug)
4254
-		echo '
4470
+	if ($is_debug) {
4471
+			echo '
4255 4472
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4473
+	}
4256 4474
 
4257 4475
 	echo '
4258 4476
 					}
@@ -4311,8 +4529,8 @@  discard block
 block discarded – undo
4311 4529
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4312 4530
 				{';
4313 4531
 
4314
-		if ($is_debug)
4315
-			echo '
4532
+		if ($is_debug) {
4533
+					echo '
4316 4534
 					document.getElementById(\'debug_section\').style.display = "none";
4317 4535
 
4318 4536
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4330,6 +4548,7 @@  discard block
 block discarded – undo
4330 4548
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4331 4549
 
4332 4550
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4551
+		}
4333 4552
 
4334 4553
 		echo '
4335 4554
 
@@ -4337,9 +4556,10 @@  discard block
 block discarded – undo
4337 4556
 					document.getElementById(\'contbutt\').disabled = 0;
4338 4557
 					document.getElementById(\'database_done\').value = 1;';
4339 4558
 
4340
-		if ($upcontext['file_count'] > 1)
4341
-			echo '
4559
+		if ($upcontext['file_count'] > 1) {
4560
+					echo '
4342 4561
 					document.getElementById(\'info1\').style.display = "none";';
4562
+		}
4343 4563
 
4344 4564
 		echo '
4345 4565
 					document.getElementById(\'info2\').style.display = "none";
@@ -4352,9 +4572,10 @@  discard block
 block discarded – undo
4352 4572
 					lastItem = 0;
4353 4573
 					prevFile = curFile;';
4354 4574
 
4355
-		if ($is_debug)
4356
-			echo '
4575
+		if ($is_debug) {
4576
+					echo '
4357 4577
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4578
+		}
4358 4579
 
4359 4580
 		echo '
4360 4581
 					getNextItem();
@@ -4362,8 +4583,8 @@  discard block
 block discarded – undo
4362 4583
 				}';
4363 4584
 
4364 4585
 		// If debug scroll the screen.
4365
-		if ($is_debug)
4366
-			echo '
4586
+		if ($is_debug) {
4587
+					echo '
4367 4588
 				if (iLastSubStepProgress == -1)
4368 4589
 				{
4369 4590
 					// Give it consistent dots.
@@ -4382,6 +4603,7 @@  discard block
 block discarded – undo
4382 4603
 
4383 4604
 				if (document.getElementById(\'debug_section\').scrollHeight)
4384 4605
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4606
+		}
4385 4607
 
4386 4608
 		echo '
4387 4609
 				// Update the page.
@@ -4442,9 +4664,10 @@  discard block
 block discarded – undo
4442 4664
 			}';
4443 4665
 
4444 4666
 		// Start things off assuming we've not errored.
4445
-		if (empty($upcontext['error_message']))
4446
-			echo '
4667
+		if (empty($upcontext['error_message'])) {
4668
+					echo '
4447 4669
 			getNextItem();';
4670
+		}
4448 4671
 
4449 4672
 		echo '
4450 4673
 		//# sourceURL=dynamicScript-dbch.js
@@ -4462,18 +4685,21 @@  discard block
 block discarded – undo
4462 4685
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4463 4686
 	<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>';
4464 4687
 
4465
-	if (!empty($upcontext['error_message']))
4466
-		echo '
4688
+	if (!empty($upcontext['error_message'])) {
4689
+			echo '
4467 4690
 	<error>', $upcontext['error_message'], '</error>';
4691
+	}
4468 4692
 
4469
-	if (!empty($upcontext['error_string']))
4470
-		echo '
4693
+	if (!empty($upcontext['error_string'])) {
4694
+			echo '
4471 4695
 	<sql>', $upcontext['error_string'], '</sql>';
4696
+	}
4472 4697
 
4473
-	if ($is_debug)
4474
-		echo '
4698
+	if ($is_debug) {
4699
+			echo '
4475 4700
 	<curtime>', time(), '</curtime>';
4476
-}
4701
+	}
4702
+	}
4477 4703
 
4478 4704
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4479 4705
 function template_convert_utf8()
@@ -4492,18 +4718,20 @@  discard block
 block discarded – undo
4492 4718
 			</div>';
4493 4719
 
4494 4720
 	// Done any tables so far?
4495
-	if (!empty($upcontext['previous_tables']))
4496
-		foreach ($upcontext['previous_tables'] as $table)
4721
+	if (!empty($upcontext['previous_tables'])) {
4722
+			foreach ($upcontext['previous_tables'] as $table)
4497 4723
 			echo '
4498 4724
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4725
+	}
4499 4726
 
4500 4727
 	echo '
4501 4728
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4502 4729
 
4503 4730
 	// If we dropped their index, let's let them know
4504
-	if ($upcontext['dropping_index'])
4505
-		echo '
4731
+	if ($upcontext['dropping_index']) {
4732
+			echo '
4506 4733
 				<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>';
4734
+	}
4507 4735
 
4508 4736
 	// Completion notification
4509 4737
 	echo '
@@ -4540,12 +4768,13 @@  discard block
 block discarded – undo
4540 4768
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4541 4769
 
4542 4770
 		// If debug flood the screen.
4543
-		if ($is_debug)
4544
-			echo '
4771
+		if ($is_debug) {
4772
+					echo '
4545 4773
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4546 4774
 
4547 4775
 				if (document.getElementById(\'debug_section\').scrollHeight)
4548 4776
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4777
+		}
4549 4778
 
4550 4779
 		echo '
4551 4780
 				// Get the next update...
@@ -4593,19 +4822,21 @@  discard block
 block discarded – undo
4593 4822
 			</div>';
4594 4823
 
4595 4824
 	// Dont any tables so far?
4596
-	if (!empty($upcontext['previous_tables']))
4597
-		foreach ($upcontext['previous_tables'] as $table)
4825
+	if (!empty($upcontext['previous_tables'])) {
4826
+			foreach ($upcontext['previous_tables'] as $table)
4598 4827
 			echo '
4599 4828
 			<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4829
+	}
4600 4830
 
4601 4831
 	echo '
4602 4832
 			<h3 id="current_tab_div">', $txt['upgrade_current_table'], ' &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4603 4833
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>';
4604 4834
 
4605 4835
 	// Try to make sure substep was reset.
4606
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4607
-		echo '
4836
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4837
+			echo '
4608 4838
 			<input type="hidden" name="substep" id="substep" value="0">';
4839
+	}
4609 4840
 
4610 4841
 	// Continue please!
4611 4842
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4638,12 +4869,13 @@  discard block
 block discarded – undo
4638 4869
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4639 4870
 
4640 4871
 		// If debug flood the screen.
4641
-		if ($is_debug)
4642
-			echo '
4872
+		if ($is_debug) {
4873
+					echo '
4643 4874
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4644 4875
 
4645 4876
 				if (document.getElementById(\'debug_section\').scrollHeight)
4646 4877
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4878
+		}
4647 4879
 
4648 4880
 		echo '
4649 4881
 				// Get the next update...
@@ -4679,8 +4911,8 @@  discard block
 block discarded – undo
4679 4911
 	<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4680 4912
 	<form action="', $boardurl, '/index.php">';
4681 4913
 
4682
-	if (!empty($upcontext['can_delete_script']))
4683
-		echo '
4914
+	if (!empty($upcontext['can_delete_script'])) {
4915
+			echo '
4684 4916
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> <em>', $txt['upgrade_delete_server'], '</em>
4685 4917
 			<script>
4686 4918
 				function doTheDelete(theCheck)
@@ -4692,6 +4924,7 @@  discard block
 block discarded – undo
4692 4924
 				}
4693 4925
 			</script>
4694 4926
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4927
+	}
4695 4928
 
4696 4929
 	$active = time() - $upcontext['started'];
4697 4930
 	$hours = floor($active / 3600);
@@ -4701,16 +4934,20 @@  discard block
 block discarded – undo
4701 4934
 	if ($is_debug)
4702 4935
 	{
4703 4936
 		$totalTime = '';
4704
-		if ($hours > 0)
4705
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4706
-		if ($minutes > 0)
4707
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4708
-		if ($seconds > 0)
4709
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4937
+		if ($hours > 0) {
4938
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4939
+		}
4940
+		if ($minutes > 0) {
4941
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4942
+		}
4943
+		if ($seconds > 0) {
4944
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4945
+		}
4710 4946
 	}
4711 4947
 
4712
-	if ($is_debug && !empty($totalTime))
4713
-		echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4948
+	if ($is_debug && !empty($totalTime)) {
4949
+			echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>';
4950
+	}
4714 4951
 
4715 4952
 	echo '<br>
4716 4953
 			', sprintf($txt['upgrade_problems'], 'http://simplemachines.org'), '<br>
@@ -4737,8 +4974,9 @@  discard block
 block discarded – undo
4737 4974
 
4738 4975
 	$current_substep = $_GET['substep'];
4739 4976
 
4740
-	if (empty($_GET['a']))
4741
-		$_GET['a'] = 0;
4977
+	if (empty($_GET['a'])) {
4978
+			$_GET['a'] = 0;
4979
+	}
4742 4980
 	$step_progress['name'] = 'Converting ips';
4743 4981
 	$step_progress['current'] = $_GET['a'];
4744 4982
 
@@ -4781,16 +5019,19 @@  discard block
 block discarded – undo
4781 5019
 				'empty' => '',
4782 5020
 				'limit' => $limit,
4783 5021
 		));
4784
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4785
-			$arIp[] = $row[$oldCol];
5022
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5023
+					$arIp[] = $row[$oldCol];
5024
+		}
4786 5025
 		$smcFunc['db_free_result']($request);
4787 5026
 
4788 5027
 		// Special case, null ip could keep us in a loop.
4789
-		if (is_null($arIp[0]))
4790
-			unset($arIp[0]);
5028
+		if (is_null($arIp[0])) {
5029
+					unset($arIp[0]);
5030
+		}
4791 5031
 
4792
-		if (empty($arIp))
4793
-			$is_done = true;
5032
+		if (empty($arIp)) {
5033
+					$is_done = true;
5034
+		}
4794 5035
 
4795 5036
 		$updates = array();
4796 5037
 		$cases = array();
@@ -4799,16 +5040,18 @@  discard block
 block discarded – undo
4799 5040
 		{
4800 5041
 			$arIp[$i] = trim($arIp[$i]);
4801 5042
 
4802
-			if (empty($arIp[$i]))
4803
-				continue;
5043
+			if (empty($arIp[$i])) {
5044
+							continue;
5045
+			}
4804 5046
 
4805 5047
 			$updates['ip' . $i] = $arIp[$i];
4806 5048
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4807 5049
 
4808 5050
 			if ($setSize > 0 && $i % $setSize === 0)
4809 5051
 			{
4810
-				if (count($updates) == 1)
4811
-					continue;
5052
+				if (count($updates) == 1) {
5053
+									continue;
5054
+				}
4812 5055
 
4813 5056
 				$updates['whereSet'] = array_values($updates);
4814 5057
 				$smcFunc['db_query']('', '
@@ -4842,8 +5085,7 @@  discard block
 block discarded – undo
4842 5085
 							'ip' => $ip
4843 5086
 					));
4844 5087
 				}
4845
-			}
4846
-			else
5088
+			} else
4847 5089
 			{
4848 5090
 				$updates['whereSet'] = array_values($updates);
4849 5091
 				$smcFunc['db_query']('', '
@@ -4857,9 +5099,9 @@  discard block
 block discarded – undo
4857 5099
 					$updates
4858 5100
 				);
4859 5101
 			}
5102
+		} else {
5103
+					$is_done = true;
4860 5104
 		}
4861
-		else
4862
-			$is_done = true;
4863 5105
 
4864 5106
 		$_GET['a'] += $limit;
4865 5107
 		$step_progress['current'] = $_GET['a'];
@@ -4885,10 +5127,11 @@  discard block
 block discarded – undo
4885 5127
 
4886 5128
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4887 5129
 
4888
-	if (isset($columns[$column]))
4889
-		return $columns[$column];
4890
-	else
4891
-		return null;
4892
-}
5130
+	if (isset($columns[$column])) {
5131
+			return $columns[$column];
5132
+	} else {
5133
+			return null;
5134
+	}
5135
+	}
4893 5136
 
4894 5137
 ?>
4895 5138
\ No newline at end of file
Please login to merge, or discard this patch.