Completed
Push — release-2.1 ( 6f245d...0f7175 )
by Michael
13s
created
other/upgrade.php 1 patch
Braces   +867 added lines, -635 removed lines patch added patch discarded remove patch
@@ -81,8 +81,9 @@  discard block
 block discarded – undo
81 81
 $upcontext['inactive_timeout'] = 10;
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
84
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
85 85
     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.');
86
+}
86 87
 
87 88
 require_once($upgrade_path . '/upgrade-helper.php');
88 89
 
@@ -106,11 +107,14 @@  discard block
 block discarded – undo
106 107
 	ini_set('default_socket_timeout', 900);
107 108
 }
108 109
 // Clean the upgrade path if this is from the client.
109
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
110
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
110
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
111
+	for ($i = 1;
112
+}
113
+$i < $_SERVER['argc']; $i++)
111 114
 	{
112
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
113
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
115
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
116
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
117
+		}
114 118
 	}
115 119
 
116 120
 // Are we from the client?
@@ -118,16 +122,17 @@  discard block
 block discarded – undo
118 122
 {
119 123
 	$command_line = true;
120 124
 	$disable_security = true;
121
-}
122
-else
125
+} else {
123 126
 	$command_line = false;
127
+}
124 128
 
125 129
 // Load this now just because we can.
126 130
 require_once($upgrade_path . '/Settings.php');
127 131
 
128 132
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
129
-if (isset($language))
133
+if (isset($language)) {
130 134
 	$language = str_ireplace('-utf8', '', $language);
135
+}
131 136
 
132 137
 // Are we logged in?
133 138
 if (isset($upgradeData))
@@ -135,10 +140,12 @@  discard block
 block discarded – undo
135 140
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
136 141
 
137 142
 	// Check for sensible values.
138
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
139
-		$upcontext['user']['started'] = time();
140
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
141
-		$upcontext['user']['updated'] = 0;
143
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
144
+			$upcontext['user']['started'] = time();
145
+	}
146
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
147
+			$upcontext['user']['updated'] = 0;
148
+	}
142 149
 
143 150
 	$upcontext['started'] = $upcontext['user']['started'];
144 151
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -196,8 +203,9 @@  discard block
 block discarded – undo
196 203
 			'db_error_skip' => true,
197 204
 		)
198 205
 	);
199
-	while ($row = $smcFunc['db_fetch_assoc']($request))
200
-		$modSettings[$row['variable']] = $row['value'];
206
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
207
+			$modSettings[$row['variable']] = $row['value'];
208
+	}
201 209
 	$smcFunc['db_free_result']($request);
202 210
 }
203 211
 
@@ -207,10 +215,12 @@  discard block
 block discarded – undo
207 215
 	$modSettings['theme_url'] = 'Themes/default';
208 216
 	$modSettings['images_url'] = 'Themes/default/images';
209 217
 }
210
-if (!isset($settings['default_theme_url']))
218
+if (!isset($settings['default_theme_url'])) {
211 219
 	$settings['default_theme_url'] = $modSettings['theme_url'];
212
-if (!isset($settings['default_theme_dir']))
220
+}
221
+if (!isset($settings['default_theme_dir'])) {
213 222
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
223
+}
214 224
 
215 225
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
216 226
 // Default title...
@@ -228,13 +238,15 @@  discard block
 block discarded – undo
228 238
 	$support_js = $upcontext['upgrade_status']['js'];
229 239
 
230 240
 	// Only set this if the upgrader status says so.
231
-	if (empty($is_debug))
232
-		$is_debug = $upcontext['upgrade_status']['debug'];
241
+	if (empty($is_debug)) {
242
+			$is_debug = $upcontext['upgrade_status']['debug'];
243
+	}
233 244
 
234 245
 	// Load the language.
235
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
236
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
237
-}
246
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
247
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
248
+	}
249
+	}
238 250
 // Set the defaults.
239 251
 else
240 252
 {
@@ -252,15 +264,18 @@  discard block
 block discarded – undo
252 264
 }
253 265
 
254 266
 // If this isn't the first stage see whether they are logging in and resuming.
255
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
267
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
256 268
 	checkLogin();
269
+}
257 270
 
258
-if ($command_line)
271
+if ($command_line) {
259 272
 	cmdStep0();
273
+}
260 274
 
261 275
 // Don't error if we're using xml.
262
-if (isset($_GET['xml']))
276
+if (isset($_GET['xml'])) {
263 277
 	$upcontext['return_error'] = true;
278
+}
264 279
 
265 280
 // Loop through all the steps doing each one as required.
266 281
 $upcontext['overall_percent'] = 0;
@@ -281,10 +296,11 @@  discard block
 block discarded – undo
281 296
 		}
282 297
 
283 298
 		// Call the step and if it returns false that means pause!
284
-		if (function_exists($step[2]) && $step[2]() === false)
285
-			break;
286
-		elseif (function_exists($step[2]))
287
-			$upcontext['current_step']++;
299
+		if (function_exists($step[2]) && $step[2]() === false) {
300
+					break;
301
+		} elseif (function_exists($step[2])) {
302
+					$upcontext['current_step']++;
303
+		}
288 304
 	}
289 305
 	$upcontext['overall_percent'] += $step[3];
290 306
 }
@@ -323,17 +339,18 @@  discard block
 block discarded – undo
323 339
 		// This should not happen my dear... HELP ME DEVELOPERS!!
324 340
 		if (!empty($command_line))
325 341
 		{
326
-			if (function_exists('debug_print_backtrace'))
327
-				debug_print_backtrace();
342
+			if (function_exists('debug_print_backtrace')) {
343
+							debug_print_backtrace();
344
+			}
328 345
 
329 346
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
330 347
 			flush();
331 348
 			die();
332 349
 		}
333 350
 
334
-		if (!isset($_GET['xml']))
335
-			template_upgrade_above();
336
-		else
351
+		if (!isset($_GET['xml'])) {
352
+					template_upgrade_above();
353
+		} else
337 354
 		{
338 355
 			header('Content-Type: text/xml; charset=UTF-8');
339 356
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -355,21 +372,24 @@  discard block
 block discarded – undo
355 372
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
356 373
 
357 374
 			// Custom stuff to pass back?
358
-			if (!empty($upcontext['query_string']))
359
-				$upcontext['form_url'] .= $upcontext['query_string'];
375
+			if (!empty($upcontext['query_string'])) {
376
+							$upcontext['form_url'] .= $upcontext['query_string'];
377
+			}
360 378
 
361 379
 			call_user_func('template_' . $upcontext['sub_template']);
362 380
 		}
363 381
 
364 382
 		// Was there an error?
365
-		if (!empty($upcontext['forced_error_message']))
366
-			echo $upcontext['forced_error_message'];
383
+		if (!empty($upcontext['forced_error_message'])) {
384
+					echo $upcontext['forced_error_message'];
385
+		}
367 386
 
368 387
 		// Show the footer.
369
-		if (!isset($_GET['xml']))
370
-			template_upgrade_below();
371
-		else
372
-			template_xml_below();
388
+		if (!isset($_GET['xml'])) {
389
+					template_upgrade_below();
390
+		} else {
391
+					template_xml_below();
392
+		}
373 393
 	}
374 394
 
375 395
 
@@ -381,15 +401,19 @@  discard block
 block discarded – undo
381 401
 		$seconds = intval($active % 60);
382 402
 
383 403
 		$totalTime = '';
384
-		if ($hours > 0)
385
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
386
-		if ($minutes > 0)
387
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
388
-		if ($seconds > 0)
389
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
404
+		if ($hours > 0) {
405
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
406
+		}
407
+		if ($minutes > 0) {
408
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
409
+		}
410
+		if ($seconds > 0) {
411
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
412
+		}
390 413
 
391
-		if (!empty($totalTime))
392
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
414
+		if (!empty($totalTime)) {
415
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
416
+		}
393 417
 	}
394 418
 
395 419
 	// Bang - gone!
@@ -402,8 +426,9 @@  discard block
 block discarded – undo
402 426
 	global $upgradeurl, $upcontext, $command_line;
403 427
 
404 428
 	// Command line users can't be redirected.
405
-	if ($command_line)
406
-		upgradeExit(true);
429
+	if ($command_line) {
430
+			upgradeExit(true);
431
+	}
407 432
 
408 433
 	// Are we providing the core info?
409 434
 	if ($addForm)
@@ -426,19 +451,22 @@  discard block
 block discarded – undo
426 451
 	global $modSettings, $sourcedir, $smcFunc;
427 452
 
428 453
 	// Do the non-SSI stuff...
429
-	if (function_exists('set_magic_quotes_runtime'))
430
-		@set_magic_quotes_runtime(0);
454
+	if (function_exists('set_magic_quotes_runtime')) {
455
+			@set_magic_quotes_runtime(0);
456
+	}
431 457
 
432 458
 	error_reporting(E_ALL);
433 459
 	define('SMF', 1);
434 460
 
435 461
 	// Start the session.
436
-	if (@ini_get('session.save_handler') == 'user')
437
-		@ini_set('session.save_handler', 'files');
462
+	if (@ini_get('session.save_handler') == 'user') {
463
+			@ini_set('session.save_handler', 'files');
464
+	}
438 465
 	@session_start();
439 466
 
440
-	if (empty($smcFunc))
441
-		$smcFunc = array();
467
+	if (empty($smcFunc)) {
468
+			$smcFunc = array();
469
+	}
442 470
 
443 471
 	// We need this for authentication and some upgrade code
444 472
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -450,8 +478,9 @@  discard block
 block discarded – undo
450 478
 	initialize_inputs();
451 479
 
452 480
 	// Get the database going!
453
-	if (empty($db_type) || $db_type == 'mysqli')
454
-		$db_type = 'mysql';
481
+	if (empty($db_type) || $db_type == 'mysqli') {
482
+			$db_type = 'mysql';
483
+	}
455 484
 
456 485
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
457 486
 	{
@@ -461,17 +490,19 @@  discard block
 block discarded – undo
461 490
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
462 491
 
463 492
 		// Oh dear god!!
464
-		if ($db_connection === null)
465
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
493
+		if ($db_connection === null) {
494
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
495
+		}
466 496
 
467
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
468
-			$smcFunc['db_query']('', '
497
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
498
+					$smcFunc['db_query']('', '
469 499
 			SET NAMES {string:db_character_set}',
470 500
 			array(
471 501
 				'db_error_skip' => true,
472 502
 				'db_character_set' => $db_character_set,
473 503
 			)
474 504
 		);
505
+		}
475 506
 
476 507
 		// Load the modSettings data...
477 508
 		$request = $smcFunc['db_query']('', '
@@ -482,11 +513,11 @@  discard block
 block discarded – undo
482 513
 			)
483 514
 		);
484 515
 		$modSettings = array();
485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
486
-			$modSettings[$row['variable']] = $row['value'];
516
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
517
+					$modSettings[$row['variable']] = $row['value'];
518
+		}
487 519
 		$smcFunc['db_free_result']($request);
488
-	}
489
-	else
520
+	} else
490 521
 	{
491 522
 		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.');
492 523
 	}
@@ -500,9 +531,10 @@  discard block
 block discarded – undo
500 531
 		cleanRequest();
501 532
 	}
502 533
 
503
-	if (!isset($_GET['substep']))
504
-		$_GET['substep'] = 0;
505
-}
534
+	if (!isset($_GET['substep'])) {
535
+			$_GET['substep'] = 0;
536
+	}
537
+	}
506 538
 
507 539
 function initialize_inputs()
508 540
 {
@@ -532,8 +564,9 @@  discard block
 block discarded – undo
532 564
 		$dh = opendir(dirname(__FILE__));
533 565
 		while ($file = readdir($dh))
534 566
 		{
535
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
536
-				@unlink(dirname(__FILE__) . '/' . $file);
567
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
568
+							@unlink(dirname(__FILE__) . '/' . $file);
569
+			}
537 570
 		}
538 571
 		closedir($dh);
539 572
 
@@ -563,8 +596,9 @@  discard block
 block discarded – undo
563 596
 	{
564 597
 		$upcontext['remote_files_available'] = false;
565 598
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
566
-		if ($test)
567
-			$upcontext['remote_files_available'] = true;
599
+		if ($test) {
600
+					$upcontext['remote_files_available'] = true;
601
+		}
568 602
 		@fclose($test);
569 603
 	}
570 604
 
@@ -572,8 +606,9 @@  discard block
 block discarded – undo
572 606
 	$temp = 'upgrade_php?step';
573 607
 	while (strlen($temp) > 4)
574 608
 	{
575
-		if (isset($_GET[$temp]))
576
-			unset($_GET[$temp]);
609
+		if (isset($_GET[$temp])) {
610
+					unset($_GET[$temp]);
611
+		}
577 612
 		$temp = substr($temp, 1);
578 613
 	}
579 614
 
@@ -600,32 +635,39 @@  discard block
 block discarded – undo
600 635
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
601 636
 
602 637
 	// Need legacy scripts?
603
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
604
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
605
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
606
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
607
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
608
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
638
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
639
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
640
+	}
641
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
642
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
643
+	}
644
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
645
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
646
+	}
609 647
 
610 648
 	// We don't need "-utf8" files anymore...
611 649
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
612 650
 
613 651
 	// This needs to exist!
