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.= '
'; - $o.= '

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

'; - if ($dbfamily == 'mysql') { - $o.= '

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

'; - } - $o.= ' '; - $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=''; + } + + 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.= ' '; + $r.= ' '; + $r.= '
'; - $r.= '

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

'; - $r.= '

' . $this->str['wrongints'] . ': ' . count($wrong_fields) . '

'; - $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.= ' '; - $r.= ' '; - $r.= '
    '; + $r.= '

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

    '; + $r.= '

    ' . $this->str['wrongints'] . ': ' . count($wrong_fields) . '

    '; + $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.= '
    '; - /// Add the complete log message - $r.= '

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

    '; - $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.= '
'; + /// Add the complete log message + $r.= '

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

'; + $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.= '
'; - $o.= '

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

'; - $o.= ' '; - $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=''; } - /// 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.= ' '; + $r.= ' '; + $r.= '
'; + $r.= '

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

'; + $r.= '

' . $this->str['missingindexes'] . ': ' . count($missing_indexes) . '

'; + $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.= '
'; + /// Add the complete log message + $r.= '

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

'; + $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.= ' '; + $r.= ' '; + $r.= '
'; + $r.= '

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

'; + $r.= '

' . $this->str['wrongdefaults'] . ': ' . count($wrong_fields) . '

'; + $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.= '
'; + /// Add the complete log message + $r.= '

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

'; + $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.= '
'; + $o.= '

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

'; + $o.= ' '; + $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=''; + } + + /// 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 (