Browse Source

Upgrade the verification questions to the new system when upgrading (fixes #727)

Signed-off-by: Michael Eshom <[email protected]>
Michael Eshom 11 years ago
parent
commit
37f93157e9
3 changed files with 149 additions and 0 deletions
  1. 47 0
      other/upgrade_2-1_mysql.sql
  2. 51 0
      other/upgrade_2-1_postgresql.sql
  3. 51 0
      other/upgrade_2-1_sqlite.sql

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

@@ -422,4 +422,51 @@ CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
 ---# Deleting integration hooks
 DELETE FROM {$db_prefix}settings
 WHERE variable LIKE 'integrate_%';
+---#
+
+/******************************************************************************/
+--- Upgrading "verification questions" feature
+/******************************************************************************/
+---# Creating qanda table
+CREATE TABLE IF NOT EXISTS {$db_prefix}qanda (
+  id_question smallint(5) unsigned NOT NULL auto_increment,
+  lngfile varchar(255) NOT NULL default '',
+  question varchar(255) NOT NULL default '',
+  answers text NOT NULL,
+  PRIMARY KEY (id_question),
+  KEY lngfile (lngfile)
+) ENGINE=MyISAM;
+---#
+
+---# Moving questions and answers to the new table
+---{
+$questions = array();
+$get_questions = upgrade_query("
+	SELECT body AS question, recipient_name AS answer
+	FROM {$db_prefix}log_comments
+	WHERE comment_type = 'ver_test'");
+
+	while ($row = smf_mysql_fetch_assoc($get_questions))
+	{
+		$questions[] = array($language, $row['question'], serialize(array($row['answer'])));
+	}
+
+	$smcFunc['db_free_result']($get_questions);
+
+	if (!empty($questions))
+	{
+		upgrade_query("
+			INSERT INTO {$db_prefix}qanda
+				(lngfile, question, answers)
+			VALUES
+				" . implode(',', $questions));
+
+		// Delete the questions from log_comments now
+		upgrade_query("
+			DELETE FROM {$db_prefix}log_comments
+			WHERE comment_type = 'ver_test'
+		");
+	}
+}
+---}
 ---#

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

@@ -483,4 +483,55 @@ CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
 ---#
 DELETE FROM {$db_prefix}settings
 WHERE variable LIKE 'integrate_%';
+---#
+
+/******************************************************************************/
+--- Upgrading "verification questions" feature
+/******************************************************************************/
+---# Creating qanda table
+CREATE TABLE {$db_prefix}qanda (
+  id_question smallint(5) unsigned NOT NULL auto_increment,
+  lngfile varchar(255) NOT NULL default '',
+  question varchar(255) NOT NULL default '',
+  answers text NOT NULL,
+  PRIMARY KEY (id_question),
+  KEY lngfile (lngfile)
+);
+---#
+
+---# Moving questions and answers to the new table
+---{
+	$questions = array();
+
+	$get_questions = upgrade_query("
+		SELECT body AS question, recipient_name AS answer
+		FROM {$db_prefix}log_comments
+		WHERE comment_type = 'ver_test'");
+
+	while ($row = $smcFunc['db_fetch_assoc']($get_questions))
+	{
+		$questions[] = array($language, $row['question'], serialize(array($row['answer'])));
+	}
+
+	$smcFunc['db_free_result']($get_questions);
+
+	if (!empty($questions))
+	{
+		foreach ($questions as $question)
+		{
+			upgrade_query("
+				INSERT INTO {$db_prefix}qanda
+					(lngfile, question, answers)
+				VALUES
+					" . $question);
+		}
+
+		// Delete the questions from log_comments now
+		upgrade_query("
+			DELETE FROM {$db_prefix}log_comments
+			WHERE comment_type = 'ver_test'
+		");
+	}
+}
+---}
 ---#

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

@@ -473,4 +473,55 @@ CREATE TABLE IF NOT EXISTS {$db_prefix}moderator_groups (
 ---#
 DELETE FROM {$db_prefix}settings
 WHERE variable LIKE 'integrate_%';
+---#
+
+/******************************************************************************/
+--- Upgrading "verification questions" feature
+/******************************************************************************/
+---# Creating qanda table
+CREATE TABLE IF NOT EXISTS {$db_prefix}qanda (
+  id_question smallint(5) unsigned NOT NULL auto_increment,
+  lngfile varchar(255) NOT NULL default '',
+  question varchar(255) NOT NULL default '',
+  answers text NOT NULL,
+  PRIMARY KEY (id_question),
+  KEY lngfile (lngfile)
+);
+---#
+
+---# Moving questions and answers to the new table
+---{
+	$questions = array();
+
+	$get_questions = upgrade_query("
+		SELECT body AS question, recipient_name AS answer
+		FROM {$db_prefix}log_comments
+		WHERE comment_type = 'ver_test'");
+
+	while ($row = $smcFunc['db_fetch_assoc']($get_questions))
+	{
+		$questions[] = array($language, $row['question'], serialize(array($row['answer'])));
+	}
+
+	$smcFunc['db_free_result']($get_questions);
+
+	if (!empty($questions))
+	{
+		foreach ($questions as $question)
+		{
+			upgrade_query("
+				INSERT INTO {$db_prefix}qanda
+					(lngfile, question, answers)
+				VALUES
+					" . $question);
+		}
+
+		// Delete the questions from log_comments now
+		upgrade_query("
+			DELETE FROM {$db_prefix}log_comments
+			WHERE comment_type = 'ver_test'
+		");
+	}
+}
+---}
 ---#