614
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
615
-		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>]');
616
-	else
617
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
652
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
653
+			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>]');
654
+	} else {
655
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
656
+	}
618 657
 
619
-	if (!$check)
620
-		// 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.
658
+	if (!$check) {
659
+			// 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.
621 660
 		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.');
661
+	}
622 662
 
623 663
 	// Do they meet the install requirements?
624
-	if (!php_version_check())
625
-		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.');
664
+	if (!php_version_check()) {
665
+			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.');
666
+	}
626 667
 
627
-	if (!db_version_check())
628
-		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.');
668
+	if (!db_version_check()) {
669
+			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.');
670
+	}
629 671
 
630 672
 	// Do some checks to make sure they have proper privileges
631 673
 	db_extend('packages');
@@ -640,14 +682,16 @@  discard block
 block discarded – undo
640 682
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
641 683
 
642 684
 	// Sorry... we need CREATE, ALTER and DROP
643
-	if (!$create || !$alter || !$drop)
644
-		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.');
685
+	if (!$create || !$alter || !$drop) {
686
+			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.');
687
+	}
645 688
 
646 689
 	// Do a quick version spot check.
647 690
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
648 691
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
649
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
650
-		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.');
692
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
693
+			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.');
694
+	}
651 695
 
652 696
 	// What absolutely needs to be writable?
653 697
 	$writable_files = array(
@@ -669,12 +713,13 @@  discard block
 block discarded – undo
669 713
 	quickFileWritable($custom_av_dir);
670 714
 
671 715
 	// Are we good now?
672
-	if (!is_writable($custom_av_dir))
673
-		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));
674
-	elseif ($need_settings_update)
716
+	if (!is_writable($custom_av_dir)) {
717
+			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));
718
+	} elseif ($need_settings_update)
675 719
 	{
676
-		if (!function_exists('cache_put_data'))
677
-			require_once($sourcedir . '/Load.php');
720
+		if (!function_exists('cache_put_data')) {
721
+					require_once($sourcedir . '/Load.php');
722
+		}
678 723
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
679 724
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
680 725
 	}
@@ -683,28 +728,33 @@  discard block
 block discarded – undo
683 728
 
684 729
 	// Check the cache directory.
685 730
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
686
-	if (!file_exists($cachedir_temp))
687
-		@mkdir($cachedir_temp);
688
-	if (!file_exists($cachedir_temp))
689
-		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.');
690
-
691
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
692
-		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>.');
693
-	elseif (!isset($_GET['skiplang']))
731
+	if (!file_exists($cachedir_temp)) {
732
+			@mkdir($cachedir_temp);
733
+	}
734
+	if (!file_exists($cachedir_temp)) {
735
+			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.');
736
+	}
737
+
738
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
739
+			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>.');
740
+	} elseif (!isset($_GET['skiplang']))
694 741
 	{
695 742
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
696 743
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
697 744
 
698
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
699
-			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>]');
745
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
746
+					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>]');
747
+		}
700 748
 	}
701 749
 
702
-	if (!makeFilesWritable($writable_files))
703
-		return false;
750
+	if (!makeFilesWritable($writable_files)) {
751
+			return false;
752
+	}
704 753
 
705 754
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
706
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
707
-		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.');
755
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
756
+			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.');
757
+	}
708 758
 
709 759
 	// Upgrade the agreement.
710 760
 	elseif (isset($modSettings['agreement']))
@@ -715,8 +765,8 @@  discard block
 block discarded – undo
715 765
 	}
716 766
 
717 767
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
718
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
719
-		$upcontext['warning'] = '
768
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
769
+			$upcontext['warning'] = '
720 770
 			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>
721 771
 			<ul>
722 772
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -724,10 +774,12 @@  discard block
 block discarded – undo
724 774
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
725 775
 			</ul>
726 776
 			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="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
777
+	}
727 778
 
728 779
 	// Either we're logged in or we're going to present the login.
729
-	if (checkLogin())
730
-		return true;
780
+	if (checkLogin()) {
781
+			return true;
782
+	}
731 783
 
732 784
 	$upcontext += createToken('login');
733 785
 
@@ -741,15 +793,17 @@  discard block
 block discarded – undo
741 793
 	global $smcFunc, $db_type, $support_js;
742 794
 
743 795
 	// Don't bother if the security is disabled.
744
-	if ($disable_security)
745
-		return true;
796
+	if ($disable_security) {
797
+			return true;
798
+	}
746 799
 
747 800
 	// Are we trying to login?
748 801
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
749 802
 	{
750 803
 		// If we've disabled security pick a suitable name!
751
-		if (empty($_POST['user']))
752
-			$_POST['user'] = 'Administrator';
804
+		if (empty($_POST['user'])) {
805
+					$_POST['user'] = 'Administrator';
806
+		}
753 807
 
754 808
 		// Before 2.0 these column names were different!
755 809
 		$oldDB = false;
@@ -764,16 +818,17 @@  discard block
 block discarded – undo
764 818
 					'db_error_skip' => true,
765 819
 				)
766 820
 			);
767
-			if ($smcFunc['db_num_rows']($request) != 0)
768
-				$oldDB = true;
821
+			if ($smcFunc['db_num_rows']($request) != 0) {
822
+							$oldDB = true;
823
+			}
769 824
 			$smcFunc['db_free_result']($request);
770 825
 		}
771 826
 
772 827
 		// Get what we believe to be their details.
773 828
 		if (!$disable_security)
774 829
 		{
775
-			if ($oldDB)
776
-				$request = $smcFunc['db_query']('', '
830
+			if ($oldDB) {
831
+							$request = $smcFunc['db_query']('', '
777 832
 					SELECT id_member, memberName AS member_name, passwd, id_group,
778 833
 					additionalGroups AS additional_groups, lngfile
779 834
 					FROM {db_prefix}members
@@ -783,8 +838,8 @@  discard block
 block discarded – undo
783 838
 						'db_error_skip' => true,
784 839
 					)
785 840
 				);
786
-			else
787
-				$request = $smcFunc['db_query']('', '
841
+			} else {
842
+							$request = $smcFunc['db_query']('', '
788 843
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
789 844
 					FROM {db_prefix}members
790 845
 					WHERE member_name = {string:member_name}',
@@ -793,6 +848,7 @@  discard block
 block discarded – undo
793 848
 						'db_error_skip' => true,
794 849
 					)
795 850
 				);
851
+			}
796 852
 			if ($smcFunc['db_num_rows']($request) != 0)
797 853
 			{
798 854
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -800,16 +856,17 @@  discard block
 block discarded – undo
800 856
 				$groups = explode(',', $addGroups);
801 857
 				$groups[] = $id_group;
802 858
 
803
-				foreach ($groups as $k => $v)
804
-					$groups[$k] = (int) $v;
859
+				foreach ($groups as $k => $v) {
860
+									$groups[$k] = (int) $v;
861
+				}
805 862
 
806 863
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
807 864
 
808 865
 				// We don't use "-utf8" anymore...
809 866
 				$user_language = str_ireplace('-utf8', '', $user_language);
867
+			} else {
868
+							$upcontext['username_incorrect'] = true;
810 869
 			}
811
-			else
812
-				$upcontext['username_incorrect'] = true;
813 870
 			$smcFunc['db_free_result']($request);
814 871
 		}
815 872
 		$upcontext['username'] = $_POST['user'];
@@ -819,13 +876,14 @@  discard block
 block discarded – undo
819 876
 		{
820 877
 			$upcontext['upgrade_status']['js'] = 1;
821 878
 			$support_js = 1;
879
+		} else {
880
+					$support_js = 0;
822 881
 		}
823
-		else
824
-			$support_js = 0;
825 882
 
826 883
 		// Note down the version we are coming from.
827
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
828
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
884
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
885
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
886
+		}
829 887
 
830 888
 		// Didn't get anywhere?
831 889
 		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']))
@@ -859,15 +917,15 @@  discard block
 block discarded – undo
859 917
 							'db_error_skip' => true,
860 918
 						)
861 919
 					);
862
-					if ($smcFunc['db_num_rows']($request) == 0)
863
-						return throw_error('You need to be an admin to perform an upgrade!');
920
+					if ($smcFunc['db_num_rows']($request) == 0) {
921
+											return throw_error('You need to be an admin to perform an upgrade!');
922
+					}
864 923
 					$smcFunc['db_free_result']($request);
865 924
 				}
866 925
 
867 926
 				$upcontext['user']['id'] = $id_member;
868 927
 				$upcontext['user']['name'] = $name;
869
-			}
870
-			else
928
+			} else
871 929
 			{
872 930
 				$upcontext['user']['id'] = 1;
873 931
 				$upcontext['user']['name'] = 'Administrator';
@@ -883,11 +941,11 @@  discard block
 block discarded – undo
883 941
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
884 942
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
885 943
 
886
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
887
-					$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'] . '.';
888
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
889
-					$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'] . '.';
890
-				else
944
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
945
+									$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'] . '.';
946
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
947
+									$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'] . '.';
948
+				} else
891 949
 				{
892 950
 					// Set this as the new language.
893 951
 					$upcontext['language'] = $user_language;
@@ -931,8 +989,9 @@  discard block
 block discarded – undo
931 989
 	unset($member_columns);
932 990
 
933 991
 	// If we've not submitted then we're done.
934
-	if (empty($_POST['upcont']))
935
-		return false;
992
+	if (empty($_POST['upcont'])) {
993
+			return false;
994
+	}
936 995
 
937 996
 	// Firstly, if they're enabling SM stat collection just do it.
938 997
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -947,25 +1006,26 @@  discard block
 block discarded – undo
947 1006
 			fwrite($fp, $out);
948 1007
 
949 1008
 			$return_data = '';
950
-			while (!feof($fp))
951
-				$return_data .= fgets($fp, 128);
1009
+			while (!feof($fp)) {
1010
+							$return_data .= fgets($fp, 128);
1011
+			}
952 1012
 
953 1013
 			fclose($fp);
954 1014
 
955 1015
 			// Get the unique site ID.
956 1016
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
957 1017
 
958
-			if (!empty($ID[1]))
959
-				$smcFunc['db_insert']('replace',
1018
+			if (!empty($ID[1])) {
1019
+							$smcFunc['db_insert']('replace',
960 1020
 					$db_prefix . 'settings',
961 1021
 					array('variable' => 'string', 'value' => 'string'),
962 1022
 					array('allow_sm_stats', $ID[1]),
963 1023
 					array('variable')
964 1024
 				);
1025
+			}
965 1026
 		}
966
-	}
967
-	else
968
-		$smcFunc['db_query']('', '
1027
+	} else {
1028
+			$smcFunc['db_query']('', '
969 1029
 			DELETE FROM {db_prefix}settings
970 1030
 			WHERE variable = {string:allow_sm_stats}',
971 1031
 			array(
@@ -973,6 +1033,7 @@  discard block
 block discarded – undo
973 1033
 				'db_error_skip' => true,
974 1034
 			)
975 1035
 		);
1036
+	}
976 1037
 
977 1038
 	// Deleting old karma stuff?
978 1039
 	if (!empty($_POST['delete_karma']))
@@ -987,20 +1048,22 @@  discard block
 block discarded – undo
987 1048
 		);
988 1049
 
989 1050
 		// Cleaning up old karma member settings.
990
-		if ($upcontext['karma_installed']['good'])
991
-			$smcFunc['db_query']('', '
1051
+		if ($upcontext['karma_installed']['good']) {
1052
+					$smcFunc['db_query']('', '
992 1053
 				ALTER TABLE {db_prefix}members
993 1054
 				DROP karma_good',
994 1055
 				array()
995 1056
 			);
1057
+		}
996 1058
 
997 1059
 		// Does karma bad was enable?
998
-		if ($upcontext['karma_installed']['bad'])
999
-			$smcFunc['db_query']('', '
1060
+		if ($upcontext['karma_installed']['bad']) {
1061
+					$smcFunc['db_query']('', '
1000 1062
 				ALTER TABLE {db_prefix}members
1001 1063
 				DROP karma_bad',
1002 1064
 				array()
1003 1065
 			);
1066
+		}
1004 1067
 
1005 1068
 		// Cleaning up old karma permissions.
1006 1069
 		$smcFunc['db_query']('', '
@@ -1013,26 +1076,29 @@  discard block
 block discarded – undo
1013 1076
 	}
1014 1077
 
1015 1078
 	// Emptying the error log?
1016
-	if (!empty($_POST['empty_error']))
1017
-		$smcFunc['db_query']('truncate_table', '
1079
+	if (!empty($_POST['empty_error'])) {
1080
+			$smcFunc['db_query']('truncate_table', '
1018 1081
 			TRUNCATE {db_prefix}log_errors',
1019 1082
 			array(
1020 1083
 			)
1021 1084
 		);
1085
+	}
1022 1086
 
1023 1087
 	$changes = array();
1024 1088
 
1025 1089
 	// Add proxy settings.
1026
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1027
-		$changes += array(
1090
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1091
+			$changes += array(
1028 1092
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1029 1093
 			'image_proxy_maxsize' => 5190,
1030 1094
 			'image_proxy_enabled' => 0,
1031 1095
 		);
1096
+	}
1032 1097
 
1033 1098
 	// If we're overriding the language follow it through.
1034
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1035
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1099
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1100
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1101
+	}
1036 1102
 
1037 1103
 	if (!empty($_POST['maint']))
1038 1104
 	{
@@ -1044,30 +1110,34 @@  discard block
 block discarded – undo
1044 1110
 		{
1045 1111
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1046 1112
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1047
-		}
1048
-		else
1113
+		} else
1049 1114
 		{
1050 1115
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1051 1116
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1052 1117
 		}
1053 1118
 	}
1054 1119
 
1055
-	if ($command_line)
1056
-		echo ' * Updating Settings.php...';
1120
+	if ($command_line) {
1121
+			echo ' * Updating Settings.php...';
1122
+	}
1057 1123
 
1058 1124
 	// Fix some old paths.
1059
-	if (substr($boarddir, 0, 1) == '.')
1060
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1125
+	if (substr($boarddir, 0, 1) == '.') {
1126
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1127
+	}
1061 1128
 
1062
-	if (substr($sourcedir, 0, 1) == '.')
1063
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1129
+	if (substr($sourcedir, 0, 1) == '.') {
1130
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1131
+	}
1064 1132
 
1065
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1066
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1133
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1134
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1135
+	}
1067 1136
 
