. /** * @package tool * @subpackage xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * reporting about the ones not physically implemented as BIGINTs * and providing one SQL script to fix all them. Also, under MySQL, * it performs one check of signed bigints. MDL-11038 * * @package tool * @subpackage xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ 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 // Set own custom attributes // Get needed strings $this->loadStrings(array( 'wrongints' => 'tool_xmldb', 'nowrongintsfound' => 'tool_xmldb', 'yeswrongintsfound' => 'tool_xmldb', 'mysqlextracheckbigints' => 'tool_xmldb', )); // Correct fields must be type bigint for MySQL and int8 for PostgreSQL $this->dbfamily = $DB->get_dbfamily(); switch ($this->dbfamily) { case 'mysql': $this->correct_type = 'bigint'; break; case 'postgres': $this->correct_type = 'int8'; break; default: $this->correct_type = NULL; } } protected function check_table(xmldb_table $xmldb_table, array $metacolumns) { $o = ''; $wrong_fields = array(); // Get and process XMLDB fields if ($xmldb_fields = $xmldb_table->getFields()) { $o.=' '; } 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['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 ($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.= '
'; return $r; } }