Hi, I was trying to upgrade quiz from version 6.x-3.5 to version 6.x-4.0-rc7, I have about 640 multichoice questions, I did the steps as mentioned in the quiz project page (remove quiz folder than upload the quiz 4), I also have the autoload installed and didnt forget to back it up first. But when I tried to update it, it keeps getting error. And below is the error message after it failed updating:

* user warning: Incorrect table definition; there can be only one auto column and it must be defined as a key query: ALTER TABLE quiz_multichoice_user_answers DROP PRIMARY KEY in /home/sloki/user/ariestai/sites/masukui.com/www/includes/database.mysql-common.inc on line 386.
* user warning: Duplicate column name 'id' query: ALTER TABLE quiz_multichoice_user_answers ADD `id` INT auto_increment DEFAULT NULL, ADD PRIMARY KEY (id) in /home/sloki/user/ariestai/sites/masukui.com/www/includes/database.mysql-common.inc on line 298.
* user warning: Duplicate column name 'choice_order' query: ALTER TABLE quiz_multichoice_user_answers ADD `choice_order` TEXT DEFAULT NULL in /home/sloki/user/ariestai/sites/masukui.com/www/includes/database.mysql-common.inc on line 298.
* user warning: Table 'quiz_multichoice_user_answer_multi' already exists query: CREATE TABLE quiz_multichoice_user_answer_multi ( `user_answer_id` INT unsigned NOT NULL, `answer_id` INT unsigned NOT NULL, PRIMARY KEY (user_answer_id, answer_id) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ in /home/sloki/user/ariestai/sites/masukui.com/www/includes/database.inc on line 550.

I hope somebody here could help me to figure it out, or give me another option to get the quiz 4 installed and keep the multichoice questions exist.

Thanks in advance

Comments

Aquade’s picture

Still working on updating multichoice...

I am trying to use another option (node_save), but it still does not work, firstly I back up the old quiz_multichoice_answers table and named it quiz_multichoice_answers_lama, then use node_save to insert all data from quiz_multichoice_answers_lama into new quiz_multichoice_answers, the problem is, it only inserts one answer field, below is the code:

  <?php
 if( ! function_exists("node_object_prepare")) {
      include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
   }

   $query_node = db_query("SELECT * FROM node n INNER JOIN quiz_multichoice_answers_lama q ON n.nid = q.nid WHERE type = 'multichoice' ");
   while($rows=db_fetch_object($query_node)){
	   $node = node_load($rows->nid);
	   $nid = $rows->nid;	   
	   $body = $node->body;
	   $uid = $node->uid;
	   $name = $node->name;
	   $created = $node->created;
	   $promoted = $node->promote;
	   $sticky = $node->sticky;
	   $format = $node->format;
	   $title = $node->title;
	   $body = $node->body;

  $node = new stdClass();

  $node->is_new = $nid; 
  $node->type = $contenttype; 
  node_object_prepare($node);
  $node->status = 1;  
  $node->uid = $uid; 
  $node->type = 'multichoice';
  $node->status = '1';
  $node->name = $name;
  $node->created = $created;
  $node->date = $created;
  $node->timestamp = $created;
  $node->changed = $created;
  $node->promote = $promoted;
  $node->sticky = $sticky;
  $node->language = '';
  $node->format = $format;
  $node->title = $title;  
  $node->teaser = $body;
  $node->body = $body;
  $node->alternatives[0][answer] = $rows->answer;
  $node->alternatives[0][answer_format] = '1' ;
  $node->alternatives[0][feedback_if_chosen] = $rows->feedback;
  $node->alternatives[0][feedback_if_chosen_format] = '1';
  $node->alternatives[0][feedback_if_not_chosen] ='' ;
  $node->alternatives[0][feedback_if_not_chosen_format] = '1';
  $node->alternatives[0][score_if_chosen] = $rows->is_correct;
  $node->alternatives[0][score_if_not_chosen] = '0';


  node_validate($newnode);
  $node = node_submit($node);
  node_save($node);  
  content_insert($node);

}

?>

I look forward for anybody here helping me to figure it out.

Thanks

Aquade’s picture

Never mind I have figured it out myself, Just in case anyone here have the same problem in updating quiz 3 to quiz 4, to get multichoice updated, here is the solution to try:
- Back up old table quiz_multichoice_answers then rename it
- uninstall old quiz (6.x.3.x)
- upload new quiz (6.x.4.x)
- Install new quiz
- create a new content/ node and fill out below snippets

<?php
 if( ! function_exists("node_object_prepare")) {
      include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
   }
   
$query_node = db_query("SELECT nid FROM {node} WHERE type = '%s' ", 'multichoice');
while ($node_rows = db_fetch_object($query_node)){
	$nid = $node_rows->nid;
	$query_choice = db_query("SELECT * FROM {quiz_multichoice_answers_lama} WHERE nid = %d", $nid);
	$i=0;
	
	while($choice = db_fetch_object($query_choice)){
		$alternatives[$i][answer] = $choice->answer;
		$alternatives[$i][answer_format] = '1' ;
		$alternatives[$i][feedback_if_chosen] = $choice->feedback;
		$alternatives[$i][feedback_if_chosen_format] = '1';
		$alternatives[$i][feedback_if_not_chosen] ='' ;
		$alternatives[$i][feedback_if_not_chosen_format] = '1';
		$alternatives[$i][score_if_chosen] = $choice->is_correct;
		$alternatives[$i][score_if_not_chosen] = '0';
		$i++;	
		
	}+
	$node = node_load($nid);	
	$node->alternatives = $alternatives;	
	$node = node_submit($node);
	node_save($node);
	content_insert($node);
}


?>

Note: do not forget to remove the node after it successfully updated multichoice, because if it is viewed it will execute the node_save again.

Aquade’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mazdakaps’s picture

Hello this works partially for me. I do what you suggest but except that not all questions are getting into the table and the question/answer relationship is gone. I believe at first we should focus why this is happening. I am having the late ver of quiz 4.

mazdakaps’s picture

Status: Closed (fixed) » Active
djdevin’s picture

Status: Active » Closed (outdated)

This issue is being closed because it is filed against a version that is no longer supported.