Browse Source

Use the version tag the way it's supposed to be

Signed-off-by: Suki <[email protected]>
Suki 11 years ago
parent
commit
f6d9d60809
2 changed files with 52 additions and 2 deletions
  1. 51 1
      Sources/Themes.php
  2. 1 1
      Themes/default/languages/Errors.english.php

+ 51 - 1
Sources/Themes.php

@@ -1404,7 +1404,8 @@ function ThemeInstall()
 <theme-info xmlns="http://www.simplemachines.org/xml/theme-info" xmlns:smf="http://www.simplemachines.org/">
 	<!-- For the id, always use something unique - put your name, a colon, and then the package name. -->
 	<id>smf:' . $smcFunc['strtolower'](str_replace(array(' '), '_', $_REQUEST['copy'])) . '</id>
-	<version>' . $modSettings['smfVersion'] . '</version>
+	<!-- The theme\'s version, please try to use vemantic versioning. -->
+	<version>1.0</version>
 	<!-- Theme name, used purely for aesthetics. -->
 	<name>' . $_REQUEST['copy'] . '</name>
 	<!-- Author: your email address or contact information. The name attribute is optional. -->
@@ -1517,12 +1518,61 @@ function ThemeInstall()
 				'theme_layers' => 'layers',
 				'theme_templates' => 'templates',
 				'based_on' => 'based-on',
+				'version' => 'version',
 			);
 
 			foreach ($xml_elements as $var => $name)
 				if (!empty($theme_info_xml[$name]))
 					$install_info[$var] = $theme_info_xml[$name];
 
+			// OK, is this a newer version of an already installed theme?
+			if (!empty($install_info['version']))
+			{
+				$to_update = array();
+				$request = $smcFunc['db_query']('', '
+					SELECT th.value AS name, th.id_theme, th2.value AS version
+					FROM {db_prefix}themes AS th
+						INNER JOIN {db_prefix}themes AS th2 ON (th2.id_theme = th.id_theme
+							AND th2.id_member = {int:no_member}
+							AND th2.variable = {string:version})
+					WHERE th.id_member = {int:no_member}
+						AND th.variable = {string:name}
+						AND th.value LIKE {string:name_value}
+					LIMIT 1',
+					array(
+						'no_member' => 0,
+						'name' => 'name',
+						'version' => 'version',
+						'name_value' => '%'. $install_info['name'] .'%',
+					)
+				);
+				$to_update = $smcFunc['db_fetch_assoc']($request);
+				$smcFunc['db_free_result']($request);
+
+				// Got something, lets figure it out what to do next.
+				if (!empty($to_update) && !empty($to_update['version']))
+					switch (compareVersions($install_info['version'], $to_update['version'])) 
+					{
+						case 0: // This is exactly the same theme.
+						case -1: // The one being installed is older than the one already installed.
+							fatal_lang_error('package_get_error_theme_no_new_version', false, array($install_info['version'], $to_update['version']))
+							break;
+						case 1: // Got a newer version, update the old entry.
+							$smcFunc['db_query']('', '
+								UPDATE {db_prefix}themes
+								SET value = {string:new_value}
+								WHERE variable = {string:version}
+									AND id_theme = {int:id_theme}',
+								array(
+									'new_value' => $install_info['version'],
+									'version' => 'version',
+									'id_theme' => $to_update['id_theme'],
+								)
+							);
+							break;
+					}
+			}
+
 			if (!empty($theme_info_xml['images']))
 			{
 				$install_info['images_url'] = $install_info['theme_url'] . '/' . $theme_info_xml['images'];

+ 1 - 1
Themes/default/languages/Errors.english.php

@@ -302,7 +302,7 @@ $txt['package_get_error_is_theme'] = 'You can\'t install a Theme from this secti
 $txt['package_get_error_is_mod'] = 'You can\'t install a mod from this section, please use the <a href="{MANAGEMODURL}">Package manager</a> page to upload it';
 $txt['package_get_error_theme_not_compatible'] = 'Your theme does not show it has compatibility with %1$s. Please contact the theme author.';
 $txt['package_get_error_theme_no_based_on_found'] = 'The theme you\'re trying to install depends on another theme: %1$s, you need to install that theme first.';
-
+$txt['package_get_error_theme_no_new_version'] = 'The theme you\'re trying to install is already installed or is an outdated version of it, the version you\'re trying to install is: %1$s and the version already installed is: %2$s';
 
 $txt['no_membergroup_selected'] = 'No membergroup selected';
 $txt['membergroup_does_not_exist'] = 'The membergroup doesn\'t exist or is invalid.';