1068 1137
 	// Not had the database type added before?
1069
-	if (empty($db_type))
1070
-		$changes['db_type'] = 'mysql';
1138
+	if (empty($db_type)) {
1139
+			$changes['db_type'] = 'mysql';
1140
+	}
1071 1141
 
1072 1142
 	// If they have a "host:port" setup for the host, split that into separate values
1073 1143
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1078,32 +1148,36 @@  discard block
 block discarded – undo
1078 1148
 		$changes['db_server'] = '\'' . $db_server . '\'';
1079 1149
 
1080 1150
 		// Only set this if we're not using the default port
1081
-		if ($db_port != ini_get('mysqli.default_port'))
1082
-			$changes['db_port'] = (int) $db_port;
1083
-	}
1084
-	elseif (!empty($db_port))
1151
+		if ($db_port != ini_get('mysqli.default_port')) {
1152
+					$changes['db_port'] = (int) $db_port;
1153
+		}
1154
+	} elseif (!empty($db_port))
1085 1155
 	{
1086 1156
 		// If db_port is set and is the same as the default, set it to ''
1087 1157
 		if ($db_type == 'mysql')
1088 1158
 		{
1089
-			if ($db_port == ini_get('mysqli.default_port'))
1090
-				$changes['db_port'] = '\'\'';
1091
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1092
-				$changes['db_port'] = '\'\'';
1159
+			if ($db_port == ini_get('mysqli.default_port')) {
1160
+							$changes['db_port'] = '\'\'';
1161
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1162
+							$changes['db_port'] = '\'\'';
1163
+			}
1093 1164
 		}
1094 1165
 	}
1095 1166
 
1096 1167
 	// Maybe we haven't had this option yet?
1097
-	if (empty($packagesdir))
1098
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1168
+	if (empty($packagesdir)) {
1169
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1170
+	}
1099 1171
 
1100 1172
 	// Add support for $tasksdir var.
1101
-	if (empty($tasksdir))
1102
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1173
+	if (empty($tasksdir)) {
1174
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1175
+	}
1103 1176
 
1104 1177
 	// Make sure we fix the language as well.
1105
-	if (stristr($language, '-utf8'))
1106
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1178
+	if (stristr($language, '-utf8')) {
1179
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1180
+	}
1107 1181
 
1108 1182
 	// @todo Maybe change the cookie name if going to 1.1, too?
1109 1183
 
@@ -1111,8 +1185,9 @@  discard block
 block discarded – undo
1111 1185
 	require_once($sourcedir . '/Subs-Admin.php');
1112 1186
 	updateSettingsFile($changes);
1113 1187
 
1114
-	if ($command_line)
1115
-		echo ' Successful.' . "\n";
1188
+	if ($command_line) {
1189
+			echo ' Successful.' . "\n";
1190
+	}
1116 1191
 
1117 1192
 	// Are we doing debug?
1118 1193
 	if (isset($_POST['debug']))
@@ -1122,8 +1197,9 @@  discard block
 block discarded – undo
1122 1197
 	}
1123 1198
 
1124 1199
 	// If we're not backing up then jump one.
1125
-	if (empty($_POST['backup']))
1126
-		$upcontext['current_step']++;
1200
+	if (empty($_POST['backup'])) {
1201
+			$upcontext['current_step']++;
1202
+	}
1127 1203
 
1128 1204
 	// If we've got here then let's proceed to the next step!
1129 1205
 	return true;
@@ -1138,8 +1214,9 @@  discard block
 block discarded – undo
1138 1214
 	$upcontext['page_title'] = 'Backup Database';
1139 1215
 
1140 1216
 	// Done it already - js wise?
1141
-	if (!empty($_POST['backup_done']))
1142
-		return true;
1217
+	if (!empty($_POST['backup_done'])) {
1218
+			return true;
1219
+	}
1143 1220
 
1144 1221
 	// Some useful stuff here.
1145 1222
 	db_extend();
@@ -1153,9 +1230,10 @@  discard block
 block discarded – undo
1153 1230
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1154 1231
 
1155 1232
 	$table_names = array();
1156
-	foreach ($tables as $table)
1157
-		if (substr($table, 0, 7) !== 'backup_')
1233
+	foreach ($tables as $table) {
1234
+			if (substr($table, 0, 7) !== 'backup_')
1158 1235
 			$table_names[] = $table;
1236
+	}
1159 1237
 
1160 1238
 	$upcontext['table_count'] = count($table_names);
1161 1239
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1165,12 +1243,14 @@  discard block
 block discarded – undo
1165 1243
 	$file_steps = $upcontext['table_count'];
1166 1244
 
1167 1245
 	// What ones have we already done?
1168
-	foreach ($table_names as $id => $table)
1169
-		if ($id < $_GET['substep'])
1246
+	foreach ($table_names as $id => $table) {
1247
+			if ($id < $_GET['substep'])
1170 1248
 			$upcontext['previous_tables'][] = $table;
1249
+	}
1171 1250
 
1172
-	if ($command_line)
1173
-		echo 'Backing Up Tables.';
1251
+	if ($command_line) {
1252
+			echo 'Backing Up Tables.';
1253
+	}
1174 1254
 
1175 1255
 	// If we don't support javascript we backup here.
1176 1256
 	if (!$support_js || isset($_GET['xml']))
@@ -1189,8 +1269,9 @@  discard block
 block discarded – undo
1189 1269
 			backupTable($table_names[$substep]);
1190 1270
 
1191 1271
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1192
-			if (isset($_GET['xml']))
1193
-				return upgradeExit();
1272
+			if (isset($_GET['xml'])) {
1273
+							return upgradeExit();
1274
+			}
1194 1275
 		}
1195 1276
 
1196 1277
 		if ($command_line)
@@ -1223,9 +1304,10 @@  discard block
 block discarded – undo
1223 1304
 
1224 1305
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1225 1306
 
1226
-	if ($command_line)
1227
-		echo ' done.';
1228
-}
1307
+	if ($command_line) {
1308
+			echo ' done.';
1309
+	}
1310
+	}
1229 1311
 
1230 1312
 // Step 2: Everything.
1231 1313
 function DatabaseChanges()
@@ -1234,8 +1316,9 @@  discard block
 block discarded – undo
1234 1316
 	global $upcontext, $support_js, $db_type;
1235 1317
 
1236 1318
 	// Have we just completed this?
1237
-	if (!empty($_POST['database_done']))
1238
-		return true;
1319
+	if (!empty($_POST['database_done'])) {
1320
+			return true;
1321
+	}
1239 1322
 
1240 1323
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1241 1324
 	$upcontext['page_title'] = 'Database Changes';
@@ -1250,15 +1333,16 @@  discard block
 block discarded – undo
1250 1333
 	);
1251 1334
 
1252 1335
 	// How many files are there in total?
1253
-	if (isset($_GET['filecount']))
1254
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1255
-	else
1336
+	if (isset($_GET['filecount'])) {
1337
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1338
+	} else
1256 1339
 	{
1257 1340
 		$upcontext['file_count'] = 0;
1258 1341
 		foreach ($files as $file)
1259 1342
 		{
1260
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1261
-				$upcontext['file_count']++;
1343
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1344
+							$upcontext['file_count']++;
1345
+			}
1262 1346
 		}
1263 1347
 	}
1264 1348
 
@@ -1268,9 +1352,9 @@  discard block
 block discarded – undo
1268 1352
 	$upcontext['cur_file_num'] = 0;
1269 1353
 	foreach ($files as $file)
1270 1354
 	{
1271
-		if ($did_not_do)
1272
-			$did_not_do--;
1273
-		else
1355
+		if ($did_not_do) {
1356
+					$did_not_do--;
1357
+		} else
1274 1358
 		{
1275 1359
 			$upcontext['cur_file_num']++;
1276 1360
 			$upcontext['cur_file_name'] = $file[0];
@@ -1297,12 +1381,13 @@  discard block
 block discarded – undo
1297 1381
 					// Flag to move on to the next.
1298 1382
 					$upcontext['completed_step'] = true;
1299 1383
 					// Did we complete the whole file?
1300
-					if ($nextFile)
1301
-						$upcontext['current_debug_item_num'] = -1;
1384
+					if ($nextFile) {
1385
+											$upcontext['current_debug_item_num'] = -1;
1386
+					}
1302 1387
 					return upgradeExit();
1388
+				} elseif ($support_js) {
1389
+									break;
1303 1390
 				}
1304
-				elseif ($support_js)
1305
-					break;
1306 1391
 			}
1307 1392
 			// Set the progress bar to be right as if we had - even if we hadn't...
1308 1393
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1327,8 +1412,9 @@  discard block
 block discarded – undo
1327 1412
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1328 1413
 
1329 1414
 	// Now it's nice to have some of the basic SMF source files.
1330
-	if (!isset($_GET['ssi']) && !$command_line)
1331
-		redirectLocation('&ssi=1');
1415
+	if (!isset($_GET['ssi']) && !$command_line) {
1416
+			redirectLocation('&ssi=1');
1417
+	}
1332 1418
 
1333 1419
 	$upcontext['sub_template'] = 'upgrade_complete';
1334 1420
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1344,14 +1430,16 @@  discard block
 block discarded – undo
1344 1430
 	// Are we in maintenance mode?
1345 1431
 	if (isset($upcontext['user']['main']))
1346 1432
 	{
1347
-		if ($command_line)
1348
-			echo ' * ';
1433
+		if ($command_line) {
1434
+					echo ' * ';
1435
+		}
1349 1436
 		$upcontext['removed_maintenance'] = true;
1350 1437
 		$changes['maintenance'] = $upcontext['user']['main'];
1351 1438
 	}
1352 1439
 	// Otherwise if somehow we are in 2 let's go to 1.
1353
-	elseif (!empty($maintenance) && $maintenance == 2)
1354
-		$changes['maintenance'] = 1;
1440
+	elseif (!empty($maintenance) && $maintenance == 2) {
1441
+			$changes['maintenance'] = 1;
1442
+	}
1355 1443
 
1356 1444
 	// Wipe this out...
1357 1445
 	$upcontext['user'] = array();
@@ -1366,9 +1454,9 @@  discard block
 block discarded – undo
1366 1454
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1367 1455
 
1368 1456
 	// Now is the perfect time to fetch the SM files.
1369
-	if ($command_line)
1370
-		cli_scheduled_fetchSMfiles();
1371
-	else
1457
+	if ($command_line) {
1458
+			cli_scheduled_fetchSMfiles();
1459
+	} else
1372 1460
 	{
1373 1461
 		require_once($sourcedir . '/ScheduledTasks.php');
1374 1462
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1376,8 +1464,9 @@  discard block
 block discarded – undo
1376 1464
 	}
1377 1465
 
1378 1466
 	// Log what we've done.
1379
-	if (empty($user_info['id']))
1380
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1467
+	if (empty($user_info['id'])) {
1468
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1469
+	}
1381 1470
 
1382 1471
 	// Log the action manually, so CLI still works.
1383 1472
 	$smcFunc['db_insert']('',
@@ -1396,8 +1485,9 @@  discard block
 block discarded – undo
1396 1485
 
1397 1486
 	// Save the current database version.
1398 1487
 	$server_version = $smcFunc['db_server_info']();
1399
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1400
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1488
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1489
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1490
+	}
1401 1491
 
1402 1492
 	if ($command_line)
