diff --git a/admin/tool/xmldb/actions/check_oracle_semantics/check_oracle_semantics.class.php b/admin/tool/xmldb/actions/check_oracle_semantics/check_oracle_semantics.class.php new file mode 100644 index 00000000000..97248cd1bed --- /dev/null +++ b/admin/tool/xmldb/actions/check_oracle_semantics/check_oracle_semantics.class.php @@ -0,0 +1,153 @@ +. + +/** + * @package xmldb-editor + * @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 xmldb-editor + * @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; + } +} diff --git a/admin/tool/xmldb/actions/main_view/main_view.class.php b/admin/tool/xmldb/actions/main_view/main_view.class.php index 833cea10df3..73d6b9f7395 100644 --- a/admin/tool/xmldb/actions/main_view/main_view.class.php +++ b/admin/tool/xmldb/actions/main_view/main_view.class.php @@ -58,6 +58,7 @@ class main_view extends XMLDBAction { 'checkdefaults' => 'tool_xmldb', 'checkforeignkeys' => 'tool_xmldb', 'checkbigints' => 'tool_xmldb', + 'checkoraclesemantics' => 'tool_xmldb', 'doc' => 'tool_xmldb', 'viewxml' => 'tool_xmldb', 'pendingchangescannotbesavedreload' => 'tool_xmldb' @@ -105,6 +106,10 @@ class main_view extends XMLDBAction { if ($DB->get_dbfamily() == 'mysql' || $DB->get_dbfamily() == 'postgres') { $b .= ' [' . $this->str['checkbigints'] . ']'; } + /// The check semantics button (only for Oracle) MDL-29416 + if ($DB->get_dbfamily() == 'oracle') { + $b .= ' [' . $this->str['checkoraclesemantics'] . ']'; + } $b .= ' [' . $this->str['checkforeignkeys'] . ']'; $b .= '

'; /// Send buttons to output diff --git a/admin/tool/xmldb/lang/en/tool_xmldb.php b/admin/tool/xmldb/lang/en/tool_xmldb.php index d95ca7c19a2..1c2a350c841 100644 --- a/admin/tool/xmldb/lang/en/tool_xmldb.php +++ b/admin/tool/xmldb/lang/en/tool_xmldb.php @@ -50,6 +50,10 @@ $string['confirmcheckindexes'] = 'This functionality will search for potential m Once generated you can copy such statements and execute them safely with your favourite SQL interface (don\'t forget to backup your data before doing that).

It\'s highly recommended to be running the latest (+ version) available of your Moodle release (1.8, 1.9, 2.x ...) before executing the search of missing indexes.

This functionality doesn\'t perform any action against the DB (just reads from it), so can be safely executed at any moment.'; +$string['confirmcheckoraclesemantics'] = 'This functionality will search for Oracle varchar2 columns using BYTE semantics in your Moodle server, generating (but not executing!) automatically the needed SQL statements to have all the columns converted to use CHAR semantics instead (better for cross-db compatibility and increased contents max. length).

+Once generated you can copy such statements and execute them safely with your favourite SQL interface (don\'t forget to backup your data before doing that).

+It\'s highly recommended to be running the latest (+ version) available of your Moodle release (2.2, 2.3, 2.x ...) before executing the search of BYTE semantics.

+This functionality doesn\'t perform any action against the DB (just reads from it), so can be safely executed at any moment.'; $string['confirmrevertchanges'] = 'Are you absolutely sure that you want to revert changes performed over:'; $string['create'] = 'Create'; $string['createtable'] = 'Create table:'; @@ -103,6 +107,8 @@ $string['checkforeignkeys'] = 'Check foreign keys'; $string['check_foreign_keys'] = 'Look for foreign key violations'; $string['checkindexes'] = 'Check indexes'; $string['check_indexes'] = 'Look for missing DB indexes'; +$string['checkoraclesemantics'] = 'Check semantics'; +$string['check_oracle_semantics'] = 'Look for incorrect length semantics'; $string['incorrectfieldname'] = 'Incorrect name'; $string['index'] = 'Index'; $string['indexes'] = 'Indexes'; @@ -130,6 +136,7 @@ $string['nomissingindexesfound'] = 'No missing indexes have been found, your DB $string['noviolatedforeignkeysfound'] = 'No violated foreign keys found'; $string['nowrongdefaultsfound'] = 'No inconsistent default values have been found, your DB does not need further actions.'; $string['nowrongintsfound'] = 'No wrong integers have been found, your DB doesn\'t need further actions.'; +$string['nowrongoraclesemanticsfound'] = 'No Oracle columns using BYTE semantics have been found, your DB doesn\'t need further actions.'; $string['numberincorrectdecimals'] = 'Incorrect number of decimals for number field'; $string['numberincorrectlength'] = 'Incorrect length for number field'; $string['pendingchanges'] = 'Note: You have performed changes to this file. They can be saved at any moment.'; @@ -172,6 +179,8 @@ $string['wrongdefaults'] = 'Wrong defaults found'; $string['wrongints'] = 'Wrong integers found'; $string['wronglengthforenum'] = 'Incorrect length for enum field'; $string['wrongreservedwords'] = 'Currently used reserved words
(note that table names aren\'t important if using $CFG->prefix)'; +$string['wrongoraclesemantics'] = 'Wrong Oracle BYTE semantics found'; $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).

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).

After doing that, it\'s highly recommended to execute this utility again to check that no more inconsistent defaults are found.'; $string['yeswrongintsfound'] = 'Some wrong integers 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).

After doing that, it\'s highly recommended to execute this utility again to check that no more wrong integers are found.'; +$string['yeswrongoraclesemanticsfound'] = 'Some Oracle columns using BYTE semantics 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).

After doing that, it\'s highly recommended to execute this utility again to check that no more wrong semantics are found.';