. /** * @package tool_xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * This class will compare all the indexes found in the XMLDB definitions * with the physical DB implementation, reporting about all the missing * indexes to be created to be 100% ok. * * @package tool_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_indexes extends XMLDBCheckAction { /** * Init method, every subclass will have its own */ function init() { $this->introstr = 'confirmcheckindexes'; parent::init(); // Set own core attributes // Set own custom attributes // Get needed strings $this->loadStrings(array( 'missing' => 'tool_xmldb', 'key' => 'tool_xmldb', 'index' => 'tool_xmldb', 'missingindexes' => 'tool_xmldb', 'nomissingindexesfound' => 'tool_xmldb', 'yesmissingindexesfound' => 'tool_xmldb', )); } protected function check_table(xmldb_table $xmldb_table, array $metacolumns) { global $DB; $dbman = $DB->get_manager(); $o = ''; $missing_indexes = array(); // Keys if ($xmldb_keys = $xmldb_table->getKeys()) { $o.=' '; } // Indexes if ($xmldb_indexes = $xmldb_table->getIndexes()) { $o.=' '; } 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 $r; } }