1403 1493
 	{
@@ -1409,8 +1499,9 @@  discard block
 block discarded – undo
1409 1499
 
1410 1500
 	// Make sure it says we're done.
1411 1501
 	$upcontext['overall_percent'] = 100;
1412
-	if (isset($upcontext['step_progress']))
1413
-		unset($upcontext['step_progress']);
1502
+	if (isset($upcontext['step_progress'])) {
1503
+			unset($upcontext['step_progress']);
1504
+	}
1414 1505
 
1415 1506
 	$_GET['substep'] = 0;
1416 1507
 	return false;
@@ -1421,8 +1512,9 @@  discard block
 block discarded – undo
1421 1512
 {
1422 1513
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1423 1514
 
1424
-	if (empty($modSettings['time_format']))
1425
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1515
+	if (empty($modSettings['time_format'])) {
1516
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1517
+	}
1426 1518
 
1427 1519
 	// What files do we want to get
1428 1520
 	$request = $smcFunc['db_query']('', '
@@ -1456,8 +1548,9 @@  discard block
 block discarded – undo
1456 1548
 		$file_data = fetch_web_data($url);
1457 1549
 
1458 1550
 		// If we got an error - give up - the site might be down.
1459
-		if ($file_data === false)
1460
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1551
+		if ($file_data === false) {
1552
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1553
+		}
1461 1554
 
1462 1555
 		// Save the file to the database.
1463 1556
 		$smcFunc['db_query']('substring', '
@@ -1499,8 +1592,9 @@  discard block
 block discarded – undo
1499 1592
 	$themeData = array();
1500 1593
 	foreach ($values as $variable => $value)
1501 1594
 	{
1502
-		if (!isset($value) || $value === null)
1503
-			$value = 0;
1595
+		if (!isset($value) || $value === null) {
1596
+					$value = 0;
1597
+		}
1504 1598
 
1505 1599
 		$themeData[] = array(0, 1, $variable, $value);
1506 1600
 	}
@@ -1529,8 +1623,9 @@  discard block
 block discarded – undo
1529 1623
 
1530 1624
 	foreach ($values as $variable => $value)
1531 1625
 	{
1532
-		if (empty($modSettings[$value[0]]))
1533
-			continue;
1626
+		if (empty($modSettings[$value[0]])) {
1627
+					continue;
1628
+		}
1534 1629
 
1535 1630
 		$smcFunc['db_query']('', '
1536 1631
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1616,10 +1711,11 @@  discard block
 block discarded – undo
1616 1711
 	set_error_handler(
1617 1712
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1618 1713
 		{
1619
-			if ($support_js)
1620
-				return true;
1621
-			else
1622
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1714
+			if ($support_js) {
1715
+							return true;
1716
+			} else {
1717
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1718
+			}
1623 1719
 		}
1624 1720
 	);
1625 1721
 
@@ -1634,8 +1730,9 @@  discard block
 block discarded – undo
1634 1730
 				'db_error_skip' => true,
1635 1731
 			)
1636 1732
 		);
1637
-		if ($smcFunc['db_num_rows']($request) === 0)
1638
-			die('Unable to find members table!');
1733
+		if ($smcFunc['db_num_rows']($request) === 0) {
1734
+					die('Unable to find members table!');
1735
+		}
1639 1736
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1640 1737
 		$smcFunc['db_free_result']($request);
1641 1738
 
@@ -1650,17 +1747,20 @@  discard block
 block discarded – undo
1650 1747
 				)
1651 1748
 			);
1652 1749
 			// Got something?
1653
-			if ($smcFunc['db_num_rows']($request) !== 0)
1654
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1750
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1751
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1752
+			}
1655 1753
 			$smcFunc['db_free_result']($request);
1656 1754
 
1657 1755
 			// Excellent!
1658
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1659
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1756
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1757
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1758
+			}
1660 1759
 		}
1661 1760
 	}
1662
-	if (empty($db_collation))
1663
-		$db_collation = '';
1761
+	if (empty($db_collation)) {
1762
+			$db_collation = '';
1763
+	}
1664 1764
 
1665 1765
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1666 1766
 
@@ -1672,8 +1772,9 @@  discard block
 block discarded – undo
1672 1772
 	$last_step = '';
1673 1773
 
1674 1774
 	// Make sure all newly created tables will have the proper characters set.
1675
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1676
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1775
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1776
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1777
+	}
1677 1778
 
1678 1779
 	// Count the total number of steps within this file - for progress.
1679 1780
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1693,15 +1794,18 @@  discard block
 block discarded – undo
1693 1794
 		$do_current = $substep >= $_GET['substep'];
1694 1795
 
1695 1796
 		// Get rid of any comments in the beginning of the line...
1696
-		if (substr(trim($line), 0, 2) === '/*')
1697
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1797
+		if (substr(trim($line), 0, 2) === '/*') {
1798
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1799
+		}
1698 1800
 
1699 1801
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1700
-		if ($is_debug && !$support_js && $command_line)
1701
-			flush();
1802
+		if ($is_debug && !$support_js && $command_line) {
1803
+					flush();
1804
+		}
1702 1805
 
1703
-		if (trim($line) === '')
1704
-			continue;
1806
+		if (trim($line) === '') {
1807
+					continue;
1808
+		}
1705 1809
 
1706 1810
 		if (trim(substr($line, 0, 3)) === '---')
1707 1811
 		{
@@ -1711,8 +1815,9 @@  discard block
 block discarded – undo
1711 1815
 			if (trim($current_data) != '' && $type !== '}')
1712 1816
 			{
1713 1817
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1714
-				if ($command_line)
1715
-					echo $upcontext['error_message'];
1818
+				if ($command_line) {
1819
+									echo $upcontext['error_message'];
1820
+				}
1716 1821
 			}
1717 1822
 
1718 1823
 			if ($type == ' ')
@@ -1730,17 +1835,18 @@  discard block
 block discarded – undo
1730 1835
 				if ($do_current)
1731 1836
 				{
1732 1837
 					$upcontext['actioned_items'][] = $last_step;
1733
-					if ($command_line)
1734
-						echo ' * ';
1838
+					if ($command_line) {
1839
+											echo ' * ';
1840
+					}
1735 1841
 				}
1736
-			}
1737
-			elseif ($type == '#')
1842
+			} elseif ($type == '#')
1738 1843
 			{
1739 1844
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1740 1845
 
1741 1846
 				$upcontext['current_debug_item_num']++;
1742
-				if (trim($line) != '---#')
1743
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1847
+				if (trim($line) != '---#') {
1848
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1849
+				}
1744 1850
 
1745 1851
 				// Have we already done something?
1746 1852
 				if (isset($_GET['xml']) && $done_something)
@@ -1751,34 +1857,36 @@  discard block
 block discarded – undo
1751 1857
 
1752 1858
 				if ($do_current)
1753 1859
 				{
1754
-					if (trim($line) == '---#' && $command_line)
1755
-						echo ' done.', $endl;
1756
-					elseif ($command_line)
1757
-						echo ' +++ ', rtrim(substr($line, 4));
1758
-					elseif (trim($line) != '---#')
1860
+					if (trim($line) == '---#' && $command_line) {
1861
+											echo ' done.', $endl;
1862
+					} elseif ($command_line) {
1863
+											echo ' +++ ', rtrim(substr($line, 4));
1864
+					} elseif (trim($line) != '---#')
1759 1865
 					{
1760
-						if ($is_debug)
1761
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1866
+						if ($is_debug) {
1867
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1868
+						}
1762 1869
 					}
1763 1870
 				}
1764 1871
 
1765 1872
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1766 1873
 				{
1767
-					if ($command_line)
1768
-						echo ' * ';
1769
-					else
1770
-						$upcontext['actioned_items'][] = $last_step;
1874
+					if ($command_line) {
1875
+											echo ' * ';
1876
+					} else {
1877
+											$upcontext['actioned_items'][] = $last_step;
1878
+					}
1771 1879
 				}
1772 1880
 
1773 1881
 				// Small step - only if we're actually doing stuff.
1774
-				if ($do_current)
1775
-					nextSubstep(++$substep);
1776
-				else
1777
-					$substep++;
1778
-			}
1779
-			elseif ($type == '{')
1780
-				$current_type = 'code';
1781
-			elseif ($type == '}')
1882
+				if ($do_current) {
1883
+									nextSubstep(++$substep);
1884
+				} else {
1885
+									$substep++;
1886
+				}
1887
+			} elseif ($type == '{') {
1888
+							$current_type = 'code';
1889
+			} elseif ($type == '}')
1782 1890
 			{
1783 1891
 				$current_type = 'sql';
1784 1892
 
@@ -1791,8 +1899,9 @@  discard block
 block discarded – undo
1791 1899
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1792 1900
 				{
1793 1901
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1794
-					if ($command_line)
1795
-						echo $upcontext['error_message'];
1902
+					if ($command_line) {
1903
+											echo $upcontext['error_message'];
1904
+					}
1796 1905
 				}
1797 1906
 
1798 1907
 				// Done with code!
@@ -1872,8 +1981,9 @@  discard block
 block discarded – undo
1872 1981
 	$db_unbuffered = false;
1873 1982
 
1874 1983
 	// Failure?!
1875
-	if ($result !== false)
1876
-		return $result;
1984
+	if ($result !== false) {
1985
+			return $result;
1986
+	}
1877 1987
 
1878 1988
 	$db_error_message = $smcFunc['db_error']($db_connection);
1879 1989
 	// If MySQL we do something more clever.
@@ -1901,54 +2011,61 @@  discard block
 block discarded – undo
1901 2011
 			{
1902 2012
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1903 2013
 				$result = mysqli_query($db_connection, $string);
1904
-				if ($result !== false)
1905
-					return $result;
2014
+				if ($result !== false) {
2015
+									return $result;
2016
+				}
1906 2017
 			}
1907
-		}
1908
-		elseif ($mysqli_errno == 2013)
2018
+		} elseif ($mysqli_errno == 2013)
1909 2019
 		{
1910 2020
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1911 2021
 			mysqli_select_db($db_connection, $db_name);
1912 2022
 			if ($db_connection)
1913 2023
 			{
1914 2024
 				$result = mysqli_query($db_connection, $string);
1915
-				if ($result !== false)
1916
-					return $result;
2025
+				if ($result !== false) {
2026
+									return $result;
2027
+				}
1917 2028
 			}
1918 2029
 		}
1919 2030
 		// Duplicate column name... should be okay ;).
1920
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1921
-			return false;
2031
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2032
+					return false;
2033
+		}
1922 2034
 		// Duplicate insert... make sure it's the proper type of query ;).
1923
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1924
-			return false;
2035
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2036
+					return false;
2037
+		}
1925 2038
 		// Creating an index on a non-existent column.
1926
-		elseif ($mysqli_errno == 1072)
1927
-			return false;
1928
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1929
-			return false;
2039
+		elseif ($mysqli_errno == 1072) {
2040
+					return false;
2041
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2042
+					return false;
2043
+		}
1930 2044
 	}
1931 2045
 	// If a table already exists don't go potty.
1932 2046
 	else
1933 2047
 	{
1934 2048
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1935 2049
 		{
1936
-			if (strpos($db_error_message, 'exist') !== false)
1937
-				return true;
1938
-		}
1939
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2050
+			if (strpos($db_error_message, 'exist') !== false) {
2051
+							return true;
2052
+			}
2053
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1940 2054
 		{
1941
-			if (strpos($db_error_message, 'duplicate') !== false)
1942
-				return true;
2055
+			if (strpos($db_error_message, 'duplicate') !== false) {
2056
+							return true;
2057
+			}
1943 2058
 		}
1944 2059
 	}
1945 2060
 
1946 2061
 	// Get the query string so we pass everything.
1947 2062
 	$query_string = '';
1948
-	foreach ($_GET as $k => $v)
1949
-		$query_string .= ';' . $k . '=' . $v;
1950
-	if (strlen($query_string) != 0)
1951
-		$query_string = '?' . substr($query_string, 1);
2063
+	foreach ($_GET as $k => $v) {
2064
+			$query_string .= ';' . $k . '=' . $v;
2065
+	}
2066
+	if (strlen($query_string) != 0) {
2067
+			$query_string = '?' . substr($query_string, 1);
2068
+	}
1952 2069
 
1953 2070
 	if ($command_line)
1954 2071
 	{
@@ -2003,16 +2120,18 @@  discard block
 block discarded – undo
2003 2120
 			{
2004 2121
 				$found |= 1;
2005 2122
 				// Do some checks on the data if we have it set.
2006
-				if (isset($change['col_type']))
2007
-					$found &= $change['col_type'] === $column['type'];
2008
-				if (isset($change['null_allowed']))
2009
-					$found &= $column['null'] == $change['null_allowed'];
2010
-				if (isset($change['default']))
2011
-					$found &= $change['default'] === $column['default'];
2123
+				if (isset($change['col_type'])) {
2124
+									$found &= $change['col_type'] === $column['type'];
2125
+				}
2126
+				if (isset($change['null_allowed'])) {
2127
+									$found &= $column['null'] == $change['null_allowed'];
2128
+				}
2129
+				if (isset($change['default'])) {
2130
+									$found &= $change['default'] === $column['default'];
2131
+				}
2012 2132
 			}
2013 2133
 		}
2014
-	}
2015
-	elseif ($change['type'] === 'index')
2134
+	} elseif ($change['type'] === 'index')
2016 2135
 	{
2017 2136
 		$request = upgrade_query('
2018 2137
 			SHOW INDEX
@@ -2021,9 +2140,10 @@  discard block
 block discarded – undo
2021 2140
 		{
2022 2141
 			$cur_index = array();
2023 2142
 
2024
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2025
-				if ($row['Key_name'] === $change['name'])
2143
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2144
+							if ($row['Key_name'] === $change['name'])
2026 2145
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2146
+			}
2027 2147
 
2028 2148
 			ksort($cur_index, SORT_NUMERIC);
2029 2149
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2033,14 +2153,17 @@  discard block
 block discarded – undo
2033 2153
 	}
2034 2154
 
2035 2155
 	// If we're trying to add and it's added, we're done.
2036
-	if ($found && in_array($change['method'], array('add', 'change')))
2037
-		return true;
2156
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2157
+			return true;
2158
+	}
2038 2159
 	// Otherwise if we're removing and it wasn't found we're also done.
