|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00035 class check_oracle_semantics extends XMLDBCheckAction { 00036 00040 function init() { 00041 $this->introstr = 'confirmcheckoraclesemantics'; 00042 parent::init(); 00043 00044 // Set own core attributes 00045 00046 // Set own custom attributes 00047 00048 // Get needed strings 00049 $this->loadStrings(array( 00050 'wrongoraclesemantics' => 'tool_xmldb', 00051 'nowrongoraclesemanticsfound' => 'tool_xmldb', 00052 'yeswrongoraclesemanticsfound' => 'tool_xmldb', 00053 'expected' => 'tool_xmldb', 00054 'actual' => 'tool_xmldb', 00055 )); 00056 } 00057 00058 protected function check_table(xmldb_table $xmldb_table, array $metacolumns) { 00059 global $DB; 00060 $o = ''; 00061 $wrong_fields = array(); 00062 00063 // Get and process XMLDB fields 00064 if ($xmldb_fields = $xmldb_table->getFields()) { 00065 $o .= '<ul>'; 00066 foreach ($xmldb_fields as $xmldb_field) { 00067 00068 // Get the type of the column, we only will process CHAR (VARCHAR2) ones 00069 if ($xmldb_field->getType() != XMLDB_TYPE_CHAR) { 00070 continue; 00071 } 00072 00073 $o.='<li>' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' '; 00074 00075 // Get current semantic from dictionary, we only will process B (BYTE) ones 00076 // suplying the SQL code to change them to C (CHAR) semantic 00077 $params = array( 00078 'table_name' => textlib::strtoupper($DB->get_prefix() . $xmldb_table->getName()), 00079 'column_name' => textlib::strtoupper($xmldb_field->getName()), 00080 'data_type' => 'VARCHAR2'); 00081 $currentsemantic = $DB->get_field_sql(' 00082 SELECT char_used 00083 FROM user_tab_columns 00084 WHERE table_name = :table_name 00085 AND column_name = :column_name 00086 AND data_type = :data_type', $params); 00087 00088 // If using byte semantics, we'll need to change them to char semantics 00089 if ($currentsemantic == 'B') { 00090 $info = '(' . $this->str['expected'] . " 'CHAR', " . $this->str['actual'] . " 'BYTE')"; 00091 $o .= '<font color="red">' . $this->str['wrong'] . " $info</font>"; 00092 // Add the wrong field to the list 00093 $obj = new stdClass(); 00094 $obj->table = $xmldb_table; 00095 $obj->field = $xmldb_field; 00096 $wrong_fields[] = $obj; 00097 } else { 00098 $o .= '<font color="green">' . $this->str['ok'] . '</font>'; 00099 } 00100 $o .= '</li>'; 00101 } 00102 $o .= '</ul>'; 00103 } 00104 00105 return array($o, $wrong_fields); 00106 } 00107 00108 protected function display_results(array $wrong_fields) { 00109 global $DB; 00110 $dbman = $DB->get_manager(); 00111 00112 $s = ''; 00113 $r = '<table class="generalbox boxaligncenter boxwidthwide" border="0" cellpadding="5" cellspacing="0" id="results">'; 00114 $r.= ' <tr><td class="generalboxcontent">'; 00115 $r.= ' <h2 class="main">' . $this->str['searchresults'] . '</h2>'; 00116 $r.= ' <p class="centerpara">' . $this->str['wrongoraclesemantics'] . ': ' . count($wrong_fields) . '</p>'; 00117 $r.= ' </td></tr>'; 00118 $r.= ' <tr><td class="generalboxcontent">'; 00119 00120 // If we have found wrong defaults inform about them 00121 if (count($wrong_fields)) { 00122 $r.= ' <p class="centerpara">' . $this->str['yeswrongoraclesemanticsfound'] . '</p>'; 00123 $r.= ' <ul>'; 00124 foreach ($wrong_fields as $obj) { 00125 $xmldb_table = $obj->table; 00126 $xmldb_field = $obj->field; 00127 00128 $r.= ' <li>' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' . 00129 $this->str['field'] . ': ' . $xmldb_field->getName() . ', ' . 00130 $this->str['expected'] . ' ' . "'CHAR'" . ' ' . 00131 $this->str['actual'] . ' ' . "'BYTE'" . '</li>'; 00132 00133 $sql = 'ALTER TABLE ' . $DB->get_prefix() . $xmldb_table->getName() . ' MODIFY ' . 00134 $xmldb_field->getName() . ' VARCHAR2(' . $xmldb_field->getLength() . ' CHAR)'; 00135 $sql = $dbman->generator->getEndedStatements($sql); 00136 $s.= '<code>' . str_replace("\n", '<br />', $sql) . '</code><br />'; 00137 } 00138 $r.= ' </ul>'; 00139 // Add the SQL statements (all together) 00140 $r.= '<hr />' . $s; 00141 } else { 00142 $r.= ' <p class="centerpara">' . $this->str['nowrongoraclesemanticsfound'] . '</p>'; 00143 } 00144 $r.= ' </td></tr>'; 00145 $r.= ' <tr><td class="generalboxcontent">'; 00146 // Add the complete log message 00147 $r.= ' <p class="centerpara">' . $this->str['completelogbelow'] . '</p>'; 00148 $r.= ' </td></tr>'; 00149 $r.= '</table>'; 00150 00151 return $r; 00152 } 00153 }