From: Simon H. <sim...@us...> - 2010-09-30 16:56:59
|
Update of /cvsroot/stack/stack-dev/lib/deployment In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv28438/lib/deployment Modified Files: Deployment.php Log Message: Merging 2.2 branch (with some additional fixes to ensure seamless updating for version lines) Index: Deployment.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/deployment/Deployment.php,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Deployment.php 11 Jan 2010 17:23:37 -0000 1.11 --- Deployment.php 30 Sep 2010 16:56:21 -0000 1.12 *************** *** 22,26 **** /** * This class manages the deployment of question instances. ! * It ensures that singletons are deployed only once. */ --- 22,26 ---- /** * This class manages the deployment of question instances. ! * It ensures that singletons are deployed only once and all instances are of the same version. */ *************** *** 28,38 **** private $cache; ! private $questionID; private $instances; public $autoDeployed; private $logger; ! public function __construct($questionID) { $this->logger = new Logger("Deployment"); --- 28,41 ---- private $cache; ! private $version; ! private $line; // lookup on demand private $instances; public $autoDeployed; + private $engineID; + private $logger; ! public function __construct($version, $engineid = NULL) { $this->logger = new Logger("Deployment"); *************** *** 41,64 **** $this->cache->connect(); ! // assign questionID ! $this->questionID = $questionID; // get deployed instances ! $this->instances = $this->cache->getInstances($this->questionID); // ensure one instance if a singleton $this->ensureSingletonDeployed(); } /* this should probably be elsewhere ~ sph 23/10/09 */ public function formXHTML() { ! //$xhtml = "<form method='POST' action='?id=".$this->questionID."'> $xhtml = "<input type='submit' name='submit' value='add'> <input type='text' name='add' value='1' size='3' maxlength='3'/> " . get_string('FE_deployQuestion_newversions', 'stack'); return $xhtml; } public function processOperations($param) { ! //$this->logger->debug("in processOperations, param = ".print_r($param, 1)); // add requests --- 44,74 ---- $this->cache->connect(); ! // assign version ! $this->version = $version; // get deployed instances ! $this->instances = $this->cache->getInstances($this->version); // ensure one instance if a singleton $this->ensureSingletonDeployed(); + + $this->engineID = $engineid; + $this->logger->debug("minstrels: ".$this->engineID); } /* this should probably be elsewhere ~ sph 23/10/09 */ public function formXHTML() { ! //$xhtml = "<form method='POST' action='?id=".$this->version."'> $xhtml = "<input type='submit' name='submit' value='add'> <input type='text' name='add' value='1' size='3' maxlength='3'/> " . get_string('FE_deployQuestion_newversions', 'stack'); + //" <input type='checkbox' name='autoprime' ".(isset($_POST['autoprime'])?'checked="checked"':"")."> ".get_string('FE_deployQuestion_autoprime', 'stack'); + /*" <input type='submit' onclick='return confirm(\"" . + get_string('FE_deployQuestion_confirmUndeployAll', 'stack')."\")' name='dropall' value='" . + get_string('FE_deployQuestion_undeployAll', 'stack')."'>";*/ return $xhtml; } public function processOperations($param) { ! $this->logger->debug("here in processOperations, param = ".print_r($param, 1)." and engineid = ".$this->engineID); // add requests *************** *** 66,70 **** if (!$this->isSingleton()) { $msg = get_string('FE_deployQuestion_attemptingDeploy', 'stack', $param['add']); ! $initialStates = $this->cache->deployCache($this->questionID, $param['add']); $msg .= ' '.get_string('FE_deployQuestion_deployedInstances', 'stack', sizeof($initialStates)); } --- 76,101 ---- if (!$this->isSingleton()) { $msg = get_string('FE_deployQuestion_attemptingDeploy', 'stack', $param['add']); ! $initialStates = $this->cache->deployCache($this->version, $param['add']); ! ! //if in Moodle, update ! //$engineID = $param['engineid']; ! if(!empty($this->engineID)) ! { ! $this->logger->debug('we is in moodle checking your engine ids'); ! $db = new MoodleDB(); ! $db->connect(); ! $inMoodle = $db->inMoodleQuestionBank($this->version, $this->engineID); ! if($inMoodle == true) ! { ! /*update Moodle's database. ! $result = $db->updateQuestion($this->version, $this->getLine(), $this->authorId, $engineID, $post['category']); ! if($result == false) ! { ! $this->userMessage .= '<h3>'.get_string('stackAuthor_moodleUpdateFail','stack','').'</h3>'.get_string('stackAuthor_moodleQBFail','stack',''); ! } ! //*/ ! } ! } ! $msg .= ' '.get_string('FE_deployQuestion_deployedInstances', 'stack', sizeof($initialStates)); } *************** *** 85,89 **** // drop requests if (isset ($param['drop']) && is_numeric($param['drop'])) { ! $msg = get_string('FE_deployQuestion_dropping', 'stack') . $param['drop'] . '<br />'; $this->cache->deinitialiseState($param['drop']);// students may have attempted $this->refreshInstances(); --- 116,120 ---- // drop requests if (isset ($param['drop']) && is_numeric($param['drop'])) { ! $msg = get_string('FE_deployQuestion_dropInstance', 'stack', $param['drop']) . '<br />'; $this->cache->deinitialiseState($param['drop']);// students may have attempted $this->refreshInstances(); *************** *** 91,94 **** --- 122,133 ---- } + // undeploy request (version) + if (isset($param['operation']) && $param['operation'] === 'undeploy' && is_numeric($param['version'])) { + $toDrop = new Deployment($param['version']); + $this->logger->debug('trying to drop version'.$param['version']); + $toDrop->drop($param['engine']); + } + + // prime requests if (isset ($param['operation']) && $param['operation'] == 'prime' && is_numeric($param['instance'])) { *************** *** 102,107 **** // ensure singletons are always instantiated public function ensureSingletonDeployed() { ! if ($this->size() === 0 && $this->isSingleton()) { ! $this->cache->deployCache($this->questionID, 1); $this->refreshInstances(); $this->autoDeployed = true; --- 141,148 ---- // ensure singletons are always instantiated public function ensureSingletonDeployed() { ! // check no earlier blocking instances ! ! if ($this->size() === 0 && $this->isSingleton() && $this->earliestDeployedVersion() === false) { ! $this->cache->deployCache($this->version, 1); $this->refreshInstances(); $this->autoDeployed = true; *************** *** 112,116 **** private function refreshInstances() { ! $this->instances = $this->cache->getInstances($this->questionID); } --- 153,158 ---- private function refreshInstances() { ! $this->instances = $this->cache->getInstances($this->version); ! } *************** *** 120,124 **** // Are random versions of this item available? $options = NULL; ! $item = new Item($options, $this->questionID); return $item->questionVariables->contains_rand() == false; } --- 162,166 ---- // Are random versions of this item available? $options = NULL; ! $item = new Item($options, $this->version); return $item->questionVariables->contains_rand() == false; } *************** *** 139,143 **** $this->logger->debug('in primeResponses with ids: ' . print_r($instanceIDs, 1)); $options = NULL; ! $item = new Item($options, $this->questionID); if($item->itemTests !== NULL) { // not guaranteed --- 181,185 ---- $this->logger->debug('in primeResponses with ids: ' . print_r($instanceIDs, 1)); $options = NULL; ! $item = new Item($options, $this->version); if($item->itemTests !== NULL) { // not guaranteed *************** *** 211,215 **** $options = NULL; ! $item = new Item($options, $this->questionID); if($item->itemTests !== NULL) { // not guaranteed --- 253,257 ---- $options = NULL; ! $item = new Item($options, $this->version); if($item->itemTests !== NULL) { // not guaranteed *************** *** 244,247 **** --- 286,351 ---- return true; } + + function getVersion() { + return $this->version; + } + + /* + * Removes all instances from this deployment by deinitialising all the states. + */ + function drop($engineID = NULL) { + if(!empty($this->instances)) { + foreach($this->instances as $instance) { + $this->cache->deinitialiseState($instance['id']); + } + $this->refreshInstances(); + } + + //if in Moodle, update + if(!empty($engineID)) + { + $db = new MoodleDB(); + $db->connect(); + $inMoodle = $db->inMoodleQuestionBank($this->version, $engineID); + if($inMoodle == true) + { + //update Moodle's database. + /*$result = $db->REMOVEQuestion($this->version, $this->authorId, $engineID, $post['category']); + if($result == false) + { + $this->userMessage .= '<h3>'.get_string('stackAuthor_moodleUpdateFail','stack','').'</h3>'.get_string('stackAuthor_moodleQBFail','stack',''); + } + */ + } + } + //*/ + } + + function earliestDeployedVersion() { + $itemDB = new StackDBItem(); + $itemDB->connect(); + $versions = $itemDB->getVersions($itemDB->getLine($this->version)); // returned in descending order + $itemDB->disconnect(); + + $earliest = false; + + // requires versions ordered by descending id + foreach($versions as $date => $id) { + if($this->cache->instancesDeployed($id)) { + $earliest = $id; + } + } + return $earliest; + } + + function getLine() { + if(!isset($this->line)) { + $itemDB = new StackDBItem(); + $itemDB->connect(); + $this->line = $itemDB->getLine($this->version); // returned in descending order + $itemDB->disconnect(); + } + return $this->line; + } } ?> \ No newline at end of file |