2039
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2040
-		return true;
2160
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2161
+			return true;
2162
+	}
2041 2163
 	// Otherwise is it just a test?
2042
-	elseif ($is_test)
2043
-		return false;
2164
+	elseif ($is_test) {
2165
+			return false;
2166
+	}
2044 2167
 
2045 2168
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2046 2169
 	$running = false;
@@ -2051,8 +2174,9 @@  discard block
 block discarded – undo
2051 2174
 			SHOW FULL PROCESSLIST');
2052 2175
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2053 2176
 		{
2054
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2055
-				$found = true;
2177
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2178
+							$found = true;
2179
+			}
2056 2180
 		}
2057 2181
 
2058 2182
 		// Can't find it? Then we need to run it fools!
@@ -2064,8 +2188,9 @@  discard block
 block discarded – undo
2064 2188
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2065 2189
 				' . $change['text'], true) !== false;
2066 2190
 
2067
-			if (!$success)
2068
-				return false;
2191
+			if (!$success) {
2192
+							return false;
2193
+			}
2069 2194
 
2070 2195
 			// Return
2071 2196
 			$running = true;
@@ -2107,8 +2232,9 @@  discard block
 block discarded – undo
2107 2232
 			'db_error_skip' => true,
2108 2233
 		)
2109 2234
 	);
2110
-	if ($smcFunc['db_num_rows']($request) === 0)
2111
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2235
+	if ($smcFunc['db_num_rows']($request) === 0) {
2236
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2237
+	}
2112 2238
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2113 2239
 	$smcFunc['db_free_result']($request);
2114 2240
 
@@ -2130,18 +2256,19 @@  discard block
 block discarded – undo
2130 2256
 			)
2131 2257
 		);
2132 2258
 		// No results? Just forget it all together.
2133
-		if ($smcFunc['db_num_rows']($request) === 0)
2134
-			unset($table_row['Collation']);
2135
-		else
2136
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2259
+		if ($smcFunc['db_num_rows']($request) === 0) {
2260
+					unset($table_row['Collation']);
2261
+		} else {
2262
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2263
+		}
2137 2264
 		$smcFunc['db_free_result']($request);
2138 2265
 	}
2139 2266
 
2140 2267
 	if ($column_fix)
2141 2268
 	{
2142 2269
 		// Make sure there are no NULL's left.
2143
-		if ($null_fix)
2144
-			$smcFunc['db_query']('', '
2270
+		if ($null_fix) {
2271
+					$smcFunc['db_query']('', '
2145 2272
 				UPDATE {db_prefix}' . $change['table'] . '
2146 2273
 				SET ' . $change['column'] . ' = {string:default}
2147 2274
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2150,6 +2277,7 @@  discard block
 block discarded – undo
2150 2277
 					'db_error_skip' => true,
2151 2278
 				)
2152 2279
 			);
2280
+		}
2153 2281
 
2154 2282
 		// Do the actual alteration.
2155 2283
 		$smcFunc['db_query']('', '
@@ -2178,8 +2306,9 @@  discard block
 block discarded – undo
2178 2306
 	}
2179 2307
 
2180 2308
 	// Not a column we need to check on?
2181
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2182
-		return;
2309
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2310
+			return;
2311
+	}
2183 2312
 
2184 2313
 	// Break it up you (six|seven).
2185 2314
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2198,13 +2327,13 @@  discard block
 block discarded – undo
2198 2327
 				'new_name' => $temp[2],
2199 2328
 		));
2200 2329
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2201
-		if ($smcFunc['db_num_rows'] != 1)
2202
-			return;
2330
+		if ($smcFunc['db_num_rows'] != 1) {
2331
+					return;
2332
+		}
2203 2333
 
2204 2334
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2205 2335
 		$smcFunc['db_free_result']($request);
2206
-	}
2207
-	else
2336
+	} else
2208 2337
 	{
2209 2338
 		// Do this the old fashion, sure method way.
2210 2339
 		$request = $smcFunc['db_query']('', '
@@ -2215,21 +2344,24 @@  discard block
 block discarded – undo
2215 2344
 		));
2216 2345
 		// Mayday!
2217 2346
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2218
-		if ($smcFunc['db_num_rows'] == 0)
2219
-			return;
2347
+		if ($smcFunc['db_num_rows'] == 0) {
2348
+					return;
2349
+		}
2220 2350
 
2221 2351
 		// Oh where, oh where has my little field gone. Oh where can it be...
2222
-		while ($row = $smcFunc['db_query']($request))
2223
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2352
+		while ($row = $smcFunc['db_query']($request)) {
2353
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2224 2354
 			{
2225 2355
 				$current_type = $row['Type'];
2356
+		}
2226 2357
 				break;
2227 2358
 			}
2228 2359
 	}
2229 2360
 
2230 2361
 	// If this doesn't match, the column may of been altered for a reason.
2231
-	if (trim($current_type) != trim($temp[3]))
2232
-		$temp[3] = $current_type;
2362
+	if (trim($current_type) != trim($temp[3])) {
2363
+			$temp[3] = $current_type;
2364
+	}
2233 2365
 
2234 2366
 	// Piece this back together.
2235 2367
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2241,8 +2373,9 @@  discard block
 block discarded – undo
2241 2373
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2242 2374
 	global $step_progress, $is_debug, $upcontext;
2243 2375
 
2244
-	if ($_GET['substep'] < $substep)
2245
-		$_GET['substep'] = $substep;
2376
+	if ($_GET['substep'] < $substep) {
2377
+			$_GET['substep'] = $substep;
2378
+	}
2246 2379
 
2247 2380
 	if ($command_line)
2248 2381
 	{
@@ -2255,29 +2388,33 @@  discard block
 block discarded – undo
2255 2388
 	}
2256 2389
 
2257 2390
 	@set_time_limit(300);
2258
-	if (function_exists('apache_reset_timeout'))
2259
-		@apache_reset_timeout();
2391
+	if (function_exists('apache_reset_timeout')) {
2392
+			@apache_reset_timeout();
2393
+	}
2260 2394
 
2261
-	if (time() - $start_time <= $timeLimitThreshold)
2262
-		return;
2395
+	if (time() - $start_time <= $timeLimitThreshold) {
2396
+			return;
2397
+	}
2263 2398
 
2264 2399
 	// Do we have some custom step progress stuff?
2265 2400
 	if (!empty($step_progress))
2266 2401
 	{
2267 2402
 		$upcontext['substep_progress'] = 0;
2268 2403
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2269
-		if ($step_progress['current'] > $step_progress['total'])
2270
-			$upcontext['substep_progress'] = 99.9;
2271
-		else
2272
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2404
+		if ($step_progress['current'] > $step_progress['total']) {
2405
+					$upcontext['substep_progress'] = 99.9;
2406
+		} else {
2407
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2408
+		}
2273 2409
 
2274 2410
 		// Make it nicely rounded.
2275 2411
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2276 2412
 	}
2277 2413
 
2278 2414
 	// If this is XML we just exit right away!
2279
-	if (isset($_GET['xml']))
2280
-		return upgradeExit();
2415
+	if (isset($_GET['xml'])) {
2416
+			return upgradeExit();
2417
+	}
2281 2418
 
2282 2419
 	// We're going to pause after this!
2283 2420
 	$upcontext['pause'] = true;
@@ -2285,13 +2422,15 @@  discard block
 block discarded – undo
2285 2422
 	$upcontext['query_string'] = '';
2286 2423
 	foreach ($_GET as $k => $v)
2287 2424
 	{
2288
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2289
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2425
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2426
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2427
+		}
2290 2428
 	}
2291 2429
 
2292 2430
 	// Custom warning?
2293
-	if (!empty($custom_warning))
2294
-		$upcontext['custom_warning'] = $custom_warning;
2431
+	if (!empty($custom_warning)) {
2432
+			$upcontext['custom_warning'] = $custom_warning;
2433
+	}
2295 2434
 
2296 2435
 	upgradeExit();
2297 2436
 }
@@ -2306,25 +2445,26 @@  discard block
 block discarded – undo
2306 2445
 	ob_implicit_flush(true);
2307 2446
 	@set_time_limit(600);
2308 2447
 
2309
-	if (!isset($_SERVER['argv']))
2310
-		$_SERVER['argv'] = array();
2448
+	if (!isset($_SERVER['argv'])) {
2449
+			$_SERVER['argv'] = array();
2450
+	}
2311 2451
 	$_GET['maint'] = 1;
2312 2452
 
2313 2453
 	foreach ($_SERVER['argv'] as $i => $arg)
2314 2454
 	{
2315
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2316
-			$_GET['lang'] = $match[1];
2317
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2318
-			continue;
2319
-		elseif ($arg == '--no-maintenance')
2320
-			$_GET['maint'] = 0;
2321
-		elseif ($arg == '--debug')
2322
-			$is_debug = true;
2323
-		elseif ($arg == '--backup')
2324
-			$_POST['backup'] = 1;
2325
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2326
-			$_GET['conv'] = 1;
2327
-		elseif ($i != 0)
2455
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2456
+					$_GET['lang'] = $match[1];
2457
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2458
+					continue;
2459
+		} elseif ($arg == '--no-maintenance') {
2460
+					$_GET['maint'] = 0;
2461
+		} elseif ($arg == '--debug') {
2462
+					$is_debug = true;
2463
+		} elseif ($arg == '--backup') {
2464
+					$_POST['backup'] = 1;
2465
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2466
+					$_GET['conv'] = 1;
2467
+		} elseif ($i != 0)
2328 2468
 		{
2329 2469
 			echo 'SMF Command-line Upgrader
2330 2470
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2338,10 +2478,12 @@  discard block
 block discarded – undo
2338 2478
 		}
2339 2479
 	}
2340 2480
 
2341
-	if (!php_version_check())
2342
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2343
-	if (!db_version_check())
2344
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2481
+	if (!php_version_check()) {
2482
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2483
+	}
2484
+	if (!db_version_check()) {
2485
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2486
+	}
2345 2487
 
2346 2488
 	// Do some checks to make sure they have proper privileges
2347 2489
 	db_extend('packages');
@@ -2356,34 +2498,39 @@  discard block
 block discarded – undo
2356 2498
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2357 2499
 
2358 2500
 	// Sorry... we need CREATE, ALTER and DROP
2359
-	if (!$create || !$alter || !$drop)
2360
-		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);
2501
+	if (!$create || !$alter || !$drop) {
2502
+			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);
2503
+	}
2361 2504
 
2362 2505
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2363 2506
 		&& @file_exists($sourcedir . '/QueryString.php')
2364 2507
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2365
-	if (!$check && !isset($modSettings['smfVersion']))
2366
-		print_error('Error: Some files are missing or out-of-date.', true);
2508
+	if (!$check && !isset($modSettings['smfVersion'])) {
2509
+			print_error('Error: Some files are missing or out-of-date.', true);
2510
+	}
2367 2511
 
2368 2512
 	// Do a quick version spot check.
2369 2513
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2370 2514
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2371
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2372
-		print_error('Error: Some files have not yet been updated properly.');
2515
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2516
+			print_error('Error: Some files have not yet been updated properly.');
2517
+	}
2373 2518
 
2374 2519
 	// Make sure Settings.php is writable.
2375 2520
 		quickFileWritable($boarddir . '/Settings.php');
2376
-	if (!is_writable($boarddir . '/Settings.php'))
2377
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2521
+	if (!is_writable($boarddir . '/Settings.php')) {
2522
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2523
+	}
2378 2524
 
2379 2525
 	// Make sure Settings_bak.php is writable.
2380 2526
 		quickFileWritable($boarddir . '/Settings_bak.php');
2381
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2382
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2527
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2528
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2529
+	}
2383 2530
 
2384
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2385
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2386
-	elseif (isset($modSettings['agreement']))
2531
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2532
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2533
+	} elseif (isset($modSettings['agreement']))
2387 2534
 	{
2388 2535
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2389 2536
 		fwrite($fp, $modSettings['agreement']);
@@ -2393,31 +2540,36 @@  discard block
 block discarded – undo
2393 2540
 	// Make sure Themes is writable.
2394 2541
 	quickFileWritable($modSettings['theme_dir']);
2395 2542
 
2396
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2397
-		print_error('Error: Unable to obtain write access to "Themes".');
2543
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2544
+			print_error('Error: Unable to obtain write access to "Themes".');
2545
+	}
2398 2546
 
2399 2547
 	// Make sure cache directory exists and is writable!
2400 2548
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2401
-	if (!file_exists($cachedir_temp))
2402
-		@mkdir($cachedir_temp);
2549
+	if (!file_exists($cachedir_temp)) {
2550
+			@mkdir($cachedir_temp);
2551
+	}
2403 2552
 
2404 2553
 	// Make sure the cache temp dir is writable.
2405 2554
 	quickFileWritable($cachedir_temp);
2406 2555
 
