From: Simon H. <sim...@us...> - 2010-09-29 15:08:42
|
Update of /cvsroot/stack/stack-dev/install/update/updates In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv28759/install/update/updates Added Files: Tag: STACK2_2 TwoPointTwo.php Log Message: Update script extended for STACK 2.2 --- 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 // 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(); // hoping this is a platform-agnostic way to modify tables - more knowlegable opinions welcome! $conn->query('ALTER TABLE stackquestion ADD COLUMN line I(11) UNSIGNED'); // 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'); for($i = 0; $i < $conn->noRows(); $i++) { //insert line for each question $id = $conn->result($i, 'questionID'); $conn->query("INSERT INTO question_lines(latestVersion) VALUES($id)"); // 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 WHERE questionID=$id"); } return true; } } |