Index: admin/xmldb/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/xmldb/index.php,v
retrieving revision 1.16
diff -u -r1.16 index.php
--- admin/xmldb/index.php 15 Jun 2008 11:28:17 -0000 1.16
+++ admin/xmldb/index.php 23 Oct 2008 04:38:20 -0000
@@ -32,7 +32,7 @@
/// Add required XMLDB action classes
require_once('actions/XMLDBAction.class.php');
-
+ require_once('actions/XMLDBCheckAction.class.php');
/// Add required XMLDB DB classes
require_once('../../lib/xmldb/xmldb_object.php');
Index: admin/xmldb/actions/check_bigints/check_bigints.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/xmldb/actions/check_bigints/check_bigints.class.php,v
retrieving revision 1.8
diff -u -r1.8 check_bigints.class.php
--- admin/xmldb/actions/check_bigints/check_bigints.class.php 19 Aug 2008 05:47:06 -0000 1.8
+++ admin/xmldb/actions/check_bigints/check_bigints.class.php 23 Oct 2008 04:38:20 -0000
@@ -29,12 +29,17 @@
/// and providing one SQL script to fix all them. Also, under MySQL,
/// it performs one check of signed bigints. MDL-11038
-class check_bigints extends XMLDBAction {
+class check_bigints extends XMLDBCheckAction {
+ private $correct_type;
+ private $dbfamily;
/**
* Init method, every subclass will have its own
*/
function init() {
+ global $DB;
+
+ $this->introstr = 'confirmcheckbigints';
parent::init();
/// Set own core attributes
@@ -43,231 +48,117 @@
/// Get needed strings
$this->loadStrings(array(
- 'confirmcheckbigints' => 'xmldb',
- 'ok' => '',
- 'wrong' => 'xmldb',
- 'table' => 'xmldb',
- 'field' => 'xmldb',
- 'searchresults' => 'xmldb',
'wrongints' => 'xmldb',
- 'completelogbelow' => 'xmldb',
'nowrongintsfound' => 'xmldb',
'yeswrongintsfound' => 'xmldb',
'mysqlextracheckbigints' => 'xmldb',
- 'yes' => '',
- 'no' => '',
- 'error' => '',
- '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;
-
- $dbman = $DB->get_manager();
- $dbfamily = $DB->get_dbfamily();
-
- /// Here we'll acummulate all the wrong fields found
- $wrong_fields = array();
/// Correct fields must be type bigint for MySQL and int8 for PostgreSQL
- switch ($dbfamily) {
+ $this->dbfamily = $DB->get_dbfamily();
+ switch ($this->dbfamily) {
case 'mysql':
- $correct_type = 'bigint';
+ $this->correct_type = 'bigint';
break;
case 'postgres':
- $correct_type = 'int8';
+ $this->correct_type = 'int8';
break;
default:
- $correct_type = NULL;
+ $this->correct_type = NULL;
}
+ }
- /// Do the job, setting $result as needed
-
- /// Get the confirmed to decide what to do
- $confirmed = optional_param('confirmed', false, PARAM_BOOL);
-
- /// If not confirmed, show confirmation box
- if (!$confirmed) {
- $o = '
';
- $o.= ' ';
- $o.= ' ' . $this->str['confirmcheckbigints'] . ' ';
- if ($dbfamily == 'mysql') {
- $o.= ' ' . $this->str['mysqlextracheckbigints'] . ' ';
- }
- $o.= ' ';
- $o.= ' ';
- $o.= ' ';
- $o.= ' | ';
- $o.= ' ';
- $o.= ' ';
- $o.= ' | ';
- $o.= ' ';
- $o.= ' |
';
- $o.= '
';
+ protected function check_table(xmldb_table $xmldb_table, array $metacolumns) {
+ $o = '';
+ $wrong_fields = array();
- $this->output = $o;
- } else {
- /// The back to edit table button
- $b = ' ';
- $b .= '[' . $this->str['back'] . ']';
- $b .= '
';
-
- /// Iterate over $XMLDB->dbdirs, loading their XML data to memory
- if ($XMLDB->dbdirs) {
- $dbdirs =& $XMLDB->dbdirs;
- $o='';
- foreach ($dbdirs as $dbdir) {
- /// Only if the directory exists
- if (!$dbdir->path_exists) {
- continue;
- }
- /// Load the XML file
- $xmldb_file = new xmldb_file($dbdir->path . '/install.xml');
-
- /// Only if the file exists
- if (!$xmldb_file->fileExists()) {
- continue;
- }
- /// Load the XML contents to structure
- $loaded = $xmldb_file->loadXMLStructure();
- if (!$loaded || !$xmldb_file->isLoaded()) {
- notify('Errors found in XMLDB file: '. $dbdir->path . '/install.xml');
- continue;
- }
- /// Arriving here, everything is ok, get the XMLDB structure
- $structure = $xmldb_file->getStructure();
- $o.=' - ' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml');
- /// Getting tables
- if ($xmldb_tables = $structure->getTables()) {
- $o.='
';
- /// Foreach table, process its fields
- foreach ($xmldb_tables as $xmldb_table) {
- /// Skip table if not exists
- if (!$dbman->table_exists($xmldb_table)) {
- continue;
- }
- /// Fetch metadata from phisical DB. All the columns info.
- if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) {
- //// Skip table if no metacolumns is available for it
- continue;
- }
- /// Table processing starts here
- $o.=' - ' . $xmldb_table->getName();
- /// Get and process XMLDB fields
- if ($xmldb_fields = $xmldb_table->getFields()) {
- $o.='
';
- foreach ($xmldb_fields as $xmldb_field) {
- /// If the field isn't integer(10), skip
- if ($xmldb_field->getType() != XMLDB_TYPE_INTEGER || $xmldb_field->getLength() != 10) {
- continue;
- }
- /// If the metadata for that column doesn't exist, skip
- if (!isset($metacolumns[$xmldb_field->getName()])) {
- continue;
- }
- /// To variable for better handling
- $metacolumn = $metacolumns[$xmldb_field->getName()];
- /// Going to check this field in DB
- $o.=' - ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' ';
- /// Detect if the phisical field is wrong and, under mysql, check for incorrect signed fields too
- if ($metacolumn->type != $correct_type || ($dbfamily == 'mysql' && $xmldb_field->getUnsigned() && !$metacolumn->unsigned)) {
- $o.='' . $this->str['wrong'] . '';
- /// Add the wrong field to the list
- $obj = new object;
- $obj->table = $xmldb_table;
- $obj->field = $xmldb_field;
- $wrong_fields[] = $obj;
- } else {
- $o.='' . $this->str['ok'] . '';
- }
- $o.='
';
- }
- $o.='
';
- }
- $o.=' ';
- }
- $o.='
';
- }
- $o.=' ';
+ /// Get and process XMLDB fields
+ if ($xmldb_fields = $xmldb_table->getFields()) {
+ $o.=' ';
+ foreach ($xmldb_fields as $xmldb_field) {
+ /// If the field isn't integer(10), skip
+ if ($xmldb_field->getType() != XMLDB_TYPE_INTEGER || $xmldb_field->getLength() != 10) {
+ continue;
}
- $o.='
';
+ /// If the metadata for that column doesn't exist, skip
+ if (!isset($metacolumns[$xmldb_field->getName()])) {
+ continue;
+ }
+ /// To variable for better handling
+ $metacolumn = $metacolumns[$xmldb_field->getName()];
+ /// Going to check this field in DB
+ $o.=' - ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' ';
+ /// Detect if the phisical field is wrong and, under mysql, check for incorrect signed fields too
+ if ($metacolumn->type != $this->correct_type || ($this->dbfamily == 'mysql' && $xmldb_field->getUnsigned() && !$metacolumn->unsigned)) {
+ $o.='' . $this->str['wrong'] . '';
+ /// Add the wrong field to the list
+ $obj = new object;
+ $obj->table = $xmldb_table;
+ $obj->field = $xmldb_field;
+ $wrong_fields[] = $obj;
+ } else {
+ $o.='' . $this->str['ok'] . '';
+ }
+ $o.='
';
}
+ $o.='
';
+ }
+
+ return array($o, $wrong_fields);
+ }
+
+ protected function display_results(array $wrong_fields) {
+ global $DB;
+ $dbman = $DB->get_manager();
- /// We have finished, let's show the results of the search
- $s = '';
- $r = '';
- $r.= ' ';
- $r.= ' ' . $this->str['searchresults'] . '';
- $r.= ' ' . $this->str['wrongints'] . ': ' . count($wrong_fields) . ' ';
- $r.= ' |
';
- $r.= ' ';
-
- /// If we have found wrong integers inform about them
- if (count($wrong_fields)) {
- $r.= ' ' . $this->str['yeswrongintsfound'] . ' ';
- $r.= ' ';
- foreach ($wrong_fields as $obj) {
- $xmldb_table = $obj->table;
- $xmldb_field = $obj->field;
- /// MySQL directly supports this
+ $s = '';
+ $r = '';
+ $r.= ' ';
+ $r.= ' ' . $this->str['searchresults'] . '';
+ $r.= ' ' . $this->str['wrongints'] . ': ' . count($wrong_fields) . ' ';
+ $r.= ' | ';
+ $r.= ' ';
+
+ /// If we have found wrong integers inform about them
+ if (count($wrong_fields)) {
+ $r.= ' ' . $this->str['yeswrongintsfound'] . ' ';
+ $r.= ' ';
+ foreach ($wrong_fields as $obj) {
+ $xmldb_table = $obj->table;
+ $xmldb_field = $obj->field;
+ /// MySQL directly supports this
// TODO: move this hack to generators!!
- if ($dbfamily == 'mysql') {
- $sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field);
- /// PostgreSQL (XMLDB implementation) is a bit, er... imperfect.
- } else if ($dbfamily == 'postgres') {
- $sqlarr = array('ALTER TABLE ' . $DB->get_prefix() . $xmldb_table->getName() .
- ' ALTER COLUMN ' . $xmldb_field->getName() . ' TYPE BIGINT;');
- }
- $r.= ' - ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
- $this->str['field'] . ': ' . $xmldb_field->getName() . '
';
- /// Add to output if we have sentences
- if ($sqlarr) {
- $sqlarr = $dbman->generator->getEndedStatements($sqlarr);
- $s.= '' . str_replace("\n", ' ', implode(' ', $sqlarr)). ' ';
- }
+ if ($this->dbfamily == 'mysql') {
+ $sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field);
+ /// PostgreSQL (XMLDB implementation) is a bit, er... imperfect.
+ } else if ($this->dbfamily == 'postgres') {
+ $sqlarr = array('ALTER TABLE ' . $DB->get_prefix() . $xmldb_table->getName() .
+ ' ALTER COLUMN ' . $xmldb_field->getName() . ' TYPE BIGINT;');
+ }
+ $r.= ' - ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
+ $this->str['field'] . ': ' . $xmldb_field->getName() . '
';
+ /// Add to output if we have sentences
+ if ($sqlarr) {
+ $sqlarr = $dbman->generator->getEndedStatements($sqlarr);
+ $s.= '' . str_replace("\n", ' ', implode(' ', $sqlarr)). ' ';
}
- $r.= ' ';
- /// Add the SQL statements (all together)
- $r.= ' ' . $s;
- } else {
- $r.= ' ' . $this->str['nowrongintsfound'] . ' ';
}
- $r.= ' | ';
- $r.= ' ';
- /// Add the complete log message
- $r.= ' ' . $this->str['completelogbelow'] . ' ';
- $r.= ' | ';
- $r.= ' ';
-
- $this->output = $b . $r . $o;
- }
-
- /// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
- return $this->launch($this->getPostAction());
+ $r.= ' ';
+ /// Add the SQL statements (all together)
+ $r.= ' ' . $s;
+ } else {
+ $r.= ' ' . $this->str['nowrongintsfound'] . ' ';
}
+ $r.= ' |
';
+ $r.= ' ';
+ /// Add the complete log message
+ $r.= ' ' . $this->str['completelogbelow'] . ' ';
+ $r.= ' |
';
+ $r.= '
';
- /// Return ok if arrived here
- return $result;
+ return $r;
}
}
?>
Index: admin/xmldb/actions/check_indexes/check_indexes.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/xmldb/actions/check_indexes/check_indexes.class.php,v
retrieving revision 1.10
diff -u -r1.10 check_indexes.class.php
--- admin/xmldb/actions/check_indexes/check_indexes.class.php 15 Jun 2008 10:32:54 -0000 1.10
+++ admin/xmldb/actions/check_indexes/check_indexes.class.php 23 Oct 2008 04:38:21 -0000
@@ -28,12 +28,13 @@
/// with the phisical DB implementation, reporting about all the missing
/// indexes to be created to be 100% ok.
-class check_indexes extends XMLDBAction {
+class check_indexes extends XMLDBCheckAction {
/**
* Init method, every subclass will have its own
*/
function init() {
+ $this->introstr = 'confirmcheckindexes';
parent::init();
/// Set own core attributes
@@ -42,226 +43,127 @@
/// Get needed strings
$this->loadStrings(array(
- 'confirmcheckindexes' => 'xmldb',
- 'ok' => '',
'missing' => 'xmldb',
- 'table' => 'xmldb',
'key' => 'xmldb',
'index' => 'xmldb',
- 'searchresults' => 'xmldb',
'missingindexes' => 'xmldb',
- 'completelogbelow' => 'xmldb',
'nomissingindexesfound' => 'xmldb',
'yesmissingindexesfound' => 'xmldb',
- 'yes' => '',
- 'no' => '',
- '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;
-
+ protected function check_table(xmldb_table $xmldb_table, array $metacolumns) {
+ global $DB;
$dbman = $DB->get_manager();
- /// Here we'll acummulate all the missing indexes found
+ $o = '';
$missing_indexes = array();
- /// Do the job, setting $result as needed
-
- /// Get the confirmed to decide what to do
- $confirmed = optional_param('confirmed', false, PARAM_BOOL);
-
- /// If not confirmed, show confirmation box
- if (!$confirmed) {
- $o = '';
- $o.= ' ';
- $o.= ' ' . $this->str['confirmcheckindexes'] . ' ';
- $o.= ' ';
- $o.= ' ';
- $o.= ' ';
- $o.= ' | ';
- $o.= ' ';
- $o.= ' ';
- $o.= ' | ';
- $o.= ' ';
- $o.= ' |
';
- $o.= '
';
-
- $this->output = $o;
- } else {
- /// The back to edit table button
- $b = ' ';
- $b .= '[' . $this->str['back'] . ']';
- $b .= '
';
-
- /// Iterate over $XMLDB->dbdirs, loading their XML data to memory
- if ($XMLDB->dbdirs) {
- $dbdirs =& $XMLDB->dbdirs;
- $o='';
- foreach ($dbdirs as $dbdir) {
- /// Only if the directory exists
- if (!$dbdir->path_exists) {
- continue;
- }
- /// Load the XML file
- $xmldb_file = new xmldb_file($dbdir->path . '/install.xml');
-
- /// Only if the file exists
- if (!$xmldb_file->fileExists()) {
- continue;
- }
- /// Load the XML contents to structure
- $loaded = $xmldb_file->loadXMLStructure();
- if (!$loaded || !$xmldb_file->isLoaded()) {
- notify('Errors found in XMLDB file: '. $dbdir->path . '/install.xml');
- continue;
+ /// Keys
+ if ($xmldb_keys = $xmldb_table->getKeys()) {
+ $o.=' ';
+ foreach ($xmldb_keys as $xmldb_key) {
+ $o.=' - ' . $this->str['key'] . ': ' . $xmldb_key->readableInfo() . ' ';
+ /// Primaries are skipped
+ if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) {
+ $o.='' . $this->str['ok'] . '
';
+ continue;
+ }
+ /// If we aren't creating the keys or the key is a XMLDB_KEY_FOREIGN (not underlying index generated
+ /// automatically by the RDBMS) create the underlying (created by us) index (if doesn't exists)
+ if (!$dbman->generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) {
+ /// Create the interim index
+ $xmldb_index = new xmldb_index('anyname');
+ $xmldb_index->setFields($xmldb_key->getFields());
+ switch ($xmldb_key->getType()) {
+ case XMLDB_KEY_UNIQUE:
+ case XMLDB_KEY_FOREIGN_UNIQUE:
+ $xmldb_index->setUnique(true);
+ break;
+ case XMLDB_KEY_FOREIGN:
+ $xmldb_index->setUnique(false);
+ break;
}
- /// Arriving here, everything is ok, get the XMLDB structure
- $structure = $xmldb_file->getStructure();
- $o.=' - ' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml');
- /// Getting tables
- if ($xmldb_tables = $structure->getTables()) {
- $o.='
';
- /// Foreach table, process its indexes and keys
- foreach ($xmldb_tables as $xmldb_table) {
- /// Skip table if not exists
- if (!$dbman->table_exists($xmldb_table)) {
- continue;
- }
- $o.=' - ' . $xmldb_table->getName();
- /// Keys
- if ($xmldb_keys = $xmldb_table->getKeys()) {
- $o.='
';
- foreach ($xmldb_keys as $xmldb_key) {
- $o.=' - ' . $this->str['key'] . ': ' . $xmldb_key->readableInfo() . ' ';
- /// Primaries are skipped
- if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) {
- $o.='' . $this->str['ok'] . '
';
- continue;
- }
- /// If we aren't creating the keys or the key is a XMLDB_KEY_FOREIGN (not underlying index generated
- /// automatically by the RDBMS) create the underlying (created by us) index (if doesn't exists)
- if (!$dbman->generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) {
- /// Create the interim index
- $xmldb_index = new xmldb_index('anyname');
- $xmldb_index->setFields($xmldb_key->getFields());
- switch ($xmldb_key->getType()) {
- case XMLDB_KEY_UNIQUE:
- case XMLDB_KEY_FOREIGN_UNIQUE:
- $xmldb_index->setUnique(true);
- break;
- case XMLDB_KEY_FOREIGN:
- $xmldb_index->setUnique(false);
- break;
- }
- /// Check if the index exists in DB
- if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
- $o.='' . $this->str['ok'] . '';
- } else {
- $o.='' . $this->str['missing'] . '';
- /// Add the missing index to the list
- $obj = new object;
- $obj->table = $xmldb_table;
- $obj->index = $xmldb_index;
- $missing_indexes[] = $obj;
- }
- }
- $o.='
';
- }
- $o.='
';
- }
- /// Indexes
- if ($xmldb_indexes = $xmldb_table->getIndexes()) {
- $o.=' ';
- foreach ($xmldb_indexes as $xmldb_index) {
- $o.=' - ' . $this->str['index'] . ': ' . $xmldb_index->readableInfo() . ' ';
- /// Check if the index exists in DB
- if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
- $o.='' . $this->str['ok'] . '';
- } else {
- $o.='' . $this->str['missing'] . '';
- /// Add the missing index to the list
- $obj = new object;
- $obj->table = $xmldb_table;
- $obj->index = $xmldb_index;
- $missing_indexes[] = $obj;
- }
- $o.='
';
- }
- $o.='
';
- }
- $o.=' ';
- }
- $o.='
';
+ /// Check if the index exists in DB
+ if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
+ $o.='' . $this->str['ok'] . '';
+ } else {
+ $o.='' . $this->str['missing'] . '';
+ /// Add the missing index to the list
+ $obj = new object;
+ $obj->table = $xmldb_table;
+ $obj->index = $xmldb_index;
+ $missing_indexes[] = $obj;
}
- $o.=' ';
}
- $o.='
';
+ $o.='';
}
-
- /// We have finished, let's show the results of the search
- $s = '';
- $r = '';
- $r.= ' ';
- $r.= ' ' . $this->str['searchresults'] . '';
- $r.= ' ' . $this->str['missingindexes'] . ': ' . count($missing_indexes) . ' ';
- $r.= ' |
';
- $r.= ' ';
-
- /// If we have found missing indexes inform about them
- if (count($missing_indexes)) {
- $r.= ' ' . $this->str['yesmissingindexesfound'] . ' ';
- $r.= ' ';
- foreach ($missing_indexes as $obj) {
- $xmldb_table = $obj->table;
- $xmldb_index = $obj->index;
- $sqlarr = $dbman->generator->getAddIndexSQL($xmldb_table, $xmldb_index);
- $r.= ' - ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
- $this->str['index'] . ': ' . $xmldb_index->readableInfo() . '
';
- $sqlarr = $dbman->generator->getEndedStatements($sqlarr);
- $s.= '' . str_replace("\n", ' ', implode(' ', $sqlarr)) . ' ';
-
+ $o.=' ';
+ }
+ /// Indexes
+ if ($xmldb_indexes = $xmldb_table->getIndexes()) {
+ $o.=' ';
+ foreach ($xmldb_indexes as $xmldb_index) {
+ $o.=' - ' . $this->str['index'] . ': ' . $xmldb_index->readableInfo() . ' ';
+ /// Check if the index exists in DB
+ if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
+ $o.='' . $this->str['ok'] . '';
+ } else {
+ $o.='' . $this->str['missing'] . '';
+ /// Add the missing index to the list
+ $obj = new object;
+ $obj->table = $xmldb_table;
+ $obj->index = $xmldb_index;
+ $missing_indexes[] = $obj;
}
- $r.= '
';
- /// Add the SQL statements (all together)
- $r.= ' ' . $s;
- } else {
- $r.= ' ' . $this->str['nomissingindexesfound'] . ' ';
+ $o.='';
}
- $r.= ' |
';
- $r.= ' ';
- /// Add the complete log message
- $r.= ' ' . $this->str['completelogbelow'] . ' ';
- $r.= ' |
';
- $r.= '
';
-
- $this->output = $b . $r . $o;
+ $o.=' ';
}
- /// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
- return $this->launch($this->getPostAction());
+ return array($o, $missing_indexes);
+ }
+
+ protected function display_results(array $missing_indexes) {
+ global $DB;
+ $dbman = $DB->get_manager();
+
+ $s = '';
+ $r = '';
+ $r.= ' ';
+ $r.= ' ' . $this->str['searchresults'] . '';
+ $r.= ' ' . $this->str['missingindexes'] . ': ' . count($missing_indexes) . ' ';
+ $r.= ' |
';
+ $r.= ' ';
+
+ /// If we have found missing indexes inform about them
+ if (count($missing_indexes)) {
+ $r.= ' ' . $this->str['yesmissingindexesfound'] . ' ';
+ $r.= ' ';
+ foreach ($missing_indexes as $obj) {
+ $xmldb_table = $obj->table;
+ $xmldb_index = $obj->index;
+ $sqlarr = $dbman->generator->getAddIndexSQL($xmldb_table, $xmldb_index);
+ $r.= ' - ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
+ $this->str['index'] . ': ' . $xmldb_index->readableInfo() . '
';
+ $sqlarr = $dbman->generator->getEndedStatements($sqlarr);
+ $s.= '' . str_replace("\n", ' ', implode(' ', $sqlarr)) . ' ';
+
+ }
+ $r.= ' ';
+ /// Add the SQL statements (all together)
+ $r.= ' ' . $s;
+ } else {
+ $r.= ' ' . $this->str['nomissingindexesfound'] . ' ';
}
+ $r.= ' |
';
+ $r.= ' ';
+ /// Add the complete log message
+ $r.= ' ' . $this->str['completelogbelow'] . ' ';
+ $r.= ' |
';
+ $r.= '
';
- /// Return ok if arrived here
- return $result;
+ return $r;
}
}
?>
Index: admin/xmldb/actions/check_defaults/check_defaults.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/xmldb/actions/check_defaults/check_defaults.class.php,v
retrieving revision 1.6
diff -u -r1.6 check_defaults.class.php
--- admin/xmldb/actions/check_defaults/check_defaults.class.php 15 Jun 2008 10:32:54 -0000 1.6
+++ admin/xmldb/actions/check_defaults/check_defaults.class.php 23 Oct 2008 04:38:20 -0000
@@ -28,12 +28,13 @@
/// match those specified in the xml specs
/// and providing one SQL script to fix all them.
-class check_defaults extends XMLDBAction {
+class check_defaults extends XMLDBCheckAction {
/**
* Init method, every subclass will have its own
*/
function init() {
+ $this->introstr = 'confirmcheckdefaults';
parent::init();
/// Set own core attributes
@@ -42,230 +43,117 @@
/// Get needed strings
$this->loadStrings(array(
- 'confirmcheckdefaults' => 'xmldb',
- 'ok' => '',
- 'wrong' => 'xmldb',
- 'table' => 'xmldb',
- 'field' => 'xmldb',
- 'searchresults' => 'xmldb',
'wrongdefaults' => 'xmldb',
- 'completelogbelow' => 'xmldb',
'nowrongdefaultsfound' => 'xmldb',
'yeswrongdefaultsfound' => 'xmldb',
- 'yes' => '',
- 'no' => '',
- 'error' => '',
'expected' => 'xmldb',
'actual' => '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;
-
- /// And we nedd some ddl suff
- $dbman = $DB->get_manager();
-
- /// Here we'll acummulate all the wrong fields found
+ protected function check_table(xmldb_table $xmldb_table, array $metacolumns) {
+ $o = '';
$wrong_fields = array();
- /// Do the job, setting $result as needed
+ /// Get and process XMLDB fields
+ if ($xmldb_fields = $xmldb_table->getFields()) {
+ $o.=' ';
}
- /// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
- return $this->launch($this->getPostAction());
+ return array($o, $wrong_fields);
+ }
+
+ protected function display_results(array $wrong_fields) {
+ global $DB;
+ $dbman = $DB->get_manager();
+
+ $s = '';
+ $r = '';
+ $r.= ' ';
+ $r.= ' ' . $this->str['searchresults'] . '';
+ $r.= ' ' . $this->str['wrongdefaults'] . ': ' . count($wrong_fields) . ' ';
+ $r.= ' |
';
+ $r.= ' ';
+
+ /// If we have found wrong defaults inform about them
+ if (count($wrong_fields)) {
+ $r.= ' ' . $this->str['yeswrongdefaultsfound'] . ' ';
+ $r.= ' ';
+ foreach ($wrong_fields as $obj) {
+ $xmldb_table = $obj->table;
+ $xmldb_field = $obj->field;
+ $physicaldefault = $obj->physicaldefault;
+ $xmldbdefault = $obj->xmldbdefault;
+
+ // get the alter table command
+ $sqlarr = $dbman->generator->getAlterFieldSQL($xmldb_table, $xmldb_field);
+
+ $r.= ' - ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' .
+ $this->str['field'] . ': ' . $xmldb_field->getName() . ', ' .
+ $this->str['expected'] . ' ' . "'$xmldbdefault'" . ' ' .
+ $this->str['actual'] . ' ' . "'$physicaldefault'" . '
';
+ /// Add to output if we have sentences
+ if ($sqlarr) {
+ $sqlarr = $dbman->generator->getEndedStatements($sqlarr);
+ $s.= '' . str_replace("\n", ' ', implode(' ', $sqlarr)) . ' ';
+ }
+ }
+ $r.= ' ';
+ /// Add the SQL statements (all together)
+ $r.= ' ' . $s;
+ } else {
+ $r.= ' ' . $this->str['nowrongdefaultsfound'] . ' ';
}
+ $r.= ' |
';
+ $r.= ' ';
+ /// Add the complete log message
+ $r.= ' ' . $this->str['completelogbelow'] . ' ';
+ $r.= ' |
';
+ $r.= '
';
- /// Return ok if arrived here
- return $result;
+ return $r;
}
}
?>
Index: admin/xmldb/actions/XMLDBCheckAction.class.php
===================================================================
RCS file: admin/xmldb/actions/XMLDBCheckAction.class.php
diff -N admin/xmldb/actions/XMLDBCheckAction.class.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ admin/xmldb/actions/XMLDBCheckAction.class.php 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,206 @@
+loadStrings(array(
+ $this->introstr => 'xmldb',
+ 'ok' => '',
+ 'wrong' => 'xmldb',
+ 'table' => 'xmldb',
+ 'field' => 'xmldb',
+ 'searchresults' => 'xmldb',
+ 'completelogbelow' => 'xmldb',
+ 'yes' => '',
+ 'no' => '',
+ 'error' => '',
+ '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;
+
+ /// And we nedd some ddl suff
+ $dbman = $DB->get_manager();
+
+ /// Here we'll acummulate all the wrong fields found
+ $problemsfound = array();
+
+ /// Do the job, setting $result as needed
+
+ /// Get the confirmed to decide what to do
+ $confirmed = optional_param('confirmed', false, PARAM_BOOL);
+
+ /// If not confirmed, show confirmation box
+ if (!$confirmed) {
+ $o = '';
+ $o.= ' ';
+ $o.= ' ' . $this->str[$this->introstr] . ' ';
+ $o.= ' ';
+ $o.= ' ';
+ $o.= ' ';
+ $o.= ' | ';
+ $o.= ' ';
+ $o.= ' ';
+ $o.= ' | ';
+ $o.= ' ';
+ $o.= ' |
';
+ $o.= '
';
+
+ $this->output = $o;
+ } else {
+ /// The back to edit table button
+ $b = ' ';
+ $b .= '[' . $this->str['back'] . ']';
+ $b .= '
';
+
+ /// Iterate over $XMLDB->dbdirs, loading their XML data to memory
+ if ($XMLDB->dbdirs) {
+ $dbdirs =& $XMLDB->dbdirs;
+ $o='';
+ foreach ($dbdirs as $dbdir) {
+ /// Only if the directory exists
+ if (!$dbdir->path_exists) {
+ continue;
+ }
+ /// Load the XML file
+ $xmldb_file = new xmldb_file($dbdir->path . '/install.xml');
+
+ /// Only if the file exists
+ if (!$xmldb_file->fileExists()) {
+ continue;
+ }
+ /// Load the XML contents to structure
+ $loaded = $xmldb_file->loadXMLStructure();
+ if (!$loaded || !$xmldb_file->isLoaded()) {
+ notify('Errors found in XMLDB file: '. $dbdir->path . '/install.xml');
+ continue;
+ }
+ /// Arriving here, everything is ok, get the XMLDB structure
+ $structure = $xmldb_file->getStructure();
+
+ $o.=' - ' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml');
+ /// Getting tables
+ if ($xmldb_tables = $structure->getTables()) {
+ $o.='
';
+ /// Foreach table, process its fields
+ foreach ($xmldb_tables as $xmldb_table) {
+ /// Skip table if not exists
+ if (!$dbman->table_exists($xmldb_table)) {
+ continue;
+ }
+ /// Fetch metadata from phisical DB. All the columns info.
+ if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) {
+ //// Skip table if no metacolumns is available for it
+ continue;
+ }
+ /// Table processing starts here
+ $o.=' - ' . $xmldb_table->getName();
+ /// Do the specific check.
+ list($output, $newproblems) = $this->check_table($xmldb_table, $metacolumns);
+ $o.=$output;
+ $problemsfound = array_merge($problemsfound, $newproblems);
+ $o.='
';
+ }
+ $o.='
';
+ }
+ $o.=' ';
+ }
+ $o.='
';
+ }
+
+ /// Create a report of the problems found.
+ $r = $this->display_results($problemsfound);
+
+ /// Combine the various bits of output.
+ $this->output = $b . $r . $o;
+ }
+
+ /// Launch postaction if exists (leave this here!)
+ if ($this->getPostAction() && $result) {
+ return $this->launch($this->getPostAction());
+ }
+
+ /// Return ok if arrived here
+ return $result;
+ }
+
+ /**
+ * Do the checks necessary on one particular table.
+ *
+ * @param xmldb_table $xmldb_table the table definition from the install.xml file.
+ * @param array $metacolumns the column information read from the database.
+ * @return array an array with two elements: First, some additional progress output,
+ * for example a list () of the things check each with an one work ok/not ok summary.
+ * Second, an array giving the details of any problems found. These arrays
+ * for all tables will be aggregated, and then passed to
+ */
+ abstract protected function check_table(xmldb_table $xmldb_table, array $metacolumns);
+
+ /**
+ * Display a list of the problems found.
+ *
+ * @param array $problems_found an aggregation of all the problems found by
+ * all the check_table calls.
+ * @return string a display of all the problems found as HTML.
+ */
+ abstract protected function display_results(array $problems_found);
+}
+?>