2407
-	if (!is_writable($cachedir_temp))
2408
-		print_error('Error: Unable to obtain write access to "cache".', true);
2556
+	if (!is_writable($cachedir_temp)) {
2557
+			print_error('Error: Unable to obtain write access to "cache".', true);
2558
+	}
2409 2559
 
2410
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2411
-		print_error('Error: Unable to find language files!', true);
2412
-	else
2560
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2561
+			print_error('Error: Unable to find language files!', true);
2562
+	} else
2413 2563
 	{
2414 2564
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2415 2565
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2416 2566
 
2417
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2418
-			print_error('Error: Language files out of date.', true);
2419
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2420
-			print_error('Error: Install language is missing for selected language.', true);
2567
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2568
+					print_error('Error: Language files out of date.', true);
2569
+		}
2570
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2571
+					print_error('Error: Install language is missing for selected language.', true);
2572
+		}
2421 2573
 
2422 2574
 		// Otherwise include it!
2423 2575
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2446,8 +2598,7 @@  discard block
 block discarded – undo
2446 2598
 		);
2447 2599
 
2448 2600
 		return true;
2449
-	}
2450
-	else
2601
+	} else
2451 2602
 	{
2452 2603
 		$upcontext['page_title'] = 'Converting to UTF8';
2453 2604
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2491,8 +2642,9 @@  discard block
 block discarded – undo
2491 2642
 			)
2492 2643
 		);
2493 2644
 		$db_charsets = array();
2494
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2495
-			$db_charsets[] = $row['Charset'];
2645
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2646
+					$db_charsets[] = $row['Charset'];
2647
+		}
2496 2648
 
2497 2649
 		$smcFunc['db_free_result']($request);
2498 2650
 
@@ -2528,13 +2680,15 @@  discard block
 block discarded – undo
2528 2680
 		// If there's a fulltext index, we need to drop it first...
2529 2681
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2530 2682
 		{
2531
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2532
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2683
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2684
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2533 2685
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2686
+			}
2534 2687
 			$smcFunc['db_free_result']($request);
2535 2688
 
2536
-			if (isset($upcontext['fulltext_index']))
2537
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2689
+			if (isset($upcontext['fulltext_index'])) {
2690
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2691
+			}
2538 2692
 		}
2539 2693
 
2540 2694
 		// Drop it and make a note...
@@ -2724,8 +2878,9 @@  discard block
 block discarded – undo
2724 2878
 			$replace = '%field%';
2725 2879
 
2726 2880
 			// Build a huge REPLACE statement...
2727
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2728
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2881
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2882
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2883
+			}
2729 2884
 		}
2730 2885
 
2731 2886
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2759,8 +2914,9 @@  discard block
 block discarded – undo
2759 2914
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2760 2915
 
2761 2916
 			// Just to make sure it doesn't time out.
2762
-			if (function_exists('apache_reset_timeout'))
2763
-				@apache_reset_timeout();
2917
+			if (function_exists('apache_reset_timeout')) {
2918
+							@apache_reset_timeout();
2919
+			}
2764 2920
 
2765 2921
 			$table_charsets = array();
2766 2922
 
@@ -2781,8 +2937,9 @@  discard block
 block discarded – undo
2781 2937
 					{
2782 2938
 						list($charset) = explode('_', $collation);
2783 2939
 
2784
-						if (!isset($table_charsets[$charset]))
2785
-							$table_charsets[$charset] = array();
2940
+						if (!isset($table_charsets[$charset])) {
2941
+													$table_charsets[$charset] = array();
2942
+						}
2786 2943
 
2787 2944
 						$table_charsets[$charset][] = $column_info;
2788 2945
 					}
@@ -2822,10 +2979,11 @@  discard block
 block discarded – undo
2822 2979
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2823 2980
 				{
2824 2981
 					$update = '';
2825
-					foreach ($table_charsets as $charset => $columns)
2826
-						foreach ($columns as $column)
2982
+					foreach ($table_charsets as $charset => $columns) {
2983
+											foreach ($columns as $column)
2827 2984
 							$update .= '
2828 2985
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2986
+					}
2829 2987
 
2830 2988
 					$smcFunc['db_query']('', '
2831 2989
 						UPDATE {raw:table_name}
@@ -2850,8 +3008,9 @@  discard block
 block discarded – undo
2850 3008
 			// Now do the actual conversion (if still needed).
2851 3009
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2852 3010
 			{
2853
-				if ($command_line)
2854
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3011
+				if ($command_line) {
3012
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3013
+				}
2855 3014
 
2856 3015
 				$smcFunc['db_query']('', '
2857 3016
 					ALTER TABLE {raw:table_name}
@@ -2861,8 +3020,9 @@  discard block
 block discarded – undo
2861 3020
 					)
2862 3021
 				);
2863 3022
 
2864
-				if ($command_line)
2865
-					echo " done.\n";
3023
+				if ($command_line) {
3024
+									echo " done.\n";
3025
+				}
2866 3026
 			}
2867 3027
 		}
2868 3028
 
@@ -2892,8 +3052,8 @@  discard block
 block discarded – undo
2892 3052
 		);
2893 3053
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2894 3054
 		{
2895
-			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)
2896
-				$smcFunc['db_query']('', '
3055
+			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) {
3056
+							$smcFunc['db_query']('', '
2897 3057
 					UPDATE {db_prefix}log_actions
2898 3058
 					SET extra = {string:extra}
2899 3059
 					WHERE id_action = {int:current_action}',
@@ -2902,6 +3062,7 @@  discard block
 block discarded – undo
2902 3062
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2903 3063
 					)
2904 3064
 				);
3065
+			}
2905 3066
 		}
2906 3067
 		$smcFunc['db_free_result']($request);
2907 3068
 
@@ -2923,15 +3084,17 @@  discard block
 block discarded – undo
2923 3084
 	// First thing's first - did we already do this?
2924 3085
 	if (!empty($modSettings['json_done']))
2925 3086
 	{
2926
-		if ($command_line)
2927
-			return DeleteUpgrade();
2928
-		else
2929
-			return true;
3087
+		if ($command_line) {
3088
+					return DeleteUpgrade();
3089
+		} else {
3090
+					return true;
3091
+		}
2930 3092
 	}
2931 3093
 
2932 3094
 	// Done it already - js wise?
2933
-	if (!empty($_POST['json_done']))
2934
-		return true;
3095
+	if (!empty($_POST['json_done'])) {
3096
+			return true;
3097
+	}
2935 3098
 
2936 3099
 	// List of tables affected by this function
2937 3100
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2962,12 +3125,14 @@  discard block
 block discarded – undo
2962 3125
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2963 3126
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2964 3127
 
2965
-	foreach ($keys as $id => $table)
2966
-		if ($id < $_GET['substep'])
3128
+	foreach ($keys as $id => $table) {
3129
+			if ($id < $_GET['substep'])
2967 3130
 			$upcontext['previous_tables'][] = $table;
3131
+	}
2968 3132
 
2969
-	if ($command_line)
2970
-		echo 'Converting data from serialize() to json_encode().';
3133
+	if ($command_line) {
3134
+			echo 'Converting data from serialize() to json_encode().';
3135
+	}
2971 3136
 
2972 3137
 	if (!$support_js || isset($_GET['xml']))
2973 3138
 	{
@@ -3007,8 +3172,9 @@  discard block
 block discarded – undo
3007 3172
 
3008 3173
 				// Loop through and fix these...
3009 3174
 				$new_settings = array();
3010
-				if ($command_line)
3011
-					echo "\n" . 'Fixing some settings...';
3175
+				if ($command_line) {
3176
+									echo "\n" . 'Fixing some settings...';
3177
+				}
3012 3178
 
3013 3179
 				foreach ($serialized_settings as $var)
3014 3180
 				{
@@ -3016,22 +3182,24 @@  discard block
 block discarded – undo
3016 3182
 					{
3017 3183
 						// Attempt to unserialize the setting
3018 3184
 						$temp = @safe_unserialize($modSettings[$var]);
3019
-						if (!$temp && $command_line)
3020
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3021
-						elseif ($temp !== false)
3022
-							$new_settings[$var] = json_encode($temp);
3185
+						if (!$temp && $command_line) {
3186
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3187
+						} elseif ($temp !== false) {
3188
+													$new_settings[$var] = json_encode($temp);
3189
+						}
3023 3190
 					}
3024 3191
 				}
3025 3192
 
3026 3193
 				// Update everything at once
3027
-				if (!function_exists('cache_put_data'))
3028
-					require_once($sourcedir . '/Load.php');
3194
+				if (!function_exists('cache_put_data')) {
3195
+									require_once($sourcedir . '/Load.php');
3196
+				}
3029 3197
 				updateSettings($new_settings, true);
3030 3198
 
3031
-				if ($command_line)
3032
-					echo ' done.';
3033
-			}
3034
-			elseif ($table == 'themes')
3199
+				if ($command_line) {
3200
+									echo ' done.';
3201
+				}
3202
+			} elseif ($table == 'themes')
3035 3203
 			{
3036 3204
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3037 3205
 				$query = $smcFunc['db_query']('', '
@@ -3050,10 +3218,11 @@  discard block
 block discarded – undo
3050 3218
 
3051 3219
 						if ($command_line)
3052 3220
 						{
3053
-							if ($temp === false)
3054
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3055
-							else
3056
-								echo "\n" . 'Fixing admin preferences...';
3221
+							if ($temp === false) {
3222
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3223
+							} else {
3224
+															echo "\n" . 'Fixing admin preferences...';
3225
+							}
3057 3226
 						}
3058 3227
 
3059 3228
 						if ($temp !== false)
@@ -3075,15 +3244,15 @@  discard block
 block discarded – undo
3075 3244
 								)
3076 3245
 							);
3077 3246
 
3078
-							if ($command_line)
3079
-								echo ' done.';
3247
+							if ($command_line) {
3248
+															echo ' done.';
3249
+							}
3080 3250
 						}
3081 3251
 					}
3082 3252
 
3083 3253
 					$smcFunc['db_free_result']($query);
3084 3254
 				}
3085
-			}
3086
-			else
3255
+			} else
3087 3256
 			{
3088 3257
 				// First item is always the key...
3089 3258
 				$key = $info[0];
@@ -3094,8 +3263,7 @@  discard block
 block discarded – undo
3094 3263
 				{
3095 3264
 					$col_select = $info[1];
3096 3265
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3097
-				}
3098
-				else
3266
+				} else
3099 3267
 				{
3100 3268
 					$col_select = implode(', ', $info);
3101 3269
 				}
@@ -3128,8 +3296,7 @@  discard block
 block discarded – undo
3128 3296
 								if ($temp === false && $command_line)
3129 3297
 								{
3130 3298
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3131
-								}
3132
-								else
3299
+								} else
3133 3300
 								{
3134 3301
 									$row[$col] = json_encode($temp);
3135 3302
 
@@ -3154,16 +3321,18 @@  discard block
 block discarded – undo
3154 3321
 						}
3155 3322
 					}
3156 3323
 
3157
-					if ($command_line)
3158
-						echo ' done.';
3324
+					if ($command_line) {
3325
+											echo ' done.';
3326
+					}
3159 3327
 
3160 3328
 					// Free up some memory...
3161 3329
 					$smcFunc['db_free_result']($query);
3162 3330
 				}
3163 3331
 			}
3164 3332
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3165
-			if (isset($_GET['xml']))
3166
-				return upgradeExit();
3333
+			if (isset($_GET['xml'])) {
3334
+							return upgradeExit();
3335
+			}
3167 3336
 		}
3168 3337
 
3169 3338
 		if ($command_line)
@@ -3178,8 +3347,9 @@  discard block
 block discarded – undo
3178 3347
 
3179 3348
 		$_GET['substep'] = 0;
3180 3349
 		// Make sure we move on!
3181
-		if ($command_line)
3182
-			return DeleteUpgrade();
3350
+		if ($command_line) {
3351
+					return DeleteUpgrade();
3352
+		}
3183 3353
 
3184 3354
 		return true;
3185 3355
 	}
@@ -3199,14 +3369,16 @@  discard block
 block discarded – undo
3199 3369
 	global $upcontext, $txt, $settings;
3200 3370
 
3201 3371
 	// Don't call me twice!
3202
-	if (!empty($upcontext['chmod_called']))
3203
-		return;
3372
+	if (!empty($upcontext['chmod_called'])) {
3373
+			return;
3374
+	}
3204 3375
 
3205 3376
 	$upcontext['chmod_called'] = true;
3206 3377
 
3207 3378
 	// Nothing?
3208
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3209
-		return;
3379
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3380
+			return;
3381
+	}
3210 3382
 
3211 3383
 	// Was it a problem with Windows?
3212 3384
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3238,11 +3410,12 @@  discard block
 block discarded – undo
3238 3410
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3239 3411
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3240 3412
 
3241
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3242
-		echo '
3413
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3414
+			echo '
3243 3415
 					content.write(\'<hr>\n\t\t\t\');
3244 3416
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3245 3417
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3418
+	}
3246 3419
 
3247 3420
 	echo '
3248 3421
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3250,17 +3423,19 @@  discard block
 block discarded – undo
3250 3423
 				}
3251 3424
 		</script>';
3252 3425
 
3253
-	if (!empty($upcontext['chmod']['ftp_error']))
3254
-		echo '
3426
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3427
+			echo '
3255 3428
 			<div class="error_message red">
