mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-24092 removing STATEMENTS support from install.xml, use db/install.php or db/log.php instead
This commit is contained in:
parent
12c80f79b4
commit
844239d3ed
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @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 = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p class="centerpara">' . $this->str['confirmdeletesentence'] . '</p>';
|
||||
$o.= ' <table class="boxaligncenter" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_sentence&sesskey=' . sesskey() . '&confirmed=yes&postaction=edit_statement&sentence=' . $sentenceparam . '&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></fieldset></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=edit_statement&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></fieldset></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -1,117 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @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 = '<table width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p class="centerpara">' . $this->str['confirmdeletestatement'] . '<br /><br />' . $statementparam . '</p>';
|
||||
$o.= ' <table class="boxaligncenter" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_statement&sesskey=' . sesskey() . '&confirmed=yes&postaction=edit_xml_file&statement=' . $statementparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></fieldset></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post"><fieldset class="invisiblefieldset">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></fieldset></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -1,158 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @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 = '<form id="form" action="index.php" method="post">';
|
||||
$o.= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
$o.= ' <input type="hidden" name ="statement" value="' . $statementparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="sentence" value="' . $sentenceparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="sesskey" value="' . sesskey() .'" />';
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_sentence_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
|
||||
$o.= ' <table id="formelements" class="boxaligncenter">';
|
||||
/// The fields box
|
||||
$o.= ' <tr><td>INSERT INTO ' . s($statement->getTable()) . '</td></tr>';
|
||||
$o.= ' <tr><td><textarea name="fields" rows="2" cols="70" id="fields">' . s(implode(', ', $fields)) . '</textarea></td></tr>';
|
||||
/// The values box
|
||||
$o.= ' <tr><td>VALUES</td></tr>';
|
||||
$o.= ' <tr><td><textarea name="values" rows="2" cols="70" id="values">' . s(implode(', ', $values)) . '</textarea></td></tr>';
|
||||
/// The submit button
|
||||
$o.= ' <tr valign="top"><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</div></form>';
|
||||
/// Calculate the buttons
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
/// The back to edit statement button
|
||||
$b .= ' <a href="index.php?action=edit_statement&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -1,157 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @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 = '<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . s($sentence) . '</p>';
|
||||
$o.= '<a href="index.php?action=edit_sentence&sentence=' .$sentenceparam . '&statement=' .
|
||||
urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) .
|
||||
'">[' . $this->str['back'] . ']</a>';
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -1,187 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @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 = '<form id="form" action="index.php" method="post">';
|
||||
$o.= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
$o.= ' <input type="hidden" name ="statement" value="' . $statementparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="sesskey" value="' . sesskey() .'" />';
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_statement_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
|
||||
$o.= ' <table id="formelements" class="boxaligncenter">';
|
||||
$o.= ' <tr valign="top"><td>Name:</td><td><input type="hidden" name ="name" value="' . s($statement->getName()) . '" />' . s($statement->getName()) .'</td></tr>';
|
||||
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td><textarea name="comment" rows="3" cols="80" id="comment">' . s($statement->getComment()) . '</textarea></td></tr>';
|
||||
$o.= ' <tr valign="top"><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</div></form>';
|
||||
/// Calculate the buttons
|
||||
$b = ' <p class="centerpara buttons">';
|
||||
/// The view original XML button
|
||||
if ($origstructure->getStatement($statementparam)) {
|
||||
$b .= ' <a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&statement=' . $statementparam . '">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
if ($statement->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&statement=' . $statementparam . '">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The new sentence button
|
||||
$b .= ' <a href="index.php?action=new_sentence&postaction=edit_sentence&sesskey=' . sesskey() . '&statement=' . $statementparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newsentence'] . ']</a>';
|
||||
/// The back to edit xml file button
|
||||
$b .= ' <a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
/// Delete any 'changeme' sentence
|
||||
///$statement->deleteSentence('changeme');
|
||||
|
||||
/// Add the fields list
|
||||
$sentences =& $statement->getSentences();
|
||||
if (!empty($sentences)) {
|
||||
$o .= '<h3 class="main">' . $this->str['sentences'] . '</h3>';
|
||||
$o .= '<table id="listfields" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
|
||||
$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 = '</td><td class="button cell">';
|
||||
/// The edit button
|
||||
$b .= '<a href="index.php?action=edit_sentence&sentence=' .$key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The duplicate button
|
||||
$b .= '<a href="index.php?action=new_sentence&postaction=edit_sentence&sesskey=' . sesskey() . '&basesentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['duplicate'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The delete button
|
||||
$b .= '<a href="index.php?action=delete_sentence&sesskey=' . sesskey() . '&sentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
|
||||
$b .= '</td>';
|
||||
/// Print table row
|
||||
$o .= '<tr class="r' . $row . '"><td class="table cell">' . $p . $sentence . $b . '</tr>';
|
||||
$row = ($row + 1) % 2;
|
||||
}
|
||||
$o .= '</table>';
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -1,108 +0,0 @@
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will save the changes performed to the name and comment of
|
||||
/// one statement
|
||||
|
||||
class edit_statement_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(
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ class edit_xml_file extends XMLDBAction {
|
||||
'vieworiginal' => 'xmldb',
|
||||
'viewedited' => 'xmldb',
|
||||
'tables' => 'xmldb',
|
||||
'statements' => 'xmldb',
|
||||
'newtable' => 'xmldb',
|
||||
'newtablefrommysql' => 'xmldb',
|
||||
'newstatement' => 'xmldb',
|
||||
'viewsqlcode' => 'xmldb',
|
||||
'viewphpcode' => 'xmldb',
|
||||
'reserved' => 'xmldb',
|
||||
@ -155,10 +153,6 @@ class edit_xml_file extends XMLDBAction {
|
||||
} else {
|
||||
$b .= ' [' . $this->str['newtablefrommysql'] . ']';
|
||||
}
|
||||
/// The new statement button
|
||||
$b .= ' <a href="index.php?action=new_statement&sesskey=' . sesskey() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newstatement'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$b .= ' <p class="centerpara buttons">';
|
||||
|
||||
/// The view sql code button
|
||||
$b .= '<a href="index.php?action=view_structure_sql&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' .$this->str['viewsqlcode'] . ']</a>';
|
||||
@ -229,49 +223,7 @@ class edit_xml_file extends XMLDBAction {
|
||||
}
|
||||
$o .= '</table>';
|
||||
}
|
||||
///Add the statements list
|
||||
$statements =& $structure->getStatements();
|
||||
if ($statements) {
|
||||
$o .= '<h3 class="main">' . $this->str['statements'] . '</h3>';
|
||||
$o .= '<table id="liststatements" border="0" cellpadding="5" cellspacing="1" class="boxaligncenter flexible">';
|
||||
$row = 0;
|
||||
foreach ($statements as $statement) {
|
||||
/// The statement name (link to edit statement)
|
||||
$s = '<a href="index.php?action=edit_statement&statement=' . $statement->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">' . $statement->getName() . '</a>';
|
||||
/// Calculate buttons
|
||||
$b = '</td><td class="button cell">';
|
||||
/// The edit button
|
||||
$b .= '<a href="index.php?action=edit_statement&statement=' . $statement->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The up button
|
||||
if ($statement->getPrevious()) {
|
||||
$b .= '<a href="index.php?action=move_updown_statement&direction=up&sesskey=' . sesskey() . '&statement=' . $statement->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['up'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['up'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The down button
|
||||
if ($statement->getNext()) {
|
||||
$b .= '<a href="index.php?action=move_updown_statement&direction=down&sesskey=' . sesskey() . '&statement=' . $statement->getName() . '&postaction=edit_xml_file' . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['down'] . ']</a>';
|
||||
} else {
|
||||
$b .= '[' . $this->str['down'] . ']';
|
||||
}
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The delete button
|
||||
$b .= '<a href="index.php?action=delete_statement&sesskey=' . sesskey() . '&statement=' . $statement->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The view xml button
|
||||
$b .= '<a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&statement=' . $statement->getName() . '&select=edited">[' . $this->str['viewxml'] . ']</a>';
|
||||
$b .= '</td>';
|
||||
/// Print statement row
|
||||
$o .= '<tr class="r' . $row . '"><td class="statement cell">' . $s . $b . '</tr>';
|
||||
$row = ($row + 1) % 2;
|
||||
}
|
||||
$o .= '</table>';
|
||||
}
|
||||
///Add the back to main
|
||||
|
||||
|
||||
$this->output = $o;
|
||||
}
|
||||
}
|
||||
|
@ -1,140 +0,0 @@
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will will move one statement down
|
||||
|
||||
class move_updown_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(
|
||||
/// '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;
|
||||
}
|
||||
}
|
||||
|
@ -1,122 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
@ -1,160 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @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 = '<form id="form" action="index.php" method="post">';
|
||||
$o .= '<div>';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
$o.= ' <input type="hidden" name ="action" value="new_statement" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
|
||||
$o.= ' <input type="hidden" name ="sesskey" value="' . sesskey() . '" />';
|
||||
$o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">';
|
||||
$o.= ' <tr><td><label for="type" accesskey="t">' . $this->str['statementtype'] .' </label>' . html_writer::select($typeoptions, 'type') . '<label for="table" accesskey="a">' . $this->str['statementtable'] . ' </label>' .html_writer::select($selecttables, 'table') . '</td></tr>';
|
||||
$o.= ' <tr><td colspan="2" align="center"><input type="submit" value="' .$this->str['create'] . '" /></td></tr>';
|
||||
$o.= ' <tr><td colspan="2" align="center"><a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</div></form>';
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -1,129 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,6 @@ $string['completelogbelow'] = '(see the complete log of the search below)';
|
||||
$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 <a href="http://tracker.moodle.org/browse/MDL-11038">potential wrong integer fields</a> in your Moodle server, generating (but not executing!) automatically the needed SQL statements to have all the integers in your DB properly defined.<br /><br />
|
||||
@ -60,8 +58,6 @@ $string['delete'] = 'Delete';
|
||||
$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'] = 'Edit Index';
|
||||
$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['load'] = 'Load';
|
||||
$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['mysqlextracheckbigints'] = 'Under MySQL it also looks for incorrectly s
|
||||
$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['selectfieldkeyindex'] = 'Select Field/Key/Index:';
|
||||
$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['wrong'] = 'Wrong';
|
||||
$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<br />(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).<br /><br />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).<br /><br />After doing that, it\'s highly recommended to execute this utility again to check that no more iconsistent defaults are found.';
|
||||
|
@ -196,37 +196,6 @@ abstract class sql_generator {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -63,8 +63,6 @@ require_once($CFG->libdir.'/xmldb/xmldb_field.php');
|
||||
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');
|
||||
|
@ -35,19 +35,6 @@
|
||||
|
||||
<!ELEMENT KEYS ( KEY+ ) >
|
||||
|
||||
<!ELEMENT SENTENCE EMPTY >
|
||||
<!ATTLIST SENTENCE TEXT CDATA #REQUIRED >
|
||||
|
||||
<!ELEMENT SENTENCES ( SENTENCE+ ) >
|
||||
|
||||
<!ELEMENT STATEMENT ( SENTENCES ) >
|
||||
<!ATTLIST STATEMENT COMMENT CDATA #REQUIRED >
|
||||
<!ATTLIST STATEMENT NAME CDATA #REQUIRED >
|
||||
<!ATTLIST STATEMENT TABLE NMTOKEN #REQUIRED >
|
||||
<!ATTLIST STATEMENT TYPE NMTOKEN #REQUIRED >
|
||||
|
||||
<!ELEMENT STATEMENTS ( STATEMENT ) >
|
||||
|
||||
<!ELEMENT TABLE ( FIELDS, KEYS, INDEXES? ) >
|
||||
<!ATTLIST TABLE COMMENT CDATA #REQUIRED >
|
||||
<!ATTLIST TABLE NAME ID #REQUIRED >
|
||||
@ -56,7 +43,7 @@
|
||||
|
||||
<!ELEMENT TABLES ( TABLE+ ) >
|
||||
|
||||
<!ELEMENT XMLDB ( TABLES, STATEMENTS ) >
|
||||
<!ELEMENT XMLDB ( TABLES ) >
|
||||
<!ATTLIST XMLDB COMMENT CDATA #REQUIRED >
|
||||
<!ATTLIST XMLDB PATH CDATA #REQUIRED >
|
||||
<!ATTLIST XMLDB VERSION NMTOKEN #REQUIRED >
|
||||
|
@ -53,15 +53,6 @@
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="statementType">
|
||||
<xs:restriction base="xs:NMTOKEN">
|
||||
<xs:enumeration value="insert" />
|
||||
<xs:enumeration value="update" />
|
||||
<xs:enumeration value="delete" />
|
||||
<xs:enumeration value="custom" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
|
||||
<xs:element name="FIELD">
|
||||
<xs:complexType>
|
||||
@ -144,28 +135,6 @@
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="STATEMENT">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref="SENTENCES" />
|
||||
</xs:sequence>
|
||||
<xs:attribute name="NAME" type="xs:string" use="required" />
|
||||
<xs:attribute name="TABLE" type="tableName" use="required" />
|
||||
<xs:attribute name="TYPE" type="statementType" use="required" />
|
||||
<xs:attribute name="COMMENT" type="xs:string" use="optional" />
|
||||
<xs:attribute name="PREVIOUS" type="xs:string" use="optional" />
|
||||
<xs:attribute name="NEXT" type="xs:string" use="optional" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="STATEMENTS">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref="STATEMENT" maxOccurs="unbounded" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="TABLE">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
@ -192,7 +161,6 @@
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref="TABLES" minOccurs="0" />
|
||||
<xs:element ref="STATEMENTS" minOccurs="0" />
|
||||
</xs:sequence>
|
||||
<xs:attribute name="PATH" type="xs:string" use="required" />
|
||||
<xs:attribute name="VERSION" type="xs:string" use="required" />
|
||||
|
@ -73,65 +73,42 @@ class xmldb_file extends xmldb_object {
|
||||
*/
|
||||
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)
|
||||
}
|
||||
/// Let's capture errors
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
/// 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();
|
||||
}
|
||||
/// Create and load XML file
|
||||
$parser = new DOMDocument();
|
||||
$contents = file_get_contents($this->path);
|
||||
if (strpos($contents, '<STATEMENTS>')) {
|
||||
//delete the removed STATEMENTS section, it would not validate
|
||||
$contents = preg_replace('|<STATEMENTS>.*</STATEMENTS>|s', '', $contents);
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
$parser->loadXML($contents);
|
||||
/// Only validate if we have a schema
|
||||
if (!empty($this->schema) && file_exists($this->schema)) {
|
||||
$parser->schemaValidate($this->schema);
|
||||
}
|
||||
/// 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;
|
||||
/// 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);
|
||||
}
|
||||
/// Free parser resources
|
||||
xml_parser_free($parser);
|
||||
}
|
||||
/// Arriving here, something is really wrong because nor dom not expat are present
|
||||
else {
|
||||
/// Add structure to file
|
||||
$this->xmldb_structure = $structure;
|
||||
/// Check has failed
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -144,9 +121,15 @@ class xmldb_file extends xmldb_object {
|
||||
if (!$this->validateXMLStructure()) {
|
||||
return false;
|
||||
}
|
||||
$contents = file_get_contents($this->path);
|
||||
if (strpos($contents, '<STATEMENTS>')) {
|
||||
//delete the removed STATEMENTS section, it would not validate
|
||||
$contents = preg_replace('|<STATEMENTS>.*</STATEMENTS>|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
|
||||
|
@ -1,383 +0,0 @@
|
||||
<?php
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class represent one XMLDB Statement
|
||||
/// (a group of SQL arbitrary sentences)
|
||||
/// (only INSERT is allowed for now)
|
||||
|
||||
class xmldb_statement extends xmldb_object {
|
||||
|
||||
var $table; // Table we are handling
|
||||
var $type; // XMLDB_STATEMENT_TYPE
|
||||
var $sentences; // Collection of sentences in the statement
|
||||
|
||||
/**
|
||||
* Creates one new xmldb_statement
|
||||
*/
|
||||
function __construct($name) {
|
||||
parent::__construct($name);
|
||||
$this->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.= ' <STATEMENT NAME="' . $this->name . '" TYPE="' . xmldb_statement::getXMLDBStatementName($this->type) . '" TABLE="' . $this->table . '"';
|
||||
if ($this->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.= ' <SENTENCES>' . "\n";
|
||||
foreach ($this->sentences as $sentence) {
|
||||
$o.= ' <SENTENCE TEXT="' . htmlspecialchars($sentence) . '" />' . "\n";
|
||||
}
|
||||
$o.= ' </SENTENCES>' . "\n";
|
||||
$o.= ' </STATEMENT>' . "\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
|
@ -31,7 +31,6 @@ class xmldb_structure extends xmldb_object {
|
||||
var $path;
|
||||
var $version;
|
||||
var $tables;
|
||||
var $statements;
|
||||
|
||||
/**
|
||||
* Creates one new xmldb_structure
|
||||
@ -41,7 +40,6 @@ class xmldb_structure extends xmldb_object {
|
||||
$this->path = NULL;
|
||||
$this->version = NULL;
|
||||
$this->tables = array();
|
||||
$this->statements = array();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,19 +81,6 @@ class xmldb_structure extends xmldb_object {
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -109,19 +94,6 @@ class xmldb_structure extends xmldb_object {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -129,25 +101,6 @@ class xmldb_structure extends xmldb_object {
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -201,52 +154,6 @@ class xmldb_structure extends xmldb_object {
|
||||
$this->setChanged(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -279,38 +186,6 @@ class xmldb_structure extends xmldb_object {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -318,13 +193,6 @@ class xmldb_structure extends xmldb_object {
|
||||
$this->tables = $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the statements
|
||||
*/
|
||||
function setStatements(&$statements) {
|
||||
$this->statements = $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data from XML to the structure
|
||||
*/
|
||||
@ -409,47 +277,6 @@ class xmldb_structure extends xmldb_object {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 @@ class xmldb_structure extends xmldb_object {
|
||||
$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 @@ class xmldb_structure extends xmldb_object {
|
||||
}
|
||||
$o.= ' </TABLES>' . "\n";
|
||||
}
|
||||
/// Now the statements
|
||||
if ($this->statements) {
|
||||
$o.= ' <STATEMENTS>' . "\n";
|
||||
foreach ($this->statements as $statement) {
|
||||
$o.= $statement->xmlOutput();
|
||||
}
|
||||
$o.= ' </STATEMENTS>' . "\n";
|
||||
}
|
||||
$o.= '</XMLDB>';
|
||||
|
||||
return $o;
|
||||
@ -677,7 +487,7 @@ class xmldb_structure extends xmldb_object {
|
||||
|
||||
/**
|
||||
* 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 @@ class xmldb_structure extends xmldb_object {
|
||||
$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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user