. /** * @package tool_xmldb * @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * This class will check all the varchar2() columns * in the Moodle installed DB, looking for incorrect (INT) * length semanticas providing one SQL script to fix all * them by changing to cross-db (CHAR) length semantics. * See MDL-29322 for more details. * * @package tool_xmldb * @copyright 2011 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class check_oracle_semantics extends XMLDBCheckAction { /** * Init method, every subclass will have its own */ function init() { $this->introstr = 'confirmcheckoraclesemantics'; parent::init(); // Set own core attributes // Set own custom attributes // Get needed strings $this->loadStrings(array( 'wrongoraclesemantics' => 'tool_xmldb', 'nowrongoraclesemanticsfound' => 'tool_xmldb', 'yeswrongoraclesemanticsfound' => 'tool_xmldb', 'expected' => 'tool_xmldb', 'actual' => 'tool_xmldb', )); } protected function check_table(xmldb_table $xmldb_table, array $metacolumns) { global $DB; $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['wrongoraclesemantics'] . ': ' . count($wrong_fields) . '

'; $r.= '
'; // If we have found wrong defaults inform about them if (count($wrong_fields)) { $r.= '

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

'; $r.= '
    '; foreach ($wrong_fields as $obj) { $xmldb_table = $obj->table; $xmldb_field = $obj->field; $r.= '
  • ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' . $this->str['field'] . ': ' . $xmldb_field->getName() . ', ' . $this->str['expected'] . ' ' . "'CHAR'" . ' ' . $this->str['actual'] . ' ' . "'BYTE'" . '
  • '; $sql = 'ALTER TABLE ' . $DB->get_prefix() . $xmldb_table->getName() . ' MODIFY ' . $xmldb_field->getName() . ' VARCHAR2(' . $xmldb_field->getLength() . ' CHAR)'; $sql = $dbman->generator->getEndedStatements($sql); $s.= '' . str_replace("\n", '
    ', $sql) . '

    '; } $r.= '
'; // Add the SQL statements (all together) $r.= '
' . $s; } else { $r.= '

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

'; } $r.= '
'; // Add the complete log message $r.= '

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

'; $r.= '
'; return $r; } }