3256 3429
 				The following error was encountered when trying to connect:<br><br>
3257 3430
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3258 3431
 			</div>
3259 3432
 			<br>';
3433
+	}
3260 3434
 
3261
-	if (empty($upcontext['chmod_in_form']))
3262
-		echo '
3435
+	if (empty($upcontext['chmod_in_form'])) {
3436
+			echo '
3263 3437
 	<form action="', $upcontext['form_url'], '" method="post">';
3438
+	}
3264 3439
 
3265 3440
 	echo '
3266 3441
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3295,10 +3470,11 @@  discard block
 block discarded – undo
3295 3470
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3296 3471
 	</div>';
3297 3472
 
3298
-	if (empty($upcontext['chmod_in_form']))
3299
-		echo '
3473
+	if (empty($upcontext['chmod_in_form'])) {
3474
+			echo '
3300 3475
 	</form>';
3301
-}
3476
+	}
3477
+	}
3302 3478
 
3303 3479
 function template_upgrade_above()
3304 3480
 {
@@ -3358,9 +3534,10 @@  discard block
 block discarded – undo
3358 3534
 				<h2>', $txt['upgrade_progress'], '</h2>
3359 3535
 				<ul>';
3360 3536
 
3361
-	foreach ($upcontext['steps'] as $num => $step)
3362
-		echo '
3537
+	foreach ($upcontext['steps'] as $num => $step) {
3538
+			echo '
3363 3539
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3540
+	}
3364 3541
 
3365 3542
 	echo '
3366 3543
 					</ul>
@@ -3373,8 +3550,8 @@  discard block
 block discarded – undo
3373 3550
 				</div>
3374 3551
 			</div>';
3375 3552
 
3376
-	if (isset($upcontext['step_progress']))
3377
-		echo '
3553
+	if (isset($upcontext['step_progress'])) {
3554
+			echo '
3378 3555
 				<br>
3379 3556
 				<br>
3380 3557
 				<div id="progress_bar_step">
@@ -3383,6 +3560,7 @@  discard block
 block discarded – undo
3383 3560
 						<span>', $txt['upgrade_step_progress'], '</span>
3384 3561
 					</div>
3385 3562
 				</div>';
3563
+	}
3386 3564
 
3387 3565
 	echo '
3388 3566
 				<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>
@@ -3413,32 +3591,36 @@  discard block
 block discarded – undo
3413 3591
 {
3414 3592
 	global $upcontext, $txt;
3415 3593
 
3416
-	if (!empty($upcontext['pause']))
3417
-		echo '
3594
+	if (!empty($upcontext['pause'])) {
3595
+			echo '
3418 3596
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3419 3597
 
3420 3598
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3421 3599
 								<h3>
3422 3600
 									', $txt['upgrade_paused_overload'], '
3423 3601
 								</h3>';
3602
+	}
3424 3603
 
3425
-	if (!empty($upcontext['custom_warning']))
3426
-		echo '
3604
+	if (!empty($upcontext['custom_warning'])) {
3605
+			echo '
3427 3606
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3428 3607
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3429 3608
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3430 3609
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3431 3610
 								</div>';
3611
+	}
3432 3612
 
3433 3613
 	echo '
3434 3614
 								<div class="righttext" style="margin: 1ex;">';
3435 3615
 
3436
-	if (!empty($upcontext['continue']))
3437
-		echo '
3616
+	if (!empty($upcontext['continue'])) {
3617
+			echo '
3438 3618
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3439
-	if (!empty($upcontext['skip']))
3440
-		echo '
3619
+	}
3620
+	if (!empty($upcontext['skip'])) {
3621
+			echo '
3441 3622
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3623
+	}
3442 3624
 
3443 3625
 	echo '
3444 3626
 								</div>
@@ -3488,11 +3670,12 @@  discard block
 block discarded – undo
3488 3670
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3489 3671
 	<smf>';
3490 3672
 
3491
-	if (!empty($upcontext['get_data']))
3492
-		foreach ($upcontext['get_data'] as $k => $v)
3673
+	if (!empty($upcontext['get_data'])) {
3674
+			foreach ($upcontext['get_data'] as $k => $v)
3493 3675
 			echo '
3494 3676
 		<get key="', $k, '">', $v, '</get>';
3495
-}
3677
+	}
3678
+	}
3496 3679
 
3497 3680
 function template_xml_below()
3498 3681
 {
@@ -3533,8 +3716,8 @@  discard block
 block discarded – undo
3533 3716
 	template_chmod();
3534 3717
 
3535 3718
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3536
-	if ($upcontext['is_large_forum'])
3537
-		echo '
3719
+	if ($upcontext['is_large_forum']) {
3720
+			echo '
3538 3721
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3539 3722
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3540 3723
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3542,10 +3725,11 @@  discard block
 block discarded – undo
3542 3725
 				', $txt['upgrade_warning_lots_data'], '
3543 3726
 			</div>
3544 3727
 		</div>';
3728
+	}
3545 3729
 
3546 3730
 	// A warning message?
3547
-	if (!empty($upcontext['warning']))
3548
-		echo '
3731
+	if (!empty($upcontext['warning'])) {
3732
+			echo '
3549 3733
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3550 3734
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3551 3735
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3553,6 +3737,7 @@  discard block
 block discarded – undo
3553 3737
 				', $upcontext['warning'], '
3554 3738
 			</div>
3555 3739
 		</div>';
3740
+	}
3556 3741
 
3557 3742
 	// Paths are incorrect?
3558 3743
 	echo '
@@ -3568,20 +3753,22 @@  discard block
 block discarded – undo
3568 3753
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3569 3754
 	{
3570 3755
 		$ago = time() - $upcontext['started'];
3571
-		if ($ago < 60)
3572
-			$ago = $ago . ' seconds';
3573
-		elseif ($ago < 3600)
3574
-			$ago = (int) ($ago / 60) . ' minutes';
3575
-		else
3576
-			$ago = (int) ($ago / 3600) . ' hours';
3756
+		if ($ago < 60) {
3757
+					$ago = $ago . ' seconds';
3758
+		} elseif ($ago < 3600) {
3759
+					$ago = (int) ($ago / 60) . ' minutes';
3760
+		} else {
3761
+					$ago = (int) ($ago / 3600) . ' hours';
3762
+		}
3577 3763
 
3578 3764
 		$active = time() - $upcontext['updated'];
3579
-		if ($active < 60)
3580
-			$updated = $active . ' seconds';
3581
-		elseif ($active < 3600)
3582
-			$updated = (int) ($active / 60) . ' minutes';
3583
-		else
3584
-			$updated = (int) ($active / 3600) . ' hours';
3765
+		if ($active < 60) {
3766
+					$updated = $active . ' seconds';
3767
+		} elseif ($active < 3600) {
3768
+					$updated = (int) ($active / 60) . ' minutes';
3769
+		} else {
3770
+					$updated = (int) ($active / 3600) . ' hours';
3771
+		}
3585 3772
 
3586 3773
 		echo '
3587 3774
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3590,16 +3777,18 @@  discard block
 block discarded – undo
3590 3777
 			<div style="padding-left: 6ex;">
3591 3778
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3592 3779
 
3593
-		if ($active < 600)
3594
-			echo '
3780
+		if ($active < 600) {
3781
+					echo '
3595 3782
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3783
+		}
3596 3784
 
3597
-		if ($active > $upcontext['inactive_timeout'])
3598
-			echo '
3785
+		if ($active > $upcontext['inactive_timeout']) {
3786
+					echo '
3599 3787
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3600
-		else
3601
-			echo '
3788
+		} else {
3789
+					echo '
3602 3790
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3791
+		}
3603 3792
 
3604 3793
 		echo '
3605 3794
 			</div>
@@ -3615,9 +3804,10 @@  discard block
 block discarded – undo
3615 3804
 					<td>
3616 3805
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3617 3806
 
3618
-	if (!empty($upcontext['username_incorrect']))
3619
-		echo '
3807
+	if (!empty($upcontext['username_incorrect'])) {
3808
+			echo '
3620 3809
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3810
+	}
3621 3811
 
3622 3812
 	echo '
3623 3813
 					</td>
@@ -3628,9 +3818,10 @@  discard block
 block discarded – undo
3628 3818
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3629 3819
 						<input type="hidden" name="hash_passwrd" value="">';
3630 3820
 
3631
-	if (!empty($upcontext['password_failed']))
3632
-		echo '
3821
+	if (!empty($upcontext['password_failed'])) {
3822
+			echo '
3633 3823
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3824
+	}
3634 3825
 
3635 3826
 	echo '
3636 3827
 					</td>
@@ -3701,8 +3892,8 @@  discard block
 block discarded – undo
3701 3892
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3702 3893
 
3703 3894
 	// Warning message?
3704
-	if (!empty($upcontext['upgrade_options_warning']))
3705
-		echo '
3895
+	if (!empty($upcontext['upgrade_options_warning'])) {
3896
+			echo '
3706 3897
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3707 3898
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3708 3899
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3710,6 +3901,7 @@  discard block
 block discarded – undo
3710 3901
 				', $upcontext['upgrade_options_warning'], '
3711 3902
 			</div>
3712 3903
 		</div>';
3904
+	}
3713 3905
 
3714 3906
 	echo '
3715 3907
 				<table>
@@ -3752,8 +3944,8 @@  discard block
 block discarded – undo
3752 3944
 						</td>
3753 3945
 					</tr>';
3754 3946
 
3755
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3756
-		echo '
3947
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3948
+			echo '
3757 3949
 					<tr valign="top">
3758 3950
 						<td width="2%">
3759 3951
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3762,6 +3954,7 @@  discard block
 block discarded – undo
3762 3954
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3763 3955
 						</td>
3764 3956
 					</tr>';
3957
+	}
3765 3958
 
3766 3959
 	echo '
3767 3960
 					<tr valign="top">
@@ -3799,10 +3992,11 @@  discard block
 block discarded – undo
3799 3992
 			</div>';
3800 3993
 
3801 3994
 	// Dont any tables so far?
3802
-	if (!empty($upcontext['previous_tables']))
3803
-		foreach ($upcontext['previous_tables'] as $table)
3995
+	if (!empty($upcontext['previous_tables'])) {
3996
+			foreach ($upcontext['previous_tables'] as $table)
3804 3997
 			echo '
3805 3998
 			<br>Completed Table: &quot;', $table, '&quot;.';
3999
+	}
3806 4000
 
3807 4001
 	echo '
3808 4002
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3839,12 +4033,13 @@  discard block
 block discarded – undo
3839 4033
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3840 4034
 
3841 4035
 		// If debug flood the screen.
3842
-		if ($is_debug)
3843
-			echo '
4036
+		if ($is_debug) {
4037
+					echo '
3844 4038
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3845 4039
 
3846 4040
 				if (document.getElementById(\'debug_section\').scrollHeight)
3847 4041
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4042
+		}
3848 4043
 
3849 4044
 		echo '
3850 4045
 				// Get the next update...
@@ -3876,8 +4071,9 @@  discard block
 block discarded – undo
3876 4071
 {
3877 4072
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3878 4073
 
3879
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3880
-		$is_debug = true;
4074
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4075
+			$is_debug = true;
4076
+	}
3881 4077
 
3882 4078
 	echo '
3883 4079
 		<h3>Executing database changes</h3>
@@ -3892,8 +4088,9 @@  discard block
 block discarded – undo
3892 4088
 	{
3893 4089
 		foreach ($upcontext['actioned_items'] as $num => $item)
3894 4090
 		{
3895
-			if ($num != 0)
3896
-				echo ' Successful!';
4091
+			if ($num != 0) {
4092
+							echo ' Successful!';
4093
+			}
3897 4094
 			echo '<br>' . $item;
3898 4095
 		}
3899 4096
 		if (!empty($upcontext['changes_complete']))
@@ -3906,28 +4103,32 @@  discard block
 block discarded – undo
3906 4103
 				$seconds = intval($active % 60);
3907 4104
 
3908 4105
 				$totalTime = '';
3909
-				if ($hours > 0)
3910
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3911
-				if ($minutes > 0)
3912
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3913
-				if ($seconds > 0)
3914
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4106
+				if ($hours > 0) {
4107
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4108
+				}
4109
+				if ($minutes > 0) {
4110
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4111
+				}
4112
+				if ($seconds > 0) {
4113
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4114
+				}
3915 4115
 			}
3916 4116
 
3917
-			if ($is_debug && !empty($totalTime))
3918
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3919
-			else
3920
-				echo ' Successful!<br><br>';
4117
+			if ($is_debug && !empty($totalTime)) {
4118
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4119
+			} else {
4120
+							echo ' Successful!<br><br>';
4121
+			}
3921 4122
 
3922 4123
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3923 4124
 		}
3924
-	}
3925
-	else
4125
+	} else
3926 4126
 	{
3927 4127
 		// Tell them how many files we have in total.
3928
-		if ($upcontext['file_count'] > 1)
3929
-			echo '
4128
+		if ($upcontext['file_count'] > 1) {
4129
+					echo '
3930 4130
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4131
+		}
3931 4132
 
3932 4133
 		echo '
3933 4134
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3943,19 +4144,23 @@  discard block
 block discarded – undo
3943 4144
 				$seconds = intval($active % 60);
3944 4145
 
3945 4146
 				$totalTime = '';
3946
-				if ($hours > 0)
3947
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3948
-				if ($minutes > 0)
3949
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3950
-				if ($seconds > 0)
3951
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4147
+				if ($hours > 0) {
4148
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4149
+				}
4150
+				if ($minutes > 0) {
4151
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4152
+				}
4153
+				if ($seconds > 0) {
4154
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4155
+				}
3952 4156
 			}
