Index: quiz.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/quiz/quiz.install,v
retrieving revision 1.13
diff -u -r1.13 quiz.install
--- quiz.install	29 Nov 2007 08:02:49 -0000	1.13
+++ quiz.install	2 Dec 2007 05:22:38 -0000
@@ -137,18 +137,100 @@
   variable_del('quiz_default_pass_rate');
 }
 
+ /*
+  * Implementation of hook_update_N()
+  * 
+  * This update will make schema up-to-date from version 1.1
+  *
+  * The following databases have changed names:
+  *   From              	To
+  *   quiz	 				quiz_node_properties
+  *   quiz_questions 		quiz_node_relationship
+  *	  quiz_question 		quiz_node_question_properties
+  *   quiz_result 			quiz_node_results
+  *   quiz_question_results quiz_node_results_answers
+  *
+  *
+  * TODO: SCORE NEEDS TO BE UPDATED WITH A CALCULATED SCORE
+  * A new function needs to be added to this script which will calculate the
+  * score for each result.
+  *
+  * 'answers' in quiz_node_results_answers need to be checked against the 
+  * answer in the multichoice module. Then this result needs to be added to the 
+  * score column in quiz_node_properties.  
+  */
 function quiz_update_1() {
   $ret = array();
   
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
-      // add a result option to the answer table
-      $ret[] = update_sql("ALTER TABLE {quiz_question_answer} ADD result_option INTEGER UNSIGNED NULL");
+
+       // rename quiz to quiz_node_properties
+       $ret[] = update_sql("ALTER TABLE {quiz} RENAME TO {quiz_node_properties}");
+       // update quiz_node_properties to new schema
+       $ret[] = update_sql("ALTER TABLE {quiz_node_properties} DROP number_of_questions;");
+       $ret[] = update_sql("ALTER TABLE {quiz_node_properties} 
+         ADD property_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
+         ADD vid INTEGER UNSIGNED NOT NULL AFTER property_id,
+         ADD number_of_random_questions TINYINT UNSIGNED DEFAULT 0 NOT NULL AFTER nid,
+         ADD tid INTEGER UNSIGNED NOT NULL DEFAULT 0,
+         DROP PRIMARY KEY,
+         ADD PRIMARY KEY (property_id),
+         ADD KEY vid (nid, vid);
+       ");
+
+       // rename quiz_questions to quiz_node_relationship
+       $ret[] = update_sql("ALTER TABLE {quiz_questions} RENAME TO {quiz_node_relationship}");
+       // update quiz_node_relationship to new schema
+       $ret[] = update_sql("ALTER TABLE {quiz_node_relationship}
+         DROP PRIMARY KEY,
+         CHANGE quiz_nid parent_nid INTEGER UNSIGNED NOT NULL,
+         ADD parent_vid INTEGER UNSIGNED NOT NULL AFTER parent_nid,
+         CHANGE question_nid child_nid INTEGER UNSIGNED NOT NULL,
+         ADD child_vid INTEGER UNSIGNED NOT NULL AFTER child_nid,
+         ADD PRIMARY KEY (parent_nid, parent_vid, child_nid, child_vid);
+       ");
+
+       // rename quiz_question to quiz_node_question_properties
+       $ret[] = update_sql("ALTER TABLE {quiz_question} RENAME TO {quiz_node_question_properties}");
+       // update quiz_node_question_properties to new schema
+       $ret[] = update_sql("ALTER TABLE {quiz_node_question_properties}
+         ADD vid INTEGER UNSIGNED NOT NULL AFTER nid,
+         ADD number_of_answers TINYINT UNSIGNED DEFAULT 1 NOT NULL,
+         DROP PRIMARY KEY;
+       ");
+
+       // rename quiz_result to quiz_node_result
+       $ret[] = update_sql("ALTER TABLE {quiz_result} RENAME TO {quiz_node_results}");
+       // update quiz_node_result to new schema
+       $ret[] = update_sql("ALTER TABLE {quiz_node_results}
+         DROP PRIMARY KEY,
+         DROP score,
+         CHANGE rid result_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
+         CHANGE quiz_nid nid INTEGER UNSIGNED NOT NULL,
+         ADD vid INTEGER UNSIGNED NOT NULL AFTER nid,
+         ADD score TINYINT NOT NULL DEFAULT 0,
+         ADD PRIMARY KEY (result_id);
+       ");
+
+       // rename quiz_question_results to quiz_node_results_answers
+       $ret[] = update_sql("ALTER TABLE {quiz_question_results} RENAME TO {quiz_node_results_answers}");
+       // update quiz_node_results_answers to new schema
+       $ret[] = update_sql("ALTER TABLE {quiz_node_results_answers}
+         DROP PRIMARY KEY,
+         CHANGE result_rid result_id INT UNSIGNED NOT NULL,
+         ADD question_vid INT UNSIGNED NOT NULL AFTER question_nid,
+         ADD is_correct TINYINT UNSIGNED NOT NULL DEFAULT '0',
+         ADD points_awarded TINYINT NOT NULL DEFAULT '0',
+         ADD answer_timestamp INT UNSIGNED NOT NULL,
+         ADD PRIMARY KEY(result_id, question_nid, question_vid);
+       ");
 
       // Create the result options table
-      $ret[] = update_sql("CREATE TABLE {quiz_result_options} (
+      $ret[] = update_sql("CREATE TABLE {quiz_node_result_options} (
         nid INTEGER UNSIGNED NOT NULL,
+        vid INTEGER UNSIGNED NOT NULL,
         option_id INTEGER UNSIGNED NOT NULL,
         option_name VARCHAR(255) character set utf8 NOT NULL,
         option_summary LONGTEXT character set utf8 NOT NULL,
Index: multichoice.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/quiz/multichoice.install,v
retrieving revision 1.3
diff -u -r1.3 multichoice.install
--- multichoice.install	29 Nov 2007 19:14:11 -0000	1.3
+++ multichoice.install	2 Dec 2007 05:22:37 -0000
@@ -70,4 +70,43 @@
   // Inform the user that uninstall was sucessful.
   drupal_set_message(t("The Multichoice module, it's settings, and all saved questions were successfully removed."));
 }
+
+/**
+ * Implementation of hook_update_N()
+ * 
+ * Update from quiz module 1.1
+ */
+function multichoice_update_1() {
+  $ret = array();
+   
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      // Create the quiz node user answers multichoice table
+      $ret[] = update_sql("CREATE TABLE {quiz_multichoice_user_answers} (
+        question_nid INTEGER UNSIGNED NOT NULL,
+        question_vid INTEGER UNSIGNED NOT NULL,
+        result_id INTEGER UNSIGNED NOT NULL,
+        answer_id INTEGER UNSIGNED NOT NULL,
+        PRIMARY KEY(result_id, question_nid, question_vid, answer_id)
+      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+      
+      // add a result option to the answer table
+      $ret[] = update_sql("ALTER TABLE {quiz_question_answer} DROP INDEX question_nid;");
+      $ret[] = update_sql("ALTER TABLE {quiz_question_answer} RENAME TO {quiz_multichoice_answers};");
+      $ret[] = update_sql("ALTER TABLE {quiz_multichoice_answers}
+        DROP PRIMARY KEY,
+        CHANGE aid answer_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
+        CHANGE question_nid nid INTEGER UNSIGNED NOT NULL,
+        ADD vid INTEGER UNSIGNED NOT NULL AFTER nid,
+        CHANGE answer answer varchar(255) NOT NULL,
+        CHANGE feedback feedback LONGTEXT,
+        ADD result_option INTEGER UNSIGNED DEFAULT 0 AFTER feedback,
+        CHANGE score is_correct TINYINT UNSIGNED DEFAULT 0,
+        ADD PRIMARY KEY(answer_id);
+      ");
+      break;
+  }
+  return $ret;
+}
        
\ No newline at end of file
