From: Simon H. <sim...@us...> - 2010-09-30 16:56:31
|
Update of /cvsroot/stack/stack-dev/install/update/updates In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv28438/install/update/updates Added Files: TwoPointTwo.php Log Message: Merging 2.2 branch (with some additional fixes to ensure seamless updating for version lines) --- NEW FILE: TwoPointTwo.php --- <?php /** * * Welcome to STACK. A system for teaching and assessment using a * computer algebra kernel. * * This file is licensed under the GPL License. * * A copy of the license is in your STACK distribution called * license.txt. If you are missing this file you can obtain * it from: * http://www.stack.bham.ac.uk/license.txt * * @package stackUpdate * @author Simon Hammond * */ /** * Updates stack alpha to 2.2. */ global $config; $root = $config->get('docroot'); require_once($root.'/lib/error.php'); require_once($root.'/lib/items/Item.php'); require_once($root.'/lib/items/QuestionPart.php'); require_once($root.'/lib/database/StackDBItem.php'); require_once($root.'/other/adodb5/adodb.inc.php'); require_once($root.'/lib/database/StackDBADOdb.php'); class TwoPointTwo{ private $errorLog; public function __construct(&$errorLog) { $this->errorLog = $errorLog; } /** * Updates the database */ public function performUpdate() { // Add the new 'question_lines' table global $config; // below from adodbinit.php - expecting to be safer than simple mySQL query: $db = NewADOConnection($config->getDB('dbType')); // Maybe this should be PConnect $db->Connect($config->getDB('host'), $config->getDB('user'), $config->getDB('password'), $config->getDB('database')); $dict = NewDataDictionary($db); // Table structure for table `question_lines` $fields = 'id I(11) UNSIGNED NOTNULL AUTO PRIMARY, latestVersion I(11) UNSIGNED, modified T NOTNULL DEFTIMESTAMP ON UPDATE '.$db->sysTimeStamp; $sqlarray = $dict->CreateTableSQL("question_lines", $fields, ""); if(!$dict->ExecuteSQLArray($sqlarray)) { $toReturn = $dict->ErrorMsg().'<br /><br />'; } // Add 'line' column in stackquestions $conn = new StackDBADOdb(); $conn->connect(); $sqlarray = $dict->AddColumnSQL('stackquestion', 'line I(11) UNSIGNED'); if(!$dict->ExecuteSQLArray($sqlarray)) { $toReturn = $dict->ErrorMsg().'<br /><br />'; } // Create new line for each question, i.e. create row in question_lines and set line with that id. $conn->query('SELECT questionID FROM stackquestion'); // new queries seem to lose prior result so temporarily saving them for($i = 0; $i < $conn->noRows(); $i++) { $qid[] = $conn->result($i, 'questionID'); } for($i = 0; $i < count($qid); $i++) { //insert line for each question $conn->query("INSERT INTO question_lines(latestVersion) VALUES(".$qid[$i].")"); // shortcut: we know sequence of insert ids will be 1,2,3,... i.e. $i // set line id in each question //$conn->query("UPDATE stackquestion SET line=".($i+1)." WHERE questionID=".$qid[$i]); // row indices start at 1 // $item = new Item(NULL, $qid[$i]); // $item->setLine($i+1); // $item->store(); } // update all items for($i = 0; $i < count($qid); $i++) { //$item = new Item(NULL, $qid[$i]); //$item->setLine($i+1); /* echo "<br />post setLine(): "; print_r($item->getLine()); */ // $item->store(); bypassing // we are going to update the questionVariables // get questionVariables field for qID $conn->query("SELECT questionVariables FROM stackquestion where questionID = ".$qid[$i]); $serialisedQV = $conn->result(0, 'questionVariables'); $questionVariables = $conn->base64_unserialize($serialisedQV); $questionVariables['line'] = $i+1; // just changing the relevant field $serialisedQV = $conn->base64_serialize($questionVariables); $sql = "UPDATE stackquestion SET line=".($i+1).", questionVariables=".$conn->dbSafeString($serialisedQV)." WHERE questionID=".$qid[$i]; $conn->query($sql); // row indices start at 1 echo $sql; // go back and check // $item = new Item(NULL, $qid[$i]); // echo "<br />line stored: "; //print_r($item->getLine()); } //load up each question in turn and set it's line (code from earlier update scripts) /* $db = new StackDBItem(); $db->connect(); $questions = $db->getListOfQuestions(); $i = 0; if(!empty($questions)) { foreach($questions as $question) { $qid = $question['id']; //load the question $item = new Item(NULL, $qid); $item->store(); //save item. $i++; } } //*/ $this->errorLog->addUserError('',$i.' question lines created.'); return true; } } |