3953 4157
 
3954 4158
 			echo '
3955 4159
 			<br><span id="upgradeCompleted">';
3956 4160
 
3957
-			if (!empty($totalTime))
3958
-				echo 'Completed in ', $totalTime, '<br>';
4161
+			if (!empty($totalTime)) {
4162
+							echo 'Completed in ', $totalTime, '<br>';
4163
+			}
3959 4164
 
3960 4165
 			echo '</span>
3961 4166
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -3992,9 +4197,10 @@  discard block
 block discarded – undo
3992 4197
 			var getData = "";
3993 4198
 			var debugItems = ', $upcontext['debug_items'], ';';
3994 4199
 
3995
-		if ($is_debug)
3996
-			echo '
4200
+		if ($is_debug) {
4201
+					echo '
3997 4202
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4203
+		}
3998 4204
 
3999 4205
 		echo '
4000 4206
 			function getNextItem()
@@ -4034,9 +4240,10 @@  discard block
 block discarded – undo
4034 4240
 						document.getElementById("error_block").style.display = "";
4035 4241
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4036 4242
 
4037
-	if ($is_debug)
4038
-		echo '
4243
+	if ($is_debug) {
4244
+			echo '
4039 4245
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4246
+	}
4040 4247
 
4041 4248
 	echo '
4042 4249
 					}
@@ -4057,9 +4264,10 @@  discard block
 block discarded – undo
4057 4264
 						document.getElementById("error_block").style.display = "";
4058 4265
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4059 4266
 
4060
-	if ($is_debug)
4061
-		echo '
4267
+	if ($is_debug) {
4268
+			echo '
4062 4269
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4270
+	}
4063 4271
 
4064 4272
 	echo '
4065 4273
 					}
@@ -4118,8 +4326,8 @@  discard block
 block discarded – undo
4118 4326
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4119 4327
 				{';
4120 4328
 
4121
-		if ($is_debug)
4122
-			echo '
4329
+		if ($is_debug) {
4330
+					echo '
4123 4331
 					document.getElementById(\'debug_section\').style.display = "none";
4124 4332
 
4125 4333
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4137,6 +4345,7 @@  discard block
 block discarded – undo
4137 4345
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4138 4346
 
4139 4347
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4348
+		}
4140 4349
 
4141 4350
 		echo '
4142 4351
 
@@ -4144,9 +4353,10 @@  discard block
 block discarded – undo
4144 4353
 					document.getElementById(\'contbutt\').disabled = 0;
4145 4354
 					document.getElementById(\'database_done\').value = 1;';
4146 4355
 
4147
-		if ($upcontext['file_count'] > 1)
4148
-			echo '
4356
+		if ($upcontext['file_count'] > 1) {
4357
+					echo '
4149 4358
 					document.getElementById(\'info1\').style.display = "none";';
4359
+		}
4150 4360
 
4151 4361
 		echo '
4152 4362
 					document.getElementById(\'info2\').style.display = "none";
@@ -4159,9 +4369,10 @@  discard block
 block discarded – undo
4159 4369
 					lastItem = 0;
4160 4370
 					prevFile = curFile;';
4161 4371
 
4162
-		if ($is_debug)
4163
-			echo '
4372
+		if ($is_debug) {
4373
+					echo '
4164 4374
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4375
+		}
4165 4376
 
4166 4377
 		echo '
4167 4378
 					getNextItem();
@@ -4169,8 +4380,8 @@  discard block
 block discarded – undo
4169 4380
 				}';
4170 4381
 
4171 4382
 		// If debug scroll the screen.
4172
-		if ($is_debug)
4173
-			echo '
4383
+		if ($is_debug) {
4384
+					echo '
4174 4385
 				if (iLastSubStepProgress == -1)
4175 4386
 				{
4176 4387
 					// Give it consistent dots.
@@ -4189,6 +4400,7 @@  discard block
 block discarded – undo
4189 4400
 
4190 4401
 				if (document.getElementById(\'debug_section\').scrollHeight)
4191 4402
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4403
+		}
4192 4404
 
4193 4405
 		echo '
4194 4406
 				// Update the page.
@@ -4249,9 +4461,10 @@  discard block
 block discarded – undo
4249 4461
 			}';
4250 4462
 
4251 4463
 		// Start things off assuming we've not errored.
4252
-		if (empty($upcontext['error_message']))
4253
-			echo '
4464
+		if (empty($upcontext['error_message'])) {
4465
+					echo '
4254 4466
 			getNextItem();';
4467
+		}
4255 4468
 
4256 4469
 		echo '
4257 4470
 		</script>';
@@ -4268,18 +4481,21 @@  discard block
 block discarded – undo
4268 4481
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4269 4482
 	<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>';
4270 4483
 
4271
-	if (!empty($upcontext['error_message']))
4272
-		echo '
4484
+	if (!empty($upcontext['error_message'])) {
4485
+			echo '
4273 4486
 	<error>', $upcontext['error_message'], '</error>';
4487
+	}
4274 4488
 
4275
-	if (!empty($upcontext['error_string']))
4276
-		echo '
4489
+	if (!empty($upcontext['error_string'])) {
4490
+			echo '
4277 4491
 	<sql>', $upcontext['error_string'], '</sql>';
4492
+	}
4278 4493
 
4279
-	if ($is_debug)
4280
-		echo '
4494
+	if ($is_debug) {
4495
+			echo '
4281 4496
 	<curtime>', time(), '</curtime>';
4282
-}
4497
+	}
4498
+	}
4283 4499
 
4284 4500
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4285 4501
 function template_convert_utf8()
@@ -4296,18 +4512,20 @@  discard block
 block discarded – undo
4296 4512
 			<span id="debuginfo"></span>';
4297 4513
 
4298 4514
 	// Done any tables so far?
4299
-	if (!empty($upcontext['previous_tables']))
4300
-		foreach ($upcontext['previous_tables'] as $table)
4515
+	if (!empty($upcontext['previous_tables'])) {
4516
+			foreach ($upcontext['previous_tables'] as $table)
4301 4517
 			echo '
4302 4518
 			<br>Completed Table: &quot;', $table, '&quot;.';
4519
+	}
4303 4520
 
4304 4521
 	echo '
4305 4522
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4306 4523
 
4307 4524
 	// If we dropped their index, let's let them know
4308
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4309
-		echo '
4525
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4526
+			echo '
4310 4527
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4528
+	}
4311 4529
 
4312 4530
 	echo '
4313 4531
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4343,9 +4561,10 @@  discard block
 block discarded – undo
4343 4561
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4344 4562
 
4345 4563
 		// If debug flood the screen.
4346
-		if ($is_debug)
4347
-			echo '
4564
+		if ($is_debug) {
4565
+					echo '
4348 4566
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4567
+		}
4349 4568
 
4350 4569
 		echo '
4351 4570
 				// Get the next update...
@@ -4387,19 +4606,21 @@  discard block
 block discarded – undo
4387 4606
 			<span id="debuginfo"></span>';
4388 4607
 
4389 4608
 	// Dont any tables so far?
4390
-	if (!empty($upcontext['previous_tables']))
4391
-		foreach ($upcontext['previous_tables'] as $table)
4609
+	if (!empty($upcontext['previous_tables'])) {
4610
+			foreach ($upcontext['previous_tables'] as $table)
4392 4611
 			echo '
4393 4612
 			<br>Completed Table: &quot;', $table, '&quot;.';
4613
+	}
4394 4614
 
4395 4615
 	echo '
4396 4616
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4397 4617
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4398 4618
 
4399 4619
 	// Try to make sure substep was reset.
4400
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4401
-		echo '
4620
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4621
+			echo '
4402 4622
 			<input type="hidden" name="substep" id="substep" value="0">';
4623
+	}
4403 4624
 
4404 4625
 	// Continue please!
4405 4626
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4432,9 +4653,10 @@  discard block
 block discarded – undo
4432 4653
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4433 4654
 
4434 4655
 		// If debug flood the screen.
4435
-		if ($is_debug)
4436
-			echo '
4656
+		if ($is_debug) {
4657
+					echo '
4437 4658
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4659
+		}
4438 4660
 
4439 4661
 		echo '
4440 4662
 				// Get the next update...
@@ -4469,8 +4691,8 @@  discard block
 block discarded – undo
4469 4691
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4470 4692
 	<form action="', $boardurl, '/index.php">';
4471 4693
 
4472
-	if (!empty($upcontext['can_delete_script']))
4473
-		echo '
4694
+	if (!empty($upcontext['can_delete_script'])) {
4695
+			echo '
4474 4696
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4475 4697
 			<script>
4476 4698
 				function doTheDelete(theCheck)
@@ -4482,6 +4704,7 @@  discard block
 block discarded – undo
4482 4704
 				}
4483 4705
 			</script>
4484 4706
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4707
+	}
4485 4708
 
4486 4709
 	$active = time() - $upcontext['started'];
4487 4710
 	$hours = floor($active / 3600);
@@ -4491,16 +4714,20 @@  discard block
 block discarded – undo
4491 4714
 	if ($is_debug)
4492 4715
 	{
4493 4716
 		$totalTime = '';
4494
-		if ($hours > 0)
4495
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4496
-		if ($minutes > 0)
4497
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4498
-		if ($seconds > 0)
4499
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4717
+		if ($hours > 0) {
4718
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4719
+		}
4720
+		if ($minutes > 0) {
4721
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4722
+		}
4723
+		if ($seconds > 0) {
4724
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4725
+		}
4500 4726
 	}
4501 4727
 
4502
-	if ($is_debug && !empty($totalTime))
4503
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4728
+	if ($is_debug && !empty($totalTime)) {
4729
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4730
+	}
4504 4731
 
4505 4732
 	echo '<br>
4506 4733
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4567,16 +4794,19 @@  discard block
 block discarded – undo
4567 4794
 				'empty' => '',
4568 4795
 				'limit' => $limit,
4569 4796
 		));
4570
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4571
-			$arIp[] = $row[$oldCol];
4797
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4798
+					$arIp[] = $row[$oldCol];
4799
+		}
4572 4800
 		$smcFunc['db_free_result']($request);
4573 4801
 
4574 4802
 		// Special case, null ip could keep us in a loop.
4575
-		if (is_null($arIp[0]))
4576
-			unset($arIp[0]);
4803
+		if (is_null($arIp[0])) {
4804
+					unset($arIp[0]);
4805
+		}
4577 4806
 
4578
-		if (empty($arIp))
4579
-			$is_done = true;
4807
+		if (empty($arIp)) {
4808
+					$is_done = true;
4809
+		}
4580 4810
 
4581 4811
 		$updates = array();
4582 4812
 		$cases = array();
@@ -4585,16 +4815,18 @@  discard block
 block discarded – undo
4585 4815
 		{
4586 4816
 			$arIp[$i] = trim($arIp[$i]);
4587 4817
 
4588
-			if (empty($arIp[$i]))
4589
-				continue;
4818
+			if (empty($arIp[$i])) {
4819
+							continue;
4820
+			}
4590 4821
 
4591 4822
 			$updates['ip' . $i] = $arIp[$i];
4592 4823
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4593 4824
 
4594 4825
 			if ($setSize > 0 && $i % $setSize === 0)
4595 4826
 			{
4596
-				if (count($updates) == 1)
4597
-					continue;
4827
+				if (count($updates) == 1) {
4828
+									continue;
4829
+				}
4598 4830
 
4599 4831
 				$updates['whereSet'] = array_values($updates);
4600 4832
 				$smcFunc['db_query']('', '
@@ -4628,8 +4860,7 @@  discard block
 block discarded – undo
4628 4860
 							'ip' => $ip
4629 4861
 					));
4630 4862
 				}
4631
-			}
4632
-			else
4863
+			} else
4633 4864
 			{
4634 4865
 				$updates['whereSet'] = array_values($updates);
4635 4866
 				$smcFunc['db_query']('', '
@@ -4643,9 +4874,9 @@  discard block
 block discarded – undo
4643 4874
 					$updates
4644 4875
 				);
4645 4876
 			}
4877
+		} else {
4878
+					$is_done = true;
4646 4879
 		}
4647
-		else
4648
-			$is_done = true;
4649 4880
 
4650 4881
 		$_GET['a'] += $limit;
4651 4882
 		$step_progress['current'] = $_GET['a'];
@@ -4671,10 +4902,11 @@  discard block
 block discarded – undo
4671 4902
  
4672 4903
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4673 4904
 
4674
-	if (isset($columns[$column]))
4675
-		return $columns[$column];
4676
-	else
4677
-		return null;
4678
-}
4905
+	if (isset($columns[$column])) {
4906
+			return $columns[$column];
4907
+	} else {
4908
+			return null;
4909
+	}
4910
+	}
4679 4911
 
4680 4912
 ?>
4681 4913
\ No newline at end of file
Please login to merge, or discard this patch.