From: Simon H. <sim...@us...> - 2010-11-01 18:18:38
|
Update of /cvsroot/stack/stack-dev/lib/items In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv12921/lib/items Modified Files: Item.php Log Message: Stable interim commit towards deployment updating. Index: Item.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/items/Item.php,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** Item.php 4 Oct 2010 15:00:28 -0000 1.66 --- Item.php 1 Nov 2010 18:18:30 -0000 1.67 *************** *** 570,580 **** } else $line = $this->line; ! if(!$asNew){ // just saving // check item has been changed $prior = new Item(null, $this->qID); if($this->equals($prior)) { ! $this->logger->debug('Item unchanged. No need to store!'); ! return false; } $this->logger->debug('Saving item '.$this->qID); --- 570,584 ---- } else $line = $this->line; ! $statusChangedOnly = false; if(!$asNew){ // just saving // check item has been changed $prior = new Item(null, $this->qID); if($this->equals($prior)) { ! $this->logger->debug('Item content unchanged.'); ! if($this->equalStatus($prior)) { ! return false; ! } else { ! $statusChangedOnly = true; ! } } $this->logger->debug('Saving item '.$this->qID); *************** *** 670,675 **** $meta['line'] = $this->line; - - //add to database //if (($asNew == true) || (empty($this->qID))) --- 674,677 ---- *************** *** 678,702 **** $status = $this->questionStatus->getSelection(); $published = $this->published->getSelection(); - $result = $db->addNewItem($dbItemOptions, $dbItemTests, $dbQuestionVariables, $meta, $this->valid, $status, $published); - //returned result is either qId or false if failed ! $this->qID = $result; ! $db->setLatestVersion($this->line, $this->qID); ! //add PRTs ! if(!empty($this->PRTrees)) ! { ! foreach($this->PRTrees as $PRT) ! { ! $data = $PRT->toBlob(); ! $name = $PRT->getName(); ! $prtResult = $db->addPRT($this->qID, $name, $data); ! if(!$prtResult) ! { ! $this->errorLog->addError(get_string('stackDatabase_failedAddPRT','stack','')); ! $this->errorLog->addUserError('main', get_string('stackDatabase_failedAddPRT','stack','')); ! } ! } } --- 680,710 ---- $status = $this->questionStatus->getSelection(); $published = $this->published->getSelection(); ! if($statusChangedOnly) { ! $result = $db->updateItem($this->qID, $dbItemOptions, $dbItemTests, $dbQuestionVariables, $meta, $this->valid, $status, $published); ! } ! else { ! $result = $db->addNewItem($dbItemOptions, $dbItemTests, $dbQuestionVariables, $meta, $this->valid, $status, $published); ! //returned result is either qId or false if failed ! $this->qID = $result; ! $db->setLatestVersion($this->line, $this->qID); ! ! //add PRTs ! if(!empty($this->PRTrees)) ! { ! foreach($this->PRTrees as $PRT) ! { ! $data = $PRT->toBlob(); ! $name = $PRT->getName(); ! $prtResult = $db->addPRT($this->qID, $name, $data); ! if(!$prtResult) ! { ! $this->errorLog->addError(get_string('stackDatabase_failedAddPRT','stack','')); ! $this->errorLog->addUserError('main', get_string('stackDatabase_failedAddPRT','stack','')); ! } ! } ! } } *************** *** 1332,1336 **** } */ ! // Compares user-editable attributes // Presumes whitespace has already been trimmed. public function equals($other) { --- 1340,1344 ---- } */ ! // Compares user-editable attributes, i.e. the content of the question rather than it's status (see equalStatus()) // Presumes whitespace has already been trimmed. public function equals($other) { *************** *** 1402,1410 **** // Might be nicer to update rather than create new 'valid' version of exact same question, but meanwhile... ! if($this->valid !== $other->valid) return false; return true; // all tests passed } // Compares user-editable attributes // Presumes whitespace has already been trimmed. --- 1410,1425 ---- // Might be nicer to update rather than create new 'valid' version of exact same question, but meanwhile... ! //if($this->valid !== $other->valid) return false; return true; // all tests passed } + public function equalStatus($other) { + if($this->valid !== $other->valid) return false; + if($this->published !== $other->published) return false; + + return true; + } + // Compares user-editable attributes // Presumes whitespace has already been trimmed. |