ソースを参照

Merge pull request #613 from Oldiesmann/release-2.1

Rename default theme and uninstall old ones when upgrading
Fixes #517
Fixes #518
Michael Eshom 11 年 前
コミット
570e43cd52

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

@@ -46,7 +46,7 @@ $txt['default_smileyset_name'] = 'Alienine\'s Set';
 $txt['default_aaron_smileyset_name'] = 'Aaron\'s Set';
 $txt['default_akyhne_smileyset_name'] = 'Akyhne\'s Set';
 $txt['default_fugue_smileyset_name'] = 'Fugue\'s Set';
-$txt['default_theme_name'] = 'SMF Default Theme - Curve II';
+$txt['default_theme_name'] = 'SMF Default Theme - Curve2';
 $txt['default_core_theme_name'] = 'Core Theme';
 $txt['default_classic_theme_name'] = 'Classic YaBB SE Theme';
 $txt['default_babylon_theme_name'] = 'Babylon Theme';

+ 33 - 142
other/upgrade_1-1.sql

@@ -369,174 +369,65 @@ if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC
 ---#
 
 /******************************************************************************/
---- Installing new default theme...
+--- Cleaning up after old themes...
 /******************************************************************************/
 
----# Installing theme settings...
+---# Checking for "classic" and removing it if necessary...
 ---{
-// This is Grudge's secret "I'm not a developer" theme install code - keep this quiet ;)
-
-// Firstly, I'm going out of my way to not do this twice!
-if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && empty($modSettings['dont_repeat_theme']))
+// Do they have "classic" installed?
+if (file_exists($GLOBALS['boarddir'] . '/Themes/classic'))
 {
-	// Check it's not already here, just incase.
+	$classic_dir = $GLOBALS['boarddir'] . '/Themes/classic';
 	$theme_request = upgrade_query("
 		SELECT ID_THEME
 		FROM {$db_prefix}themes
 		WHERE variable = 'theme_dir'
-			AND value LIKE '%babylon'");
-	// Only do the upgrade if it doesn't find the theme already.
-	if (smf_mysql_num_rows($theme_request) == 0)
+			AND value ='$classic_dir'");
+
+	// Don't do anything if this theme is already uninstalled
+	if (smf_mysql_num_rows($theme_request) == 1)
 	{
-		// Try to get some settings from the current default theme.
-		$request = upgrade_query("
-			SELECT t1.value AS theme_dir, t2.value AS theme_url, t3.value AS images_url
-			FROM ({$db_prefix}themes AS t1, {$db_prefix}themes AS t2, {$db_prefix}themes AS t3)
-			WHERE t1.ID_THEME = 1
-				AND t1.ID_MEMBER = 0
-				AND t1.variable = 'theme_dir'
-				AND t2.ID_THEME = 1
-				AND t2.ID_MEMBER = 0
-				AND t2.variable = 'theme_url'
-				AND t3.ID_THEME = 1
-				AND t3.ID_MEMBER = 0
-				AND t3.variable = 'images_url'
-			LIMIT 1");
-		if (smf_mysql_num_rows($request) != 0)
-		{
-			$core = smf_mysql_fetch_assoc($request);
-
-			if (substr_count($core['theme_dir'], 'default') === 1)
-				$babylon['theme_dir'] = strtr($core['theme_dir'], array('default' => 'babylon'));
-			if (substr_count($core['theme_url'], 'default') === 1)
-				$babylon['theme_url'] = strtr($core['theme_url'], array('default' => 'babylon'));
-			if (substr_count($core['images_url'], 'default') === 1)
-				$babylon['images_url'] = strtr($core['images_url'], array('default' => 'babylon'));
-		}
-		smf_mysql_free_result($request);
+		$id_theme = mysql_result($theme_request, 0);
+		mysql_free_result($theme_request);
 
-		if (!isset($babylon['theme_dir']))
-			$babylon['theme_dir'] = addslashes($GLOBALS['boarddir']) . '/Themes/babylon';
-		if (!isset($babylon['theme_url']))
-			$babylon['theme_url'] = $GLOBALS['boardurl'] . '/Themes/babylon';
-		if (!isset($babylon['images_url']))
-			$babylon['images_url'] = $GLOBALS['boardurl'] . '/Themes/babylon/images';
+		$known_themes = explode(', ', $modSettings['knownThemes']);
 
-		// Get an available ID_THEME first...
-		$request = upgrade_query("
-			SELECT MAX(ID_THEME) + 1
-			FROM {$db_prefix}themes");
-		list ($ID_OLD_THEME) = smf_mysql_fetch_row($request);
-		smf_mysql_free_result($request);
+		// Remove this value...
+		$known_themes = array_diff($known_themes, array($id_theme));
 
-		// Insert the babylon theme into the tables.
-		upgrade_query("
-			INSERT INTO {$db_prefix}themes
-				(ID_MEMBER, ID_THEME, variable, value)
-			VALUES
-				(0, $ID_OLD_THEME, 'name', 'Babylon Theme'),
-				(0, $ID_OLD_THEME, 'theme_url', '$babylon[theme_url]'),
-				(0, $ID_OLD_THEME, 'images_url', '$babylon[images_url]'),
-				(0, $ID_OLD_THEME, 'theme_dir', '$babylon[theme_dir]')");
-
-		$newSettings = array();
-		// Now that we have the old theme details - switch anyone who used the default to it (Make sense?!)
-		if (!empty($modSettings['theme_default']) && $modSettings['theme_default'] == 1)
-			$newSettings[] = "('theme_default', $ID_OLD_THEME)";
-		// Did guests use to use the default?
-		if (!empty($modSettings['theme_guests']) && $modSettings['theme_guests'] == 1)
-			$newSettings[] = "('theme_guests', $ID_OLD_THEME)";
-
-		// If known themes aren't set, let's just pick all themes available.
-		if (empty($modSettings['knownThemes']))
-		{
-			$request = upgrade_query("
-				SELECT DISTINCT ID_THEME
-				FROM {$db_prefix}themes");
-			$themes = array();
-			while ($row = smf_mysql_fetch_assoc($request))
-				$themes[] = $row['ID_THEME'];
-			$modSettings['knownThemes'] = implode(',', $themes);
-			upgrade_query("
-				UPDATE {$db_prefix}settings
-				SET value = '$modSettings[knownThemes]'
-				WHERE variable = 'knownThemes'");
-		}
+		// Change back to a string...
+		$known_themes = implode(', ', $known_themes);
 
-		// Known themes.
-		$allThemes = explode(',', $modSettings['knownThemes']);
-		$allThemes[] = $ID_OLD_THEME;
-		$newSettings[] = "('knownThemes', '" . implode(',', $allThemes) . "')";
+		// Update the database
+		upgrade_query("
+			REPLACE INTO {$db_prefix}settings (variable, value)
+			VALUES ('knownThemes', '$known_themes')");
 
+		// Delete any info about this theme
 		upgrade_query("
-			REPLACE INTO {$db_prefix}settings
-				(variable, value)
-			VALUES
-				" . implode(', ', $newSettings));
+			DELETE FROM {$db_prefix}themes
+			WHERE ID_THEME = $id_theme");
 
-		// What about members?
+		// Set any members or boards using this theme to the default
 		upgrade_query("
 			UPDATE {$db_prefix}members
-			SET ID_THEME = $ID_OLD_THEME
-			WHERE ID_THEME = 1");
+			SET ID_THEME = 0
+			WHERE ID_THEME = $id_theme");
 
-		// Boards?
 		upgrade_query("
 			UPDATE {$db_prefix}boards
-			SET ID_THEME = $ID_OLD_THEME
-			WHERE ID_THEME = 1");
+			SET ID_THEME = 0
+			WHERE ID_THEME = $id_theme");
 
-		// The other themes used to use babylon as their base theme.
-		if (isset($babylon['theme_dir']) && isset($babylon['theme_url']))
+		if ($modSettings['theme_guests'] == $id_theme)
 		{
-			$babylonBasedThemes = array_diff($allThemes, array(1));
-
-			// Exclude the themes that already have a base_theme_dir.
-			$request = upgrade_query("
-				SELECT DISTINCT ID_THEME
-				FROM {$db_prefix}themes
-				WHERE variable = 'base_theme_dir'");
-			while ($row = smf_mysql_fetch_assoc($request))
-				$babylonBasedThemes = array_diff($babylonBasedThemes, array($row['ID_THEME']));
-			smf_mysql_free_result($request);
-
-			// Only base themes if there are templates that need a fall-back.
-			$insertRows = array();
-			$request = upgrade_query("
-				SELECT ID_THEME, value AS theme_dir
-				FROM {$db_prefix}themes
-				WHERE ID_THEME IN (" . implode(', ', $babylonBasedThemes) . ")
-					AND ID_MEMBER = 0
-					AND variable = 'theme_dir'");
-			while ($row = smf_mysql_fetch_assoc($request))
-			{
-				if (!file_exists($row['theme_dir'] . '/BoardIndex.template.php') || !file_exists($row['theme_dir'] . '/Display.template.php') || !file_exists($row['theme_dir'] . '/index.template.php') || !file_exists($row['theme_dir'] . '/MessageIndex.template.php') || !file_exists($row['theme_dir'] . '/Settings.template.php'))
-				{
-					$insertRows[] = "(0, $row[ID_THEME], 'base_theme_dir', '" . addslashes($babylon['theme_dir']) . "')";
-					$insertRows[] = "(0, $row[ID_THEME], 'base_theme_url', '" . addslashes($babylon['theme_url']) . "')";
-				}
-			}
-			smf_mysql_free_result($request);
-
-			if (!empty($insertRows))
-				upgrade_query("
-					INSERT IGNORE INTO {$db_prefix}themes
-						(ID_MEMBER, ID_THEME, variable, value)
-					VALUES
-						" . implode(',
-						', $insertRows));
+			upgrade_query("
+				REPLACE INTO {$db_prefix}settings
+				(variable, value)
+				VALUES('theme_guests', 0)");
 		}
 	}
-	smf_mysql_free_result($theme_request);
-
-	// This ain't running twice either - not with the risk of log_tables timing us all out!
-	upgrade_query("
-		REPLACE INTO {$db_prefix}settings
-			(variable, value)
-		VALUES
-			('dont_repeat_theme', '1')");
 }
-
 ---}
 ---#
 

+ 37 - 134
other/upgrade_2-0_mysql.sql

@@ -2757,162 +2757,65 @@ if (!isset($modSettings['attachment_thumb_png']))
 ---#
 
 /******************************************************************************/
---- Installing new default theme...
+--- Cleaning up after old themes...
 /******************************************************************************/
 
----# Installing theme settings...
+---# Checking for "babylon" and removing it if necessary...
 ---{
-// This is Grudge's secret "I'm not a developer" theme install code - keep this quiet ;)
-
-// Firstly, I'm going out of my way to not do this twice!
-if ((!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '2.0 RC5' || $modSettings['smfVersion'] === '2.0 a') && empty($modSettings['dont_repeat_theme_core']))
+// Do they have "babylon" installed?
+if (file_exists($GLOBALS['boarddir'] . '/Themes/babylon'))
 {
-	// Check it's not already here, just in case.
+	$babylon_dir = $GLOBALS['boarddir'] . '/Themes/babylon';
 	$theme_request = upgrade_query("
-		SELECT id_theme
+		SELECT ID_THEME
 		FROM {$db_prefix}themes
 		WHERE variable = 'theme_dir'
-			AND value LIKE '%core'");
-	// Only do the upgrade if it doesn't find the theme already.
-	if (smf_mysql_num_rows($theme_request) == 0)
+			AND value ='$babylon_dir'");
+
+	// Don't do anything if this theme is already uninstalled
+	if (smf_mysql_num_rows($theme_request) == 1)
 	{
-		// Try to get some settings from the current default theme.
-		$request = upgrade_query("
-			SELECT t1.value AS theme_dir, t2.value AS theme_url, t3.value AS images_url
-			FROM ({$db_prefix}themes AS t1, {$db_prefix}themes AS t2, {$db_prefix}themes AS t3)
-			WHERE t1.id_theme = 1
-				AND t1.id_member = 0
-				AND t1.variable = 'theme_dir'
-				AND t2.id_theme = 1
-				AND t2.id_member = 0
-				AND t2.variable = 'theme_url'
-				AND t3.id_theme = 1
-				AND t3.id_member = 0
-				AND t3.variable = 'images_url'
-			LIMIT 1");
-		if (smf_mysql_num_rows($request) != 0)
-		{
-			$curve = smf_mysql_fetch_assoc($request);
-
-			if (substr_count($curve['theme_dir'], 'default') === 1)
-				$core['theme_dir'] = strtr($curve['theme_dir'], array('default' => 'core'));
-			if (substr_count($curve['theme_url'], 'default') === 1)
-				$core['theme_url'] = strtr($curve['theme_url'], array('default' => 'core'));
-			if (substr_count($curve['images_url'], 'default') === 1)
-				$core['images_url'] = strtr($curve['images_url'], array('default' => 'core'));
-		}
-		smf_mysql_free_result($request);
+		$id_theme = mysql_result($theme_request, 0);
+		mysql_free_result($theme_request);
 
-		if (!isset($core['theme_dir']))
-			$core['theme_dir'] = addslashes($GLOBALS['boarddir']) . '/Themes/core';
-		if (!isset($core['theme_url']))
-			$core['theme_url'] = $GLOBALS['boardurl'] . '/Themes/core';
-		if (!isset($core['images_url']))
-			$core['images_url'] = $GLOBALS['boardurl'] . '/Themes/core/images';
+		$known_themes = explode(', ', $modSettings['knownThemes']);
 
-		// Get an available id_theme first...
-		$request = upgrade_query("
-			SELECT MAX(id_theme) + 1
-			FROM {$db_prefix}themes");
-		list ($id_core_theme) = smf_mysql_fetch_row($request);
-		smf_mysql_free_result($request);
+		// Remove this value...
+		$known_themes = array_diff($known_themes, array($id_theme));
 
-		// Insert the core theme into the tables.
-		upgrade_query("
-			INSERT INTO {$db_prefix}themes
-				(id_member, id_theme, variable, value)
-			VALUES
-				(0, $id_core_theme, 'name', 'Core Theme'),
-				(0, $id_core_theme, 'theme_url', '$core[theme_url]'),
-				(0, $id_core_theme, 'images_url', '$core[images_url]'),
-				(0, $id_core_theme, 'theme_dir', '$core[theme_dir]')");
+		// Change back to a string...
+		$known_themes = implode(', ', $known_themes);
 
-		// Update the name of the default theme in the database.
+		// Update the database
 		upgrade_query("
-			UPDATE {$db_prefix}themes
-			SET value = 'SMF Default Theme - Curve'
-			WHERE id_theme = 1
-				AND variable = 'name'");
+			REPLACE INTO {$db_prefix}settings (variable, value)
+			VALUES ('knownThemes', '$known_themes')");
 
-		// If known themes aren't set, let's just pick all themes available.
-		if (empty($modSettings['knownThemes']))
-		{
-			$request = upgrade_query("
-				SELECT DISTINCT id_theme
-				FROM {$db_prefix}themes");
-			$themes = array();
-			while ($row = smf_mysql_fetch_assoc($request))
-				$themes[] = $row['id_theme'];
-			$modSettings['knownThemes'] = implode(',', $themes);
-			upgrade_query("
-				UPDATE {$db_prefix}settings
-				SET value = '$modSettings[knownThemes]'
-				WHERE variable = 'knownThemes'");
-		}
+		// Delete any info about this theme
+		upgrade_query("
+			DELETE FROM {$db_prefix}themes
+			WHERE id_theme = $id_theme");
 
-		// Known themes.
-		$allThemes = explode(',', $modSettings['knownThemes']);
-		$allThemes[] = $id_core_theme;
-		$newSettings = array();
-		$newSettings[] = "('knownThemes', '" . implode(',', $allThemes) . "')";
+		// Set any members or boards using this theme to the default
+		upgrade_query("
+			UPDATE {$db_prefix}members
+			SET id_theme = 0
+			WHERE id_theme = $id_theme");
 
 		upgrade_query("
-			REPLACE INTO {$db_prefix}settings
-				(variable, value)
-			VALUES
-				" . implode(', ', $newSettings));
+			UPDATE {$db_prefix}boards
+			SET id_theme = 0
+			WHERE id_theme = $id_theme");
 
-		// The other themes used to use core as their base theme.
-		if (isset($core['theme_dir']) && isset($core['theme_url']))
+		if ($modSettings['theme_guests'] == $id_theme)
 		{
-			$coreBasedThemes = array_diff($allThemes, array(1));
-
-			// Exclude the themes that already have a base_theme_dir.
-			$request = upgrade_query("
-				SELECT DISTINCT id_theme
-				FROM {$db_prefix}themes
-				WHERE variable = 'base_theme_dir'");
-			while ($row = smf_mysql_fetch_assoc($request))
-				$coreBasedThemes = array_diff($coreBasedThemes, array($row['id_theme']));
-			smf_mysql_free_result($request);
-
-			// Only base themes if there are templates that need a fall-back.
-			$insertRows = array();
-			$request = upgrade_query("
-				SELECT id_theme, value AS theme_dir
-				FROM {$db_prefix}themes
-				WHERE id_theme IN (" . implode(', ', $coreBasedThemes) . ")
-					AND id_member = 0
-					AND variable = 'theme_dir'");
-			while ($row = smf_mysql_fetch_assoc($request))
-			{
-				if (!file_exists($row['theme_dir'] . '/BoardIndex.template.php') || !file_exists($row['theme_dir'] . '/Display.template.php') || !file_exists($row['theme_dir'] . '/index.template.php') || !file_exists($row['theme_dir'] . '/MessageIndex.template.php') || !file_exists($row['theme_dir'] . '/Settings.template.php'))
-				{
-					$insertRows[] = "(0, $row[id_theme], 'base_theme_dir', '" . addslashes($core['theme_dir']) . "')";
-					$insertRows[] = "(0, $row[id_theme], 'base_theme_url', '" . addslashes($core['theme_url']) . "')";
-				}
-			}
-			smf_mysql_free_result($request);
-
-			if (!empty($insertRows))
-				upgrade_query("
-					INSERT IGNORE INTO {$db_prefix}themes
-						(id_member, id_theme, variable, value)
-					VALUES
-						" . implode(',
-						', $insertRows));
+			upgrade_query("
+				REPLACE INTO {$db_prefix}settings
+				(variable, value)
+				VALUES('theme_guests', 0)");
 		}
 	}
-	smf_mysql_free_result($theme_request);
-
-	// This ain't running twice either.
-	upgrade_query("
-		REPLACE INTO {$db_prefix}settings
-			(variable, value)
-		VALUES
-			('dont_repeat_theme_core', '1')");
 }
-
 ---}
 ---#
 

+ 69 - 0
other/upgrade_2-1_mysql.sql

@@ -224,6 +224,75 @@ ALTER TABLE {$db_prefix}membergroups
 CHANGE `stars` `icons` varchar(255) NOT NULL DEFAULT '';
 ---#
 
+---# Renaming default theme...
+upgrade_query("
+	UPDATE {$db_prefix}themes
+	SET value = 'SMF Default Theme - Curve2'
+	WHERE value LIKE 'SMF Default Theme%'");
+---#
+
+/******************************************************************************/
+--- Cleaning up after old themes...
+/******************************************************************************/
+---# Checking for "core" and removing it if necessary...
+---{
+// Do they have "core" installed?
+if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
+{
+	$core_dir = $GLOBALS['boarddir'] . '/Themes/core';
+	$theme_request = upgrade_query("
+		SELECT id_theme
+		FROM {$db_prefix}themes
+		WHERE variable = {str:variable}
+			AND value ='$core_dir'");
+
+	// Don't do anything if this theme is already uninstalled
+	if (smf_mysql_num_rows($theme_request) == 1)
+	{
+		$id_theme = mysql_result($theme_request, 0);
+		mysql_free_result($theme_request);
+
+		$known_themes = explode(', ', $modSettings['knownThemes']);
+
+		// Remove this value...
+		$known_themes = array_diff($known_themes, array($id_theme));
+
+		// Change back to a string...
+		$known_themes = implode(', ', $known_themes);
+
+		// Update the database
+		upgrade_query("
+			REPLACE INTO {$db_prefix}settings (variable, value)
+			VALUES ('knownThemes', '$known_themes')");
+
+		// Delete any info about this theme
+		upgrade_query("
+			DELETE FROM {$db_prefix}themes
+			WHERE id_theme = $id_theme");
+
+		// Set any members or boards using this theme to the default
+		upgrade_query("
+			UPDATE {$db_prefix}members
+			SET id_theme = 0
+			WHERE id_theme = $id_theme");
+
+		upgrade_query("
+			UPDATE {$db_prefix}boards
+			SET id_theme = 0
+			WHERE id_theme = $id_theme");
+
+		if ($modSettings['theme_guests'] == $id_theme)
+		{
+			upgrade_query("
+				REPLACE INTO {$db_prefix}settings
+				(variable, value)
+				VALUES('theme_guests', 0)");
+		}
+	}
+}
+---}
+---#
+
 /******************************************************************************/
 --- Adding support for drafts
 /******************************************************************************/

+ 70 - 0
other/upgrade_2-1_postgresql.sql

@@ -282,6 +282,76 @@ upgrade_query("
 ---}
 ---#
 
+---# Renaming default theme...
+upgrade_query("
+	UPDATE {$db_prefix}themes
+	SET value = 'SMF Default Theme - Curve2'
+	WHERE value LIKE 'SMF Default Theme%'");
+---#
+
+/******************************************************************************/
+--- Cleaning up after old themes...
+/******************************************************************************/
+---# Checking for "core" and removing it if necessary...
+---{
+// Do they have "core" installed?
+if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
+{
+	$core_dir = $GLOBALS['boarddir'] . '/Themes/core';
+	$theme_request = upgrade_query("
+		SELECT id_theme
+		FROM {$db_prefix}themes
+		WHERE variable = 'theme_dir'
+			AND value ='$core_dir'");
+
+	// Don't do anything if this theme is already uninstalled
+	if ($smcFunc['db_num_rows']($theme_request) == 1)
+	{
+		list($id_theme) = $smcFunc['db_fetch_row']($theme_request, 0);
+		$smcFunc['db_free_result']($theme_request);
+
+		$known_themes = explode(', ', $modSettings['knownThemes']);
+
+		// Remove this value...
+		$known_themes = array_diff($known_themes, array($id_theme));
+
+		// Change back to a string...
+		$known_themes = implode(', ', $known_themes);
+
+		// Update the database
+		upgrade_query("
+			UPDATE {$db_prefix}settings
+			SET value = '$known_themes'
+			WHERE variable = 'knownThemes'");
+
+		// Delete any info about this theme
+		upgrade_query("
+			DELETE FROM {$db_prefix}themes
+			WHERE id_theme = $id_theme");
+
+		// Set any members or boards using this theme to the default
+		upgrade_query("
+			UPDATE {$db_prefix}members
+			SET id_theme = 0
+			WHERE id_theme = $id_theme");
+
+		upgrade_query("
+			UPDATE {$db_prefix}boards
+			SET id_theme = 0
+			WHERE id_theme = $id_theme");
+
+		if ($modSettings['theme_guests'] == $id_theme)
+		{
+			upgrade_query("
+				UPDATE {$db_prefix}settings
+				SET value = 0
+				WHERE variable = 'theme_guests'");
+		}
+	}
+}
+---}
+---#
+
 /******************************************************************************/
 --- Adding support for drafts
 /******************************************************************************/

+ 68 - 0
other/upgrade_2-1_sqlite.sql

@@ -274,6 +274,74 @@ upgrade_query("
 ---}
 ---#
 
+---# Renaming default theme...
+upgrade_query("
+	UPDATE {$db_prefix}themes
+	SET value = 'SMF Default Theme - Curve2'
+	WHERE value LIKE 'SMF Default Theme%'");
+---#
+
+/******************************************************************************/
+--- Cleaning up after old themes...
+/******************************************************************************/
+---# Checking for "core" and removing it if necessary...
+---{
+// Do they have "core" installed?
+if (file_exists($GLOBALS['boarddir'] . '/Themes/core'))
+{
+	$core_dir = $GLOBALS['boarddir'] . '/Themes/core';
+	$theme_request = upgrade_query("
+		SELECT id_theme
+		FROM {$db_prefix}themes
+		WHERE variable = 'theme_dir'
+			AND value ='$core_dir'");
+
+	// Don't do anything if this theme is already uninstalled
+	if ($smcFunc['db_num_rows']($theme_request) == 1)
+	{
+		list($id_theme) = $smcFunc['db_fetch_row']($theme_request, 0);
+		$smcFunc['db_free_result']($theme_request);
+
+		$known_themes = explode(', ', $modSettings['knownThemes']);
+
+		// Remove this value...
+		$known_themes = array_diff($known_themes, array($id_theme));
+
+		// Change back to a string...
+		$known_themes = implode(', ', $known_themes);
+
+		// Update the database
+		upgrade_query("
+			UPDATE {$db_prefix}settings
+			SET value = '$known_themes'
+			WHERE variable = 'knownThemes'");
+
+		// Delete any info about this theme
+		upgrade_query("
+			DELETE FROM {$db_prefix}themes
+			WHERE id_theme = $id_theme");
+
+		// Set any members or boards using this theme to the default
+		upgrade_query("
+			UPDATE {$db_prefix}members
+			SET id_theme = 0
+			WHERE id_theme = $id_theme");
+
+		upgrade_query("
+			UPDATE {$db_prefix}boards
+			SET id_theme = 0
+			WHERE id_theme = $id_theme");
+
+		if ($modSettings['theme_guests'] == $id_theme)
+		{
+			upgrade_query("
+				UPDATE {$db_prefix}settings
+				SET value = 0
+				WHERE variable = 'theme_guests'");
+		}
+	}
+}
+
 /******************************************************************************/
 --- Adding support for drafts
 /******************************************************************************/