### Eclipse Workspace Patch 1.0 #P moodle20r Index: admin/xmldb/actions/delete_sentence/delete_sentence.class.php =================================================================== RCS file: admin/xmldb/actions/delete_sentence/delete_sentence.class.php diff -N admin/xmldb/actions/delete_sentence/delete_sentence.class.php --- admin/xmldb/actions/delete_sentence/delete_sentence.class.php 20 Nov 2009 19:48:02 -0000 1.8 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,135 +0,0 @@ -. - -/** - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This class will delete completely one sentence - * - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class delete_sentence extends XMLDBAction { - - /** - * Init method, every subclass will have its own - */ - function init() { - parent::init(); - - /// Set own custom attributes - - /// Get needed strings - $this->loadStrings(array( - 'confirmdeletesentence' => 'xmldb', - 'yes' => '', - 'no' => '' - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - - /// Get the dir containing the file - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - $statementparam = required_param('statement', PARAM_CLEAN); - $sentenceparam = required_param('sentence', PARAM_INT); - - $confirmed = optional_param('confirmed', false, PARAM_BOOL); - - /// If not confirmed, show confirmation box - if (!$confirmed) { - $o = ''; - $o.= ' '; - $o.= '
'; - $o.= '

' . $this->str['confirmdeletesentence'] . '

'; - $o.= ' '; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - - $this->output = $o; - } else { - /// Get the edited dir - if (!empty($XMLDB->editeddirs)) { - if (isset($XMLDB->editeddirs[$dirpath])) { - $dbdir =& $XMLDB->dbdirs[$dirpath]; - $editeddir =& $XMLDB->editeddirs[$dirpath]; - if ($editeddir) { - $structure =& $editeddir->xml_file->getStructure(); - $statements =& $structure->getStatements(); - $statement =& $structure->getStatement($statementparam); - $sentences =& $statement->getSentences(); - /// Remove the sentence - unset ($sentences[$sentenceparam]); - - /// The statement has changed - $statement->setChanged(true); - - /// Recalculate the hash - $structure->calculateHash(true); - - /// If the hash has changed from the original one, change the version - /// and mark the structure as changed - $origstructure =& $dbdir->xml_file->getStructure(); - if ($structure->getHash() != $origstructure->getHash()) { - $structure->setVersion(userdate(time(), '%Y%m%d', 99, false)); - $structure->setChanged(true); - } - } - } - } - } - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - - /// Return ok if arrived here - return $result; - } -} - Index: admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php =================================================================== RCS file: /cvsroot/moodle/moodle/admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php,v retrieving revision 1.14 diff -u -r1.14 edit_xml_file.class.php --- admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php 25 Jan 2010 16:11:20 -0000 1.14 +++ admin/xmldb/actions/edit_xml_file/edit_xml_file.class.php 6 Sep 2010 08:15:28 -0000 @@ -25,7 +25,7 @@ * This class will edit one loaded XML file * * Main page to start editing one XML file. From here it's possible to access - * to tables/statements edition plus PHP code generation and other utilities + * to tables edition plus PHP code generation and other utilities * * @package xmldb-editor * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} @@ -52,10 +52,8 @@ 'vieworiginal' => 'xmldb', 'viewedited' => 'xmldb', 'tables' => 'xmldb', - 'statements' => 'xmldb', 'newtable' => 'xmldb', 'newtablefrommysql' => 'xmldb', - 'newstatement' => 'xmldb', 'viewsqlcode' => 'xmldb', 'viewphpcode' => 'xmldb', 'reserved' => 'xmldb', @@ -155,10 +153,6 @@ } else { $b .= ' [' . $this->str['newtablefrommysql'] . ']'; } - /// The new statement button - $b .= ' [' . $this->str['newstatement'] . ']'; - $b .= '

'; - $b .= '

'; /// The view sql code button $b .= '[' .$this->str['viewsqlcode'] . ']'; @@ -229,49 +223,7 @@ } $o .= ''; } - ///Add the statements list - $statements =& $structure->getStatements(); - if ($statements) { - $o .= '

' . $this->str['statements'] . '

