Browse Source

Add some code to handle possible errors during install.

Signed-off-by: Suki <suki@missallsunday.com>
Suki 11 years ago
parent
commit
9f9a77ac43
2 changed files with 43 additions and 15 deletions
  1. 26 11
      Sources/Themes.php
  2. 17 4
      Themes/default/Themes.template.php

+ 26 - 11
Sources/Themes.php

@@ -1284,16 +1284,6 @@ function ThemeInstall()
 	loadTemplate('Themes');
 	loadLanguage('Errors');
 
-	// Everything went better than expected!
-	if (isset($_GET['theme_id']) && empty($_GET['theme_id']))
-	{
-		$context['sub_template'] = 'installed';
-		$context['page_title'] = $txt['theme_installed'];
-		$context['installed_theme'] = get_single_theme($_GET['theme_id']);
-
-		return;
-	}
-
 	$subActions = array(
 		'file' => 'InstallFile',
 		'copy' => 'InstallCopy',
@@ -1302,13 +1292,38 @@ function ThemeInstall()
 
 	// Call the right function.
 	if (isset($_GET['do']) && empty($_GET['do']) && isset($subActions[$_GET['do']]))
-		$subActions[$_GET['do']]();
+	{
+		$result = $subActions[$_GET['do']]();
+
+		// Everything went better than expected!
+		if (!empty($result) && !empty($result['id']))
+		{
+			$context['sub_template'] = 'installed';
+			$context['page_title'] = $txt['theme_installed'];
+			$context['installed_theme'] = get_single_theme($_GET['theme_id']);
+
+			// Safety.
+			$context['theme_message'] = false;
+
+			return;
+		}
+
+		// Nope, there was an error, show it along with some info about it.
+		elseif (!empty($result) && !empty($result['message']))
+			$context['theme_message'] = $result['message'];
+	}
 
 	// Nope, show a nice error.
 	else
 		fatal_lang_error('theme_install_no_action', false);
 }
 
+function InstallFile()
+{
+	// Such pessimist, looking for errors first, nah, just cautious :P
+
+}
+
 /**
  * Possibly the simplest and best example of how to use the template system.
  *  - allows the theme to take care of actions.

+ 17 - 4
Themes/default/Themes.template.php

@@ -736,25 +736,38 @@ function template_pick()
 	</div>';
 }
 
-// Okay, that theme was installed successfully!
+// Okay, that theme was installed/updated successfully!
 function template_installed()
 {
 	global $context, $settings, $options, $scripturl, $txt;
 
-	// Not much to show except a link back...
+	// The aftermath.
 	echo '
 	<div id="admincenter">
 		<div class="cat_bar">
 			<h3 class="catbg">', $context['page_title'], '</h3>
 		</div>
 		<div class="windowbg">
-			<div class="content">
+			<div class="content">';
+
+	// Oops! there was an error :(
+	if (!empty($context['theme_message']))
+		echo '
+				<p>
+					', $context['theme_message'] ,'
+				</p>';
+
+	// Not much to show except a link back...
+	else
+		echo '
 				<p>
 					<a href="', $scripturl, '?action=admin;area=theme;sa=list;th=', $context['installed_theme']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $context['installed_theme']['name'], '</a> ', $txt['theme_'. (isset($_GET['updated']) ? 'updated' : 'installed') .'_message'], '
 				</p>
 				<p>
 					<a href="', $scripturl, '?action=admin;area=theme;sa=admin;', $context['session_var'], '=', $context['session_id'], '">', $txt['back'], '</a>
-				</p>
+				</p>';
+
+	echo '
 			</div>
 		</div>
 	</div>';