'; - $o .= ''; - $row = 0; - foreach ($statements as $statement) { - /// The statement name (link to edit statement) - $s = '' . $statement->getName() . ''; - /// Calculate buttons - $b = ''; - /// Print statement row - $o .= ''; - $row = ($row + 1) % 2; - } - $o .= '
'; - /// The edit button - $b .= '[' . $this->str['edit'] . ']'; - $b .= ''; - /// The up button - if ($statement->getPrevious()) { - $b .= '[' . $this->str['up'] . ']'; - } else { - $b .= '[' . $this->str['up'] . ']'; - } - $b .= ''; - /// The down button - if ($statement->getNext()) { - $b .= '[' . $this->str['down'] . ']'; - } else { - $b .= '[' . $this->str['down'] . ']'; - } - $b .= ''; - /// The delete button - $b .= '[' . $this->str['delete'] . ']'; - $b .= ''; - /// The view xml button - $b .= '[' . $this->str['viewxml'] . ']'; - $b .= '
' . $s . $b . '
'; - } ///Add the back to main - - $this->output = $o; } } Index: lib/xmldb/xmldb_file.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/xmldb/xmldb_file.php,v retrieving revision 1.5 diff -u -r1.5 xmldb_file.php --- lib/xmldb/xmldb_file.php 10 Nov 2009 19:46:28 -0000 1.5 +++ lib/xmldb/xmldb_file.php 6 Sep 2010 08:15:29 -0000 @@ -73,65 +73,42 @@ */ function validateXMLStructure() { - /// Going to perform complete DOM schema validation - if (extension_loaded('dom') && method_exists(new DOMDocument(), 'load')) { - /// Let's capture errors - if (function_exists('libxml_use_internal_errors')) { - libxml_use_internal_errors(true); // This function is PHP5 only (MDL-8730) - } - - /// Create and load XML file - $parser = new DOMDocument(); - $parser->load($this->path); - /// Only validate if we have a schema - if (!empty($this->schema) && file_exists($this->schema)) { - $parser->schemaValidate($this->schema); - } - /// Check for errors - $errors = false; - if (function_exists('libxml_get_errors')) { - $errors = libxml_get_errors(); - } + /// Let's capture errors + libxml_use_internal_errors(true); - /// Prepare errors - if (!empty($errors)) { - /// Create one structure to store errors - $structure = new xmldb_structure($this->path); - /// Add errors to structure - $structure->errormsg = 'XML Error: '; - foreach ($errors as $error) { - $structure->errormsg .= sprintf("%s at line %d. ", - trim($error->message, "\n\r\t ."), - $error->line); - } - /// Add structure to file - $this->xmldb_structure = $structure; - /// Check has failed - return false; - } + /// Create and load XML file + $parser = new DOMDocument(); + $contents = file_get_contents($this->path); + if (strpos($contents, '')) { + //delete the removed STATEMENTS section, it would not validate + $contents = preg_replace('|.*|s', '', $contents); } - /// Going to perform expat simple check (no validation) - else if (function_exists('xml_parser_create')) { - $parser = xml_parser_create(); - if (!xml_parse($parser, file_get_contents($this->path))) { - /// Create one structure to store errors - $structure = new xmldb_structure($this->path); - /// Add error to structure - $structure->errormsg = sprintf("XML Error: %s at line %d", - xml_error_string(xml_get_error_code($parser)), - xml_get_current_line_number($parser)); - /// Add structure to file - $this->xmldb_structure = $structure; - /// Check has failed - return false; - } - /// Free parser resources - xml_parser_free($parser); + + $parser->loadXML($contents); + /// Only validate if we have a schema + if (!empty($this->schema) && file_exists($this->schema)) { + $parser->schemaValidate($this->schema); } - /// Arriving here, something is really wrong because nor dom not expat are present - else { + /// Check for errors + $errors = libxml_get_errors(); + + /// Prepare errors + if (!empty($errors)) { + /// Create one structure to store errors + $structure = new xmldb_structure($this->path); + /// Add errors to structure + $structure->errormsg = 'XML Error: '; + foreach ($errors as $error) { + $structure->errormsg .= sprintf("%s at line %d. ", + trim($error->message, "\n\r\t ."), + $error->line); + } + /// Add structure to file + $this->xmldb_structure = $structure; + /// Check has failed return false; } + return true; } @@ -144,9 +121,15 @@ if (!$this->validateXMLStructure()) { return false; } + $contents = file_get_contents($this->path); + if (strpos($contents, '')) { + //delete the removed STATEMENTS section, it would not validate + $contents = preg_replace('|.*|s', '', $contents); + debugging('STATEMENTS section is not supported any more, please use db/install.php or db/log.php'); + } /// File exists, so let's process it /// Load everything to a big array - $xmlarr = xmlize(file_get_contents($this->path)); + $xmlarr = xmlize($contents); /// Convert array to xmldb structure $this->xmldb_structure = $this->arr2xmldb_structure($xmlarr); /// Analize results Index: lib/xmldb/xmldb.xsd =================================================================== RCS file: /cvsroot/moodle/moodle/lib/xmldb/xmldb.xsd,v retrieving revision 1.4 diff -u -r1.4 xmldb.xsd --- lib/xmldb/xmldb.xsd 1 May 2009 01:19:17 -0000 1.4 +++ lib/xmldb/xmldb.xsd 6 Sep 2010 08:15:29 -0000 @@ -53,15 +53,6 @@ - - - - - - - - - @@ -144,28 +135,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -192,7 +161,6 @@ - Index: lib/xmldb/xmldb_structure.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/xmldb/xmldb_structure.php,v retrieving revision 1.3 diff -u -r1.3 xmldb_structure.php --- lib/xmldb/xmldb_structure.php 1 Nov 2009 11:47:47 -0000 1.3 +++ lib/xmldb/xmldb_structure.php 6 Sep 2010 08:15:29 -0000 @@ -31,7 +31,6 @@ var $path; var $version; var $tables; - var $statements; /** * Creates one new xmldb_structure @@ -41,7 +40,6 @@ $this->path = NULL; $this->version = NULL; $this->tables = array(); - $this->statements = array(); } /** @@ -84,19 +82,6 @@ } /** - * Returns the position of one statement in the array. - */ - function &findStatementInArray($statementname) { - foreach ($this->statements as $i => $statement) { - if ($statementname == $statement->getName()) { - return $i; - } - } - $null = NULL; - return $null; - } - - /** * This function will reorder the array of tables */ function orderTables() { @@ -110,19 +95,6 @@ } /** - * This function will reorder the array of statements - */ - function orderStatements() { - $result = $this->orderElements($this->statements); - if ($result) { - $this->setStatements($result); - return true; - } else { - return false; - } - } - - /** * Returns the tables of the structure */ function &getTables() { @@ -130,25 +102,6 @@ } /** - * Returns one xmldb_statement - */ - function &getStatement($statementname) { - $i = $this->findStatementInArray($statementname); - if ($i !== NULL) { - return $this->statements[$i]; - } - $null = NULL; - return $null; - } - - /** - * Returns the statements of the structure - */ - function &getStatements() { - return $this->statements; - } - - /** * Set the structure version */ function setVersion($version) { @@ -202,52 +155,6 @@ } /** - * Add one statement to the structure, allowing to specify the desired order - * If it's not specified, then the statement is added at the end. - */ - function addStatement(&$statement, $after=NULL) { - - /// Calculate the previous and next tables - $prevstatement = NULL; - $nextstatement = NULL; - - if (!$after) { - $allstatements =& $this->getStatements(); - if ($allstatements) { - end($allstatements); - $prevstatement =& $allstatements[key($allstatements)]; - } - } else { - $prevstatement =& $this->getStatement($after); - } - if ($prevstatement && $prevstatement->getNext()) { - $nextstatement =& $this->getStatement($prevstatement->getNext()); - } - - /// Set current statement previous and next attributes - if ($prevstatement) { - $statement->setPrevious($prevstatement->getName()); - $prevstatement->setNext($statement->getName()); - } - if ($nextstatement) { - $statement->setNext($nextstatement->getName()); - $nextstatement->setPrevious($statement->getName()); - } - /// Some more attributes - $statement->setLoaded(true); - $statement->setChanged(true); - /// Add the new statement - $this->statements[] =& $statement; - /// Reorder the whole structure - $this->orderStatements($this->statements); - /// Recalculate the hash - $this->calculateHash(true); - /// We have one new statement, so the structure has changed - $this->setVersion(userdate(time(), '%Y%m%d', 99, false)); - $this->setChanged(true); - } - - /** * Delete one table from the Structure */ function deleteTable($tablename) { @@ -280,38 +187,6 @@ } /** - * Delete one statement from the Structure - */ - function deleteStatement($statementname) { - - $statement =& $this->getStatement($statementname); - if ($statement) { - $i = $this->findStatementInArray($statementname); - $prevstatement = NULL; - $nextstatement = NULL; - /// Look for prev and next statement - $prevstatement =& $this->getStatement($statement->getPrevious()); - $nextstatement =& $this->getStatement($statement->getNext()); - /// Change their previous and next attributes - if ($prevstatement) { - $prevstatement->setNext($statement->getNext()); - } - if ($nextstatement) { - $nextstatement->setPrevious($statement->getPrevious()); - } - /// Delete the statement - unset($this->statements[$i]); - /// Reorder the statements - $this->orderStatements($this->statements); - /// Recalculate the hash - $this->calculateHash(true); - /// We have one deleted statement, so the structure has changed - $this->setVersion(userdate(time(), '%Y%m%d', 99, false)); - $this->setChanged(true); - } - } - - /** * Set the tables */ function setTables(&$tables) { @@ -319,13 +194,6 @@ } /** - * Set the statements - */ - function setStatements(&$statements) { - $this->statements = $statements; - } - - /** * Load data from XML to the structure */ function arr2xmldb_structure($xmlarr) { @@ -409,47 +277,6 @@ } } - /// Iterate over statements - if (isset($xmlarr['XMLDB']['#']['STATEMENTS']['0']['#']['STATEMENT'])) { - foreach ($xmlarr['XMLDB']['#']['STATEMENTS']['0']['#']['STATEMENT'] as $xmlstatement) { - if (!$result) { //Skip on error - continue; - } - $name = trim($xmlstatement['@']['NAME']); - $statement = new xmldb_statement($name); - $statement->arr2xmldb_statement($xmlstatement); - $this->statements[] = $statement; - if (!$statement->isLoaded()) { - $this->errormsg = 'Problem loading statement ' . $name; - $this->debug($this->errormsg); - $result = false; - } - } - } - - /// Perform some general checks over statements - if ($result && $this->statements) { - /// Check statements names are ok (lowercase, a-z _-) - if (!$this->checkNameValues($this->statements)) { - $this->errormsg = 'Some STATEMENTS name values are incorrect'; - $this->debug($this->errormsg); - $result = false; - } - /// Check previous & next are ok (duplicates and existing statements) - $this->fixPrevNext($this->statements); - if ($result && !$this->checkPreviousNextValues($this->statements)) { - $this->errormsg = 'Some STATEMENTS previous/next values are incorrect'; - $this->debug($this->errormsg); - $result = false; - } - /// Order statements - if ($result && !$this->orderStatements($this->statements)) { - $this->errormsg = 'Error ordering the statements'; - $this->debug($this->errormsg); - $result = false; - } - } - /// Set some attributes if ($result) { $this->loaded = true; @@ -475,15 +302,6 @@ $key .= $table->getHash(); } } - if ($this->statements) { - foreach ($this->statements as $sta) { - $statement =& $this->getStatement($sta->getName()); - if ($recursive) { - $statement->calculateHash($recursive); - } - $key .= $statement->getHash(); - } - } $this->hash = md5($key); } } @@ -511,14 +329,6 @@ } $o.= ' ' . "\n"; } - /// Now the statements - if ($this->statements) { - $o.= ' ' . "\n"; - foreach ($this->statements as $statement) { - $o.= $statement->xmlOutput(); - } - $o.= ' ' . "\n"; - } $o.= ''; return $o; @@ -677,7 +487,7 @@ /** * This function will return all the errors found in one structure - * looking recursively inside each table/statement. Returns + * looking recursively inside each table. Returns * an array of errors or false */ function getAllErrors() { @@ -699,14 +509,6 @@ $errors = array_merge($errors, $tableerrors); } } - /// Delegate to statements - if ($statements = $this->getStatements()) { - foreach ($statements as $statement) { - if ($statement->getError()) { - $errors[] = $statement->getError(); - } - } - } /// Return decision if (count($errors)) { return $errors; Index: lib/xmldb/xmldb.dtd =================================================================== RCS file: /cvsroot/moodle/moodle/lib/xmldb/xmldb.dtd,v retrieving revision 1.2 diff -u -r1.2 xmldb.dtd --- lib/xmldb/xmldb.dtd 1 May 2009 01:19:17 -0000 1.2 +++ lib/xmldb/xmldb.dtd 6 Sep 2010 08:15:29 -0000 @@ -35,19 +35,6 @@ - - - - - - - - - - - - - @@ -56,7 +43,7 @@ - + Index: lib/xmldb/xmldb_statement.php =================================================================== RCS file: lib/xmldb/xmldb_statement.php diff -N lib/xmldb/xmldb_statement.php --- lib/xmldb/xmldb_statement.php 1 Nov 2009 11:47:47 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,383 +0,0 @@ -table = NULL; - $this->type = XMLDB_STATEMENT_INCORRECT; - $this->sentences = array(); - } - - /** - * Get the statement table - */ - function getTable() { - return $this->table; - } - - /** - * Get the statement type - */ - function getType() { - return $this->type; - } - - /** - * Get the statement sentences - */ - function &getSentences() { - return $this->sentences; - } - - /** - * Set the statement table - */ - function setTable($table) { - $this->table = $table; - } - - /** - * Set the statement type - */ - function setType($type) { - $this->type = $type; - } - - /** - * Add one statement sentence - */ - function addSentence($sentence) { - $this->sentences[] = $sentence; - } - - /** - * Load data from XML to the index - */ - function arr2xmldb_statement($xmlarr) { - - $result = true; - - /// Debug the table - /// traverse_xmlize($xmlarr); //Debug - /// print_object ($GLOBALS['traverse_array']); //Debug - /// $GLOBALS['traverse_array']=""; //Debug - - /// Process key attributes (table, type, comment, previous, next) - if (isset($xmlarr['@']['TABLE'])) { - $this->table = strtolower(trim($xmlarr['@']['TABLE'])); - } else { - $this->errormsg = 'Missing TABLE attribute'; - $this->debug($this->errormsg); - $result = false; - } - - if (isset($xmlarr['@']['TYPE'])) { - /// Check for valid type - $type = $this->getXMLDBStatementType(trim($xmlarr['@']['TYPE'])); - if ($type) { - $this->type = $type; - } else { - $this->errormsg = 'Invalid TYPE attribute'; - $this->debug($this->errormsg); - $result = false; - } - } else { - $this->errormsg = 'Missing TYPE attribute'; - $this->debug($this->errormsg); - $result = false; - } - - /// Look for sentences - $sentencesarr = array(); - - if (isset($xmlarr['#']['SENTENCES'])) { - $sentences = $xmlarr['#']['SENTENCES'][0]['#']['SENTENCE']; - if ($sentences) { - foreach ($sentences as $sentence) { - if (isset($sentence['@']['TEXT'])) { - $sentencesarr[] = trim($sentence['@']['TEXT']); - } else { - $this->errormsg = 'Missing TEXT attribute in sentence'; - $this->debug($this->errormsg); - $result = false; - } - } - } - } - - /// Finally, set the array of sentences - $this->sentences = $sentencesarr; - - /// Now, perform some validations over sentences - /// XMLDB_STATEMENT_INSERT checks - if ($this->type == XMLDB_STATEMENT_INSERT) { - /// Separate fields and values into two arrays - if ($this->sentences) { - foreach ($this->sentences as $sentence) { - $fields = $this->getFieldsFromInsertSentence($sentence); - $values = $this->getValuesFromInsertSentence($sentence); - /// Check that we aren't inserting the id field - if (in_array('id', $fields)) { - $this->errormsg = 'Cannot insert the "id" field. It is an autonumeric column'; - $this->debug($this->errormsg); - $result = false; - } - if ($result && count($fields) == 0) { - $this->errormsg = 'Missing fields in sentence "' . $sentence . '"'; - $this->debug($this->errormsg); - $result = false; - } - if ($result && count($values) == 0) { - $this->errormsg = 'Missing values in sentence "' . $sentence . '"'; - $this->debug($this->errormsg); - $result = false; - } - if ($result && count($fields) != count($values)) { - $this->errormsg = 'Incorrect number of fields (' .implode(', ', $fields) . ') or values (' . implode(', ', $values) . ')'; - $this->debug($this->errormsg); - $result = false; - } - } - } - } else { - /// Sentences different from INSERT are not valid for now - $this->errormsg = 'Only INSERT statements are supported'; - $this->debug($this->errormsg); - $result = false; - } - - if (isset($xmlarr['@']['COMMENT'])) { - $this->comment = trim($xmlarr['@']['COMMENT']); - } - - if (isset($xmlarr['@']['PREVIOUS'])) { - $this->previous = trim($xmlarr['@']['PREVIOUS']); - } - - if (isset($xmlarr['@']['NEXT'])) { - $this->next = trim($xmlarr['@']['NEXT']); - } - - /// Set some attributes - if ($result) { - $this->loaded = true; - } - $this->calculateHash(); - return $result; - } - - /** - * This function returns the correct XMLDB_STATEMENT_XXX value for the - * string passed as argument - */ - function getXMLDBStatementType($type) { - - $result = XMLDB_STATEMENT_INCORRECT; - - switch (strtolower($type)) { - case 'insert': - $result = XMLDB_STATEMENT_INSERT; - break; - case 'update': - $result = XMLDB_STATEMENT_UPDATE; - break; - case 'delete': - $result = XMLDB_STATEMENT_DELETE; - break; - case 'custom': - $result = XMLDB_STATEMENT_CUSTOM; - break; - } - /// Return the normalized XMLDB_STATEMENT - return $result; - } - - /** - * This function returns the correct name value for the - * XMLDB_STATEMENT_XXX passed as argument - */ - function getXMLDBStatementName($type) { - - $result = ''; - - switch (strtolower($type)) { - case XMLDB_STATEMENT_INSERT: - $result = 'insert'; - break; - case XMLDB_STATEMENT_UPDATE: - $result = 'update'; - break; - case XMLDB_STATEMENT_DELETE: - $result = 'delete'; - break; - case XMLDB_STATEMENT_CUSTOM: - $result = 'custom'; - break; - } - /// Return the normalized name - return $result; - } - - /** - * This function calculate and set the hash of one xmldb_statement - */ - function calculateHash($recursive = false) { - if (!$this->loaded) { - $this->hash = NULL; - } else { - $key = $this->table . $this->type . implode (', ', $this->sentences); - $this->hash = md5($key); - } - } - - /** - * This function will output the XML text for one statement - */ - function xmlOutput() { - $o = ''; - $o.= ' comment) { - $o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"'; - } - if ($this->previous) { - $o.= ' PREVIOUS="' . $this->previous . '"'; - } - if ($this->next) { - $o.= ' NEXT="' . $this->next . '"'; - } - if ($this->sentences) { - $o.= '>' . "\n"; - $o.= ' ' . "\n"; - foreach ($this->sentences as $sentence) { - $o.= ' ' . "\n"; - } - $o.= ' ' . "\n"; - $o.= ' ' . "\n"; - } else { - $o.= '/>' . "\n"; - } - - return $o; - } - - /** - * This function will set all the attributes of the xmldb_index object - * based on information passed in one ADOindex - */ - function setFromADOIndex($adoindex) { - - /// Set the unique field - $this->unique = false; - /// Set the fields - $this->fields = $adoindex['columns']; - /// Some more fields - $this->loaded = true; - $this->changed = true; - } - - /** - * Shows info in a readable format - */ - function readableInfo() { - $o = ''; - /// unique - if ($this->unique) { - $o .= 'unique'; - } else { - $o .= 'not unique'; - } - /// fields - $o .= ' (' . implode(', ', $this->fields) . ')'; - - return $o; - } - - /** - * This function will return an array of fields from one INSERT sentence - */ - function getFieldsFromInsertSentence($sentence) { - - $fields = array(); - - /// Get first part from the sentence (before VALUES) - preg_match('/^\((.*)\)\s+VALUES/is', $sentence, $matches); - if (isset($matches[1])) { - $part = $matches[1]; - /// Convert the comma separated string to an array - $arr = $this->comma2array($part); - if ($arr) { - $fields = $arr; - } - } - - return $fields; - } - - /** - * This function will return an array of values from one INSERT sentence - */ - function getValuesFromInsertSentence($sentence) { - - $values = array(); - - /// Get second part from the sentence (after VALUES) - preg_match('/VALUES\s*\((.*)\)$/is', $sentence, $matches); - if (isset($matches[1])) { - $part = $matches[1]; - /// Convert the comma separated string to an array - $arr = $this->comma2array($part); - if ($arr) { - $values = $arr; - } - } - - return $values; - } -} - -/// TODO: Delete for 2.1 (deeprecated in 2.0). -/// Deprecated API starts here -class XMLDBStatement extends xmldb_statement { - - function __construct($name) { - parent::__construct($name); - } - -} -/// Deprecated API ends here Index: admin/xmldb/actions/move_updown_statement/move_updown_statement.class.php =================================================================== RCS file: admin/xmldb/actions/move_updown_statement/move_updown_statement.class.php diff -N admin/xmldb/actions/move_updown_statement/move_updown_statement.class.php --- admin/xmldb/actions/move_updown_statement/move_updown_statement.class.php 1 Nov 2009 10:56:00 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,140 +0,0 @@ -loadStrings(array( - /// 'key' => 'module', - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_NONE; - //$this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - /// Get the dir containing the file - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - - /// Get the correct dirs - if (!empty($XMLDB->dbdirs)) { - $dbdir =& $XMLDB->dbdirs[$dirpath]; - } else { - return false; - } - if (!empty($XMLDB->editeddirs)) { - $editeddir =& $XMLDB->editeddirs[$dirpath]; - $structure =& $editeddir->xml_file->getStructure(); - } - /// ADD YOUR CODE HERE - $prev = NULL; - $next = NULL; - $statementparam = required_param('statement', PARAM_CLEAN); - $direction = required_param('direction', PARAM_ALPHA); - $statements =& $structure->getStatements(); - if ($direction == 'down') { - $statement =& $structure->getStatement($statementparam); - $swap =& $structure->getStatement($statement->getNext()); - } else { - $swap =& $structure->getStatement($statementparam); - $statement =& $structure->getStatement($swap->getPrevious()); - } - - /// Change the statement before the pair - if ($statement->getPrevious()) { - $prev =& $structure->getStatement($statement->getPrevious()); - $prev->setNext($swap->getName()); - $swap->setPrevious($prev->getName()); - $prev->setChanged(true); - } else { - $swap->setPrevious(NULL); - } - /// Change the statement after the pair - if ($swap->getNext()) { - $next =& $structure->getStatement($swap->getNext()); - $next->setPrevious($statement->getName()); - $statement->setNext($next->getName()); - $next->setChanged(true); - } else { - $statement->setNext(NULL); - } - /// Swap the statements - $statement->setPrevious($swap->getName()); - $swap->setNext($statement->getName()); - - /// Statement has changed - $statement->setChanged(true); - - /// Reorder the structure - $structure->orderStatements($statements); - /// Send statements back to structure (the order above break refs) - $structure->setStatements($statements); - /// Recalculate the hash - $structure->calculateHash(true); - - /// If the hash has changed from the original one, change the version - /// and mark the structure as changed - $origstructure =& $dbdir->xml_file->getStructure(); - if ($structure->getHash() != $origstructure->getHash()) { - $structure->setVersion(userdate(time(), '%Y%m%d', 99, false)); - $structure->setChanged(true); - } - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - - /// Return ok if arrived here - return $result; - } -} - Index: admin/xmldb/actions/new_statement/new_statement.class.php =================================================================== RCS file: admin/xmldb/actions/new_statement/new_statement.class.php diff -N admin/xmldb/actions/new_statement/new_statement.class.php --- admin/xmldb/actions/new_statement/new_statement.class.php 16 Jan 2010 18:29:55 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,160 +0,0 @@ -. - -/** - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This class will ask for one statement type and table - * to be able to add sentences of that type - * - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class new_statement extends XMLDBAction { - - /** - * Init method, every subclass will have its own - */ - function init() { - parent::init(); - - /// Set own custom attributes - - /// Get needed strings - $this->loadStrings(array( - 'statementtype' => 'xmldb', - 'statementtable' => 'xmldb', - 'create' => 'xmldb', - 'back' => 'xmldb' - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB, $DB, $OUTPUT; - - /// Do the job, setting result as needed - /// Get the dir containing the file - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - - /// Get the correct dirs - if (!empty($XMLDB->dbdirs)) { - $dbdir =& $XMLDB->dbdirs[$dirpath]; - } else { - return false; - } - if (!empty($XMLDB->editeddirs)) { - $editeddir =& $XMLDB->editeddirs[$dirpath]; - $structure =& $editeddir->xml_file->getStructure(); - } - /// ADD YOUR CODE HERE - $tableparam = optional_param('table', NULL, PARAM_CLEAN); - $typeparam = optional_param('type', NULL, PARAM_CLEAN); - - /// If no table or type, show form - if (!$tableparam || !$typeparam) { - /// No postaction here - $this->postaction = NULL; - /// Get list of tables - $selecttables = $DB->get_tables(); - /// Get list of statement types - $typeoptions = array (XMLDB_STATEMENT_INSERT => xmldb_statement::getXMLDBStatementName(XMLDB_STATEMENT_INSERT), - XMLDB_STATEMENT_UPDATE => xmldb_statement::getXMLDBStatementName(XMLDB_STATEMENT_UPDATE), - XMLDB_STATEMENT_DELETE => xmldb_statement::getXMLDBStatementName(XMLDB_STATEMENT_DELETE), - XMLDB_STATEMENT_CUSTOM => xmldb_statement::getXMLDBStatementName(XMLDB_STATEMENT_CUSTOM)); - if (!$selecttables) { - $this->errormsg = 'No tables available to create statements'; - return false; - } - /// Now build the form - $o = '
'; - $o .= '
'; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= '
' . html_writer::select($typeoptions, 'type') . '' .html_writer::select($selecttables, 'table') . '
[' . $this->str['back'] . ']
'; - $o.= '
'; - - $this->output = $o; - - - /// If table, retrofit information and, if everything works, - /// go to the table edit action - } else { - /// Get some params (table is mandatory here) - $tableparam = required_param('table', PARAM_CLEAN); - $typeparam = required_param('type', PARAM_CLEAN); - - /// Only insert is allowed :-/ - if ($typeparam != XMLDB_STATEMENT_INSERT) { - $this->errormsg = 'Only insert of records is supported'; - return false; - } - - /// Calculate the name of the statement - $typename = xmldb_statement::getXMLDBStatementName($typeparam); - $name = trim(strtolower($typename . ' ' . $tableparam)); - - /// Check that this Statement hasn't been created before - if ($structure->getStatement($name)) { - $this->errormsg = 'The statement "' . $name . '" already exists, please use it to add more sentences'; - return false; - } - - /// Create one new xmldb_statement - $statement = new xmldb_statement($name); - $statement->setType($typeparam); - $statement->setTable($tableparam); - $statement->setComment('Initial ' . $typename . ' of records on table ' . $tableparam); - /// Finally, add the whole retroffited table to the structure - /// in the place specified - $structure->addStatement($statement); - } - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - - /// Return ok if arrived here - return $result; - } -} - Index: admin/xmldb/actions/edit_sentence/edit_sentence.class.php =================================================================== RCS file: admin/xmldb/actions/edit_sentence/edit_sentence.class.php diff -N admin/xmldb/actions/edit_sentence/edit_sentence.class.php --- admin/xmldb/actions/edit_sentence/edit_sentence.class.php 20 Nov 2009 19:48:02 -0000 1.10 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,158 +0,0 @@ -. - -/** - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This class will provide the interface for all the edit sentence actions - * - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class edit_sentence extends XMLDBAction { - - /** - * Init method, every subclass will have its own - */ - function init() { - parent::init(); - - /// Set own custom attributes - $this->sesskey_protected = false; // This action doesn't need sesskey protection - - /// Get needed strings - $this->loadStrings(array( - 'change' => 'xmldb', - 'vieworiginal' => 'xmldb', - 'viewedited' => 'xmldb', - 'back' => 'xmldb' - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - /// Get the dir containing the file - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - - /// Get the correct dirs - if (!empty($XMLDB->dbdirs)) { - $dbdir =& $XMLDB->dbdirs[$dirpath]; - } else { - return false; - } - if (!empty($XMLDB->editeddirs)) { - $editeddir =& $XMLDB->editeddirs[$dirpath]; - $structure =& $editeddir->xml_file->getStructure(); - } - - /// ADD YOUR CODE HERE - - /// Fetch request data - $statementparam = required_param('statement', PARAM_CLEAN); - $sentenceparam = optional_param('sentence', NULL, PARAM_CLEAN); - - if (!$statement =& $structure->getStatement($statementparam)) { - $this->errormsg = 'Wrong statement specified: ' . $statementparam; - return false; - } - $sentences =& $statement->getSentences(); - - /// If no sentence has been specified, edit the last one - if ($sentenceparam === NULL) { - end($sentences); - $sentenceparam = key($sentences); - } - - if (!$sentence =& $sentences[$sentenceparam]) { - $this->errormsg = 'Wrong Sentence: ' . $sentenceparam; - return false; - } - - $dbdir =& $XMLDB->dbdirs[$dirpath]; - $origstructure =& $dbdir->xml_file->getStructure(); - - /// Based in the type of statement, print different forms - if ($statement->getType() != XMLDB_STATEMENT_INSERT) { - /// Only INSERT is allowed!! - $this->errormsg = 'Wrong Statement Type. Only INSERT allowed'; - return false; - } else { - /// Prepare INSERT sentence - $fields = $statement->getFieldsFromInsertSentence($sentence); - $values = $statement->getValuesFromInsertSentence($sentence); - - /// Add the main form - $o = '
'; - $o.= '
'; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - /// The fields box - $o.= ' '; - $o.= ' '; - /// The values box - $o.= ' '; - $o.= ' '; - /// The submit button - $o.= ' '; - $o.= '
INSERT INTO ' . s($statement->getTable()) . '
VALUES
'; - $o.= '
'; - /// Calculate the buttons - $b = '

'; - /// The back to edit statement button - $b .= ' [' . $this->str['back'] . ']'; - $b .= '

'; - $o .= $b; - - $this->output = $o; - } - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - - /// Return ok if arrived here - return $result; - } -} - Index: admin/xmldb/actions/edit_sentence_save/edit_sentence_save.class.php =================================================================== RCS file: admin/xmldb/actions/edit_sentence_save/edit_sentence_save.class.php diff -N admin/xmldb/actions/edit_sentence_save/edit_sentence_save.class.php --- admin/xmldb/actions/edit_sentence_save/edit_sentence_save.class.php 5 Nov 2009 15:40:26 -0000 1.11 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,157 +0,0 @@ -. - -/** - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This class verifies all the data introduced when editing a sentence for correctness, - * peforming changes / displaying errors depending of the results. - * - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class edit_sentence_save extends XMLDBAction { - - /** - * Init method, every subclass will have its own - */ - function init() { - parent::init(); - - /// Set own custom attributes - - /// Get needed strings - $this->loadStrings(array( - 'cannotuseidfield' => 'xmldb', - 'missingfieldsinsentence' => 'xmldb', - 'missingvaluesinsentence' => 'xmldb', - 'wrongnumberoffieldsorvalues' => 'xmldb', - 'back' => 'xmldb', - 'administration' => '' - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - //$this->does_generate = ACTION_NONE; - $this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - - /// Get parameters - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - - $statementparam = strtolower(required_param('statement', PARAM_CLEAN)); - $sentenceparam = strtolower(required_param('sentence', PARAM_ALPHANUM)); - - $fields = required_param('fields', PARAM_CLEAN); - $fields = trim($fields); - $values = required_param('values', PARAM_CLEAN); - $values = trim($values); - - $editeddir =& $XMLDB->editeddirs[$dirpath]; - $structure =& $editeddir->xml_file->getStructure(); - $statement =& $structure->getStatement($statementparam); - $sentences =& $statement->getSentences(); - - $oldsentence = $sentences[$sentenceparam]; - - if (!$statement) { - $this->errormsg = 'Wrong statement specified: ' . $statementparam; - return false; - } - - /// For now, only insert sentences are allowed - if ($statement->getType() != XMLDB_STATEMENT_INSERT) { - $this->errormsg = 'Wrong Statement Type. Only INSERT allowed'; - return false; - } - - $errors = array(); /// To store all the errors found - - /// Build the whole sentence - $sentence = '(' . $fields . ') VALUES (' . $values . ')'; - - /// Perform some checks - $fields = $statement->getFieldsFromInsertSentence($sentence); - $values = $statement->getValuesFromInsertSentence($sentence); - - if (in_array('id', $fields)) { - $errors[] = $this->str['cannotuseidfield']; - } - if ($result && count($fields) == 0) { - $errors[] = $this->str['missingfieldsinsentence']; - } - if ($result && count($values) == 0) { - $errors[] = $this->str['missingvaluesinsentence']; - } - if ($result && count($fields) != count($values)) { - $errors[] = $this->str['wrongnumberoffieldsorvalues']; - } - - if (!empty($errors)) { - /// Prepare the output - $o = '

' .implode(', ', $errors) . '

-

' . s($sentence) . '

'; - $o.= '[' . $this->str['back'] . ']'; - $this->output = $o; - } - - /// Continue if we aren't under errors - if (empty($errors)) { - $sentences[$sentenceparam] = $sentence; - - /// If the sentence has changed from the old one, change the version - /// and mark the statement and structure as changed - if ($oldsentence != $sentence) { - $statement->setChanged(true); - $structure->setVersion(userdate(time(), '%Y%m%d', 99, false)); - /// Mark as changed - $structure->setChanged(true); - } - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - } - - /// Return ok if arrived here - return $result; - } -} - Index: admin/xmldb/actions/delete_statement/delete_statement.class.php =================================================================== RCS file: admin/xmldb/actions/delete_statement/delete_statement.class.php diff -N admin/xmldb/actions/delete_statement/delete_statement.class.php --- admin/xmldb/actions/delete_statement/delete_statement.class.php 20 Nov 2009 19:48:02 -0000 1.8 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,117 +0,0 @@ -. - -/** - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This class will delete completely one statement - * - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class delete_statement extends XMLDBAction { - - /** - * Init method, every subclass will have its own - */ - function init() { - parent::init(); - - /// Set own custom attributes - - /// Get needed strings - $this->loadStrings(array( - 'confirmdeletestatement' => 'xmldb', - 'yes' => '', - 'no' => '' - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - - /// Get the dir containing the file - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - $statementparam = required_param('statement', PARAM_CLEAN); - - $confirmed = optional_param('confirmed', false, PARAM_BOOL); - - /// If not confirmed, show confirmation box - if (!$confirmed) { - $o = ''; - $o.= ' '; - $o.= '
'; - $o.= '

' . $this->str['confirmdeletestatement'] . '

' . $statementparam . '

'; - $o.= ' '; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - $o.= '
'; - - $this->output = $o; - } else { - /// Get the edited dir - if (!empty($XMLDB->editeddirs)) { - if (isset($XMLDB->editeddirs[$dirpath])) { - $dbdir =& $XMLDB->dbdirs[$dirpath]; - $editeddir =& $XMLDB->editeddirs[$dirpath]; - if ($editeddir) { - $structure =& $editeddir->xml_file->getStructure(); - /// Remove the table - $structure->deleteStatement($statementparam); - } - } - } - } - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - - /// Return ok if arrived here - return $result; - } -} - Index: admin/xmldb/actions/view_statement_xml/view_statement_xml.class.php =================================================================== RCS file: admin/xmldb/actions/view_statement_xml/view_statement_xml.class.php diff -N admin/xmldb/actions/view_statement_xml/view_statement_xml.class.php --- admin/xmldb/actions/view_statement_xml/view_statement_xml.class.php 20 Nov 2009 19:48:04 -0000 1.7 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,129 +0,0 @@ -. - -/** - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This class will display the XML for one statement being edited - * - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class view_statement_xml extends XMLDBAction { - - /** - * Init method, every subclass will have its own - */ - function init() { - parent::init(); - - /// Set own custom attributes - $this->sesskey_protected = false; // This action doesn't need sesskey protection - - /// Get needed strings - $this->loadStrings(array( - /// 'key' => 'module', - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_GENERATE_XML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - - /// Get the file parameter - $statement = required_param('statement', PARAM_CLEAN); - $select = required_param('select', PARAM_ALPHA); //original/edited - /// Get the dir containing the file - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - - /// Get the correct dir - if ($select == 'original') { - if (!empty($XMLDB->dbdirs)) { - $base =& $XMLDB->dbdirs[$dirpath]; - } - } else if ($select == 'edited') { - if (!empty($XMLDB->editeddirs)) { - $base =& $XMLDB->editeddirs[$dirpath]; - } - } else { - $this->errormsg = 'Cannot access to ' . $select . ' info'; - $result = false; - } - if ($base) { - /// Only if the directory exists and it has been loaded - if (!$base->path_exists || !$base->xml_loaded) { - $this->errormsg = 'Directory ' . $dirpath . ' not loaded'; - return false; - } - } else { - $this->errormsg = 'Problem handling ' . $select . ' files'; - return false; - } - - /// Get the structure - if ($result) { - if (!$structure =& $base->xml_file->getStructure()) { - $this->errormsg = 'Error retrieving ' . $select . ' structure'; - $result = false; - } - } - /// Get the statements - if ($result) { - if (!$statements =& $structure->getStatements()) { - $this->errormsg = 'Error retrieving ' . $select . ' statements'; - $result = false; - } - } - /// Get the statement - if ($result && !$t =& $structure->getStatement($statement)) { - $this->errormsg = 'Error retrieving ' . $statement . ' statement'; - $result = false; - } - - if ($result) { - /// Everything is ok. Generate the XML output - $this->output = $t->xmlOutput(); - } else { - /// Switch to HTML and error - $this->does_generate = ACTION_GENERATE_HTML; - } - - /// Return ok if arrived here - return $result; - } -} - Index: lib/ddl/sql_generator.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/ddl/sql_generator.php,v retrieving revision 1.32 diff -u -r1.32 sql_generator.php --- lib/ddl/sql_generator.php 25 Jul 2010 12:57:03 -0000 1.32 +++ lib/ddl/sql_generator.php 6 Sep 2010 08:15:29 -0000 @@ -196,37 +196,6 @@ } } - if ($statements = $xmldb_structure->getStatements()) { - foreach ($statements as $statement) { - $results = array_merge($results, $this->getExecuteStatementSQL($statement)); - } - } - return $results; - } - - /** - * This function will return the code needed to execute a collection - * of sentences present inside one statement for the specified BD - * and prefix. - * For now it only supports INSERT statements - */ - public function getExecuteStatementSQL($xmldb_statement) { - - $results = array(); - - /// Based on statement type - switch ($xmldb_statement->type) { - case XMLDB_STATEMENT_INSERT: - $results = $this->getExecuteInsertSQL($xmldb_statement); - break; - case XMLDB_STATEMENT_UPDATE: - break; - case XMLDB_STATEMENT_DELETE: - break; - case XMLDB_STATEMENT_CUSTOM: - break; - } - return $results; } Index: lib/ddllib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/ddllib.php,v retrieving revision 1.79 diff -u -r1.79 ddllib.php --- lib/ddllib.php 25 Jul 2010 13:35:07 -0000 1.79 +++ lib/ddllib.php 6 Sep 2010 08:15:29 -0000 @@ -63,8 +63,6 @@ require_once($CFG->libdir.'/xmldb/xmldb_key.php'); // Add required XMLDB DB classes require_once($CFG->libdir.'/xmldb/xmldb_index.php'); -// Add required XMLDB DB classes -require_once($CFG->libdir.'/xmldb/xmldb_statement.php'); require_once($CFG->libdir.'/ddl/sql_generator.php'); require_once($CFG->libdir.'/ddl/database_manager.php'); Index: admin/xmldb/actions/new_sentence/new_sentence.class.php =================================================================== RCS file: admin/xmldb/actions/new_sentence/new_sentence.class.php diff -N admin/xmldb/actions/new_sentence/new_sentence.class.php --- admin/xmldb/actions/new_sentence/new_sentence.class.php 20 Nov 2009 19:48:03 -0000 1.7 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,122 +0,0 @@ -. - -/** - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This class will create a new default sentence to be edited. - * If one previous sentence key is specified, it's used as - * base to build the new setence, else a blank one is used - * - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class new_sentence extends XMLDBAction { - - /** - * Init method, every subclass will have its own - */ - function init() { - parent::init(); - - /// Set own custom attributes - - /// Get needed strings - $this->loadStrings(array( - /// 'key' => 'module', - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_NONE; - //$this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - /// Get the dir containing the file - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - - /// Get the correct dirs - if (!empty($XMLDB->dbdirs)) { - $dbdir =& $XMLDB->dbdirs[$dirpath]; - } else { - return false; - } - if (!empty($XMLDB->editeddirs)) { - $editeddir =& $XMLDB->editeddirs[$dirpath]; - $structure =& $editeddir->xml_file->getStructure(); - } - /// ADD YOUR CODE HERE - - $statementparam = required_param('statement', PARAM_CLEAN); - $basesentenceparam = optional_param('basesentence', NULL, PARAM_CLEAN); - - $statement =& $structure->getStatement($statementparam); - $sentences =& $statement->getSentences(); - - $sentence = NULL; - - /// If some sentence has been specified, create the new one - /// based on it - if (!empty($basesentenceparam)) { - $sentence = $sentences[$basesentenceparam]; - } - /// Else, try to create the new one based in the last - if (empty($sentence) && !empty($sentences)) { - $sentence = end($sentences); - } - /// Else, create one sentence by hand - if (empty($sentence)) { - $sentence = "(list, of, fields) VALUES ('list', 'of', 'values')"; - } - - /// Add the sentence to the statement - $statement->addSentence($sentence); - - /// We have one new sentence, so the statement and the structure has changed - $statement->setChanged(true); - $structure->setVersion(userdate(time(), '%Y%m%d', 99, false)); - $structure->setChanged(true); - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - - /// Return ok if arrived here - return $result; - } -} - Index: lang/en/xmldb.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en/xmldb.php,v retrieving revision 1.3 diff -u -r1.3 xmldb.php --- lang/en/xmldb.php 21 May 2010 17:46:11 -0000 1.3 +++ lang/en/xmldb.php 6 Sep 2010 08:15:28 -0000 @@ -33,8 +33,6 @@ $string['confirmdeletefield'] = 'Are you absolutely sure that you want to delete the field:'; $string['confirmdeleteindex'] = 'Are you absolutely sure that you want to delete the index:'; $string['confirmdeletekey'] = 'Are you absolutely sure that you want to delete the key:'; -$string['confirmdeletesentence'] = 'Are you absolutely sure that you want to delete the sentence'; -$string['confirmdeletestatement'] = 'Are you absolutely sure that you want to delete the statement and all its sentences:'; $string['confirmdeletetable'] = 'Are you absolutely sure that you want to delete the table:'; $string['confirmdeletexmlfile'] = 'Are you absolutely sure that you want to delete the file:'; $string['confirmcheckbigints'] = 'This functionality will search for potential wrong integer fields in your Moodle server, generating (but not executing!) automatically the needed SQL statements to have all the integers in your DB properly defined.

@@ -60,8 +58,6 @@ $string['delete_field'] = 'Delete Field'; $string['delete_index'] = 'Delete Index'; $string['delete_key'] = 'Delete Key'; -$string['delete_sentence'] = 'Delete Sentence'; -$string['delete_statement'] = 'Delete Statement'; $string['delete_table'] = 'Delete Table'; $string['delete_xml_file'] = 'Delete XML File'; $string['doc'] = 'Doc'; @@ -78,9 +74,6 @@ $string['edit_index_save'] = 'Save Index'; $string['edit_key'] = 'Edit Key'; $string['edit_key_save'] = 'Save Key'; -$string['edit_sentence'] = 'Edit Sentence'; -$string['edit_sentence_save'] = 'Save Sentence'; -$string['edit_statement'] = 'Edit Statement'; $string['edit_table'] = 'Edit Table'; $string['edit_table_save'] = 'Save Table'; $string['edit_xml_file'] = 'Edit XML File'; @@ -121,9 +114,7 @@ $string['main_view'] = 'Main View'; $string['masterprimaryuniqueordernomatch'] = 'The fields in your foreign key must be listed in the same order as they are listed in the UNIQUE KEY on the referenced table.'; $string['missing'] = 'Missing'; -$string['missingfieldsinsentence'] = 'Missing fields in sentence'; $string['missingindexes'] = 'Missing Indexes Found'; -$string['missingvaluesinsentence'] = 'Missing values in sentence'; $string['mustselectonefield'] = 'You must select one field to see field related actions!'; $string['mustselectoneindex'] = 'You must select one index to see index related actions!'; $string['mustselectonekey'] = 'You must select one key to see key related actions!'; @@ -131,9 +122,6 @@ $string['newfield'] = 'New Field'; $string['newindex'] = 'New Index'; $string['newkey'] = 'New Key'; -$string['newsentence'] = 'New Sentence'; -$string['newstatement'] = 'New Statement'; -$string['new_statement'] = 'New Statement'; $string['newtable'] = 'New Table'; $string['newtablefrommysql'] = 'New Table From MySQL'; $string['new_table_from_mysql'] = 'New Table From MySQL'; @@ -159,10 +147,6 @@ $string['selectonecommand'] = 'Please, select one Action from the list to view PHP code'; $string['selectonefieldkeyindex'] = 'Please, select one Field/Key/Index from the list to view the PHP code'; $string['selecttable'] = 'Select Table:'; -$string['sentences'] = 'Sentences'; -$string['statements'] = 'Statements'; -$string['statementtable'] = 'Statement Table:'; -$string['statementtype'] = 'Statement Type:'; $string['table'] = 'Table'; $string['tables'] = 'Tables'; $string['test'] = 'Test'; @@ -187,7 +171,6 @@ $string['wrongdefaults'] = 'Wrong Defaults Found'; $string['wrongints'] = 'Wrong Integers Found'; $string['wronglengthforenum'] = 'Incorrect length for enum field'; -$string['wrongnumberoffieldsorvalues'] = 'Incorrect number of fields or values in sentence'; $string['wrongreservedwords'] = 'Currently Used Reserved Words
(note that table names aren\'t important if using $CFG->prefix)'; $string['yesmissingindexesfound'] = 'Some missing indexes have been found in your DB. Here are their details and the needed SQL statements to be executed with your favourite SQL interface to create all them (don\'t forget to backup your data before doing that).

After doing that, it\'s highly recommended to execute this utility again to check that no more missing indexes are found.'; $string['yeswrongdefaultsfound'] = 'Some inconsistent defaults have been found in your DB. Here are their details and the needed SQL statements to be executed with your favourite SQL interface to fix them all (don\'t forget to backup your data before doing that).

After doing that, it\'s highly recommended to execute this utility again to check that no more iconsistent defaults are found.'; Index: admin/xmldb/actions/edit_statement_save/edit_statement_save.class.php =================================================================== RCS file: admin/xmldb/actions/edit_statement_save/edit_statement_save.class.php diff -N admin/xmldb/actions/edit_statement_save/edit_statement_save.class.php --- admin/xmldb/actions/edit_statement_save/edit_statement_save.class.php 1 Nov 2009 10:56:00 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,108 +0,0 @@ -loadStrings(array( - 'administration' => '' - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_NONE; - //$this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - - /// Get parameters - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - - $statementparam = strtolower(required_param('statement', PARAM_CLEAN)); - $name = trim(strtolower(required_param('name', PARAM_CLEAN))); - $comment = required_param('comment', PARAM_CLEAN); - $comment = $comment; - - $editeddir =& $XMLDB->editeddirs[$dirpath]; - $structure =& $editeddir->xml_file->getStructure(); - $statement =& $structure->getStatement($statementparam); - - $errors = array(); /// To store all the errors found - - /// If there is one name change, do it, changing the prev and next - /// atributes of the adjacent tables - if ($statementparam != $name) { - $statement->setName($name); - if ($statement->getPrevious()) { - $prev =& $structure->getStatement($statement->getPrevious()); - $prev->setNext($name); - $prev->setChanged(true); - } - if ($statement->getNext()) { - $next =& $structure->getStatement($statement->getNext()); - $next->setPrevious($name); - $next->setChanged(true); - } - } - - /// Set comment - $statement->setComment($comment); - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - - /// Return ok if arrived here - return $result; - } -} - Index: admin/xmldb/actions/edit_statement/edit_statement.class.php =================================================================== RCS file: admin/xmldb/actions/edit_statement/edit_statement.class.php diff -N admin/xmldb/actions/edit_statement/edit_statement.class.php --- admin/xmldb/actions/edit_statement/edit_statement.class.php 20 Nov 2009 19:48:02 -0000 1.11 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,187 +0,0 @@ -. - -/** - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * This class will provide the interface for all the edit statement actions - * - * @package xmldb-editor - * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class edit_statement extends XMLDBAction { - - /** - * Init method, every subclass will have its own - */ - function init() { - parent::init(); - - /// Set own custom attributes - $this->sesskey_protected = false; // This action doesn't need sesskey protection - - /// Get needed strings - $this->loadStrings(array( - 'change' => 'xmldb', - 'vieworiginal' => 'xmldb', - 'viewedited' => 'xmldb', - 'newsentence' => 'xmldb', - 'sentences' => 'xmldb', - 'edit' => 'xmldb', - 'delete' => 'xmldb', - 'duplicate' => 'xmldb', - 'back' => 'xmldb' - )); - } - - /** - * Invoke method, every class will have its own - * returns true/false on completion, setting both - * errormsg and output as necessary - */ - function invoke() { - parent::invoke(); - - $result = true; - - /// Set own core attributes - $this->does_generate = ACTION_GENERATE_HTML; - - /// These are always here - global $CFG, $XMLDB; - - /// Do the job, setting result as needed - /// Get the dir containing the file - $dirpath = required_param('dir', PARAM_PATH); - $dirpath = $CFG->dirroot . $dirpath; - - /// Get the correct dirs - if (!empty($XMLDB->dbdirs)) { - $dbdir =& $XMLDB->dbdirs[$dirpath]; - } else { - return false; - } - if (!empty($XMLDB->editeddirs)) { - $editeddir =& $XMLDB->editeddirs[$dirpath]; - $structure =& $editeddir->xml_file->getStructure(); - } - - /// ADD YOUR CODE HERE - $statementparam = optional_param('statement', NULL, PARAM_CLEAN); - /// If no statement, then we are coming for a new one. Look for - /// type and table and build the correct statementparam - if (!$statementparam) { - $typeparam = optional_param('type', NULL, PARAM_CLEAN); - $tableparam = optional_param('table', NULL, PARAM_CLEAN); - $typename = xmldb_statement::getXMLDBStatementName($typeparam); - $statementparam = trim(strtolower($typename . ' ' . $tableparam)); - } - if (!$statement =& $structure->getStatement($statementparam)) { - /// Arriving here from a name change, looking for the new statement name - $statementname = required_param('name', PARAM_CLEAN); - $statement =& $structure->getStatement($statementparam); - } - - $dbdir =& $XMLDB->dbdirs[$dirpath]; - $origstructure =& $dbdir->xml_file->getStructure(); - - /// Add the main form - $o = '
'; - $o.= '
'; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= ' '; - $o.= '
Name:' . s($statement->getName()) .'
 
'; - $o.= '
'; - /// Calculate the buttons - $b = '

'; - /// The view original XML button - if ($origstructure->getStatement($statementparam)) { - $b .= ' [' . $this->str['vieworiginal'] . ']'; - } else { - $b .= ' [' . $this->str['vieworiginal'] . ']'; - } - /// The view edited XML button - if ($statement->hasChanged()) { - $b .= ' [' . $this->str['viewedited'] . ']'; - } else { - $b .= ' [' . $this->str['viewedited'] . ']'; - } - /// The new sentence button - $b .= ' [' . $this->str['newsentence'] . ']'; - /// The back to edit xml file button - $b .= ' [' . $this->str['back'] . ']'; - $b .= '

'; - $o .= $b; - - /// Delete any 'changeme' sentence - ///$statement->deleteSentence('changeme'); - - /// Add the fields list - $sentences =& $statement->getSentences(); - if (!empty($sentences)) { - $o .= '

' . $this->str['sentences'] . '

'; - $o .= ''; - $row = 0; - foreach ($sentences as $key => $sentence) { - /// Prepend some SQL - if ($statement->getType() == XMLDB_STATEMENT_INSERT) { - $p = 'INSERT INTO ' . $statement->getTable() . ' '; - } else { - $p = 'UNSUPPORTED SENTENCE TYPE '; - } - /// Calculate buttons - $b = ''; - /// Print table row - $o .= ''; - $row = ($row + 1) % 2; - } - $o .= '
'; - /// The edit button - $b .= '[' . $this->str['edit'] . ']'; - $b .= ''; - /// The duplicate button - $b .= '[' . $this->str['duplicate'] . ']'; - $b .= ''; - /// The delete button - $b .= '[' . $this->str['delete'] . ']'; - $b .= '
' . $p . $sentence . $b . '
'; - } - - $this->output = $o; - - /// Launch postaction if exists (leave this here!) - if ($this->getPostAction() && $result) { - return $this->launch($this->getPostAction()); - } - - /// Return ok if arrived here - return $result; - } -} -