diff --git a/admin/xmldb/actions/check_indexes/check_indexes.class.php b/admin/xmldb/actions/check_indexes/check_indexes.class.php
new file mode 100644
index 00000000000..8ad40b12fd9
--- /dev/null
+++ b/admin/xmldb/actions/check_indexes/check_indexes.class.php
@@ -0,0 +1,267 @@
+loadStrings(array(
+ 'confirmcheckindexes' => 'xmldb',
+ 'ok' => '',
+ 'missing' => 'xmldb',
+ 'table' => 'xmldb',
+ 'key' => 'xmldb',
+ 'index' => 'xmldb',
+ 'searchresults' => 'xmldb',
+ 'missingindexes' => 'xmldb',
+ 'completelogbelow' => 'xmldb',
+ 'nomissingindexesfound' => 'xmldb',
+ 'yesmissingindexesfound' => 'xmldb',
+ 'yes' => '',
+ 'no' => '',
+ 'back' => 'xmldb'
+
+ ));
+ }
+
+ /**
+ * Invoke method, every class will have its own
+ * returns true/false on completion, setting both
+ * errormsg and output as necessary
+ */
+ function invoke() {
+ parent::invoke();
+
+ $result = true;
+
+ /// Set own core attributes
+ $this->does_generate = ACTION_GENERATE_HTML;
+
+ /// These are always here
+ global $CFG, $XMLDB;
+
+ /// And we nedd some ddl suff
+ require_once ($CFG->libdir . '/ddllib.php');
+
+ /// Here we'll acummulate all the missing indexes found
+ $missing_indexes = array();
+
+ /// Do the job, setting $result as needed
+
+ /// Get the confirmed to decide what to do
+ $confirmed = optional_param('confirmed', false, PARAM_BOOL);
+
+ /// If not confirmed, show confirmation box
+ if (!$confirmed) {
+ $o = '
';
+ $o.= ' | ';
+ $o.= ' ' . $this->str['confirmcheckindexes'] . ' ';
+ $o.= ' | ';
+ $o.= ' ';
+ $o.= ' ';
+ $o.= ' | ';
+ $o.= ' ';
+ $o.= ' ';
+ $o.= ' | ';
+ $o.= ' ';
+ $o.= ' |
';
+ $o.= '
';
+
+ $this->output = $o;
+ } else {
+ /// The back to edit table button
+ $b = ' ';
+ $b .= '[' . $this->str['back'] . ']';
+ $b .= '
';
+
+ /// Iterate over $XMLDB->dbdirs, loading their XML data to memory
+ if ($XMLDB->dbdirs) {
+ $dbdirs =& $XMLDB->dbdirs;
+ $o='';
+ foreach ($dbdirs as $dbdir) {
+ /// Only if the directory exists
+ if (!$dbdir->path_exists) {
+ continue;
+ }
+ /// Load the XML file
+ $xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
+ /// Load the needed XMLDB generator
+ $classname = 'XMLDB' . $CFG->dbtype;
+ $generator = new $classname();
+ $generator->setPrefix($CFG->prefix);
+
+ /// Only if the file exists
+ if (!$xmldb_file->fileExists()) {
+ continue;
+ }
+ /// Load the XML contents to structure
+ $loaded = $xmldb_file->loadXMLStructure();
+ if (!$loaded || !$xmldb_file->isLoaded()) {
+ notify('Errors found in XMLDB file: '. $dbdir->path . '/install.xml');
+ continue;
+ }
+ /// Arriving here, everything is ok, get the XMLDB structure
+ $structure = $xmldb_file->getStructure();
+ $o.=' - ' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml');
+ /// Getting tables
+ if ($xmldb_tables = $structure->getTables()) {
+ $o.='
';
+ /// Foreach table, process its indexes and keys
+ foreach ($xmldb_tables as $xmldb_table) {
+ /// Skip table if not exists
+ if (!table_exists($xmldb_table)) {
+ continue;
+ }
+ $o.=' - ' . $xmldb_table->getName();
+ /// Keys
+ if ($xmldb_keys = $xmldb_table->getKeys()) {
+ $o.='
';
+ foreach ($xmldb_keys as $xmldb_key) {
+ $o.=' - ' . $this->str['key'] . ': ' . $xmldb_key->readableInfo() . ' ';
+ /// Primaries are skipped
+ if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) {
+ $o.='' . $this->str['ok'] . '
';
+ continue;
+ }
+ /// If we aren't creating the keys or the key is a XMLDB_KEY_FOREIGN (not underlying index generated
+ /// automatically by the RDBMS) create the underlying (created by us) index (if doesn't exists)
+ if (!$generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) {
+ /// Create the interim index
+ $xmldb_index = new XMLDBIndex('anyname');
+ $xmldb_index->setFields($xmldb_key->getFields());
+ switch ($xmldb_key->getType()) {
+ case XMLDB_KEY_UNIQUE:
+ case XMLDB_KEY_FOREIGN_UNIQUE:
+ $xmldb_index->setUnique(true);
+ break;
+ case XMLDB_KEY_FOREIGN:
+ $xmldb_index->setUnique(false);
+ break;
+ }
+ /// Check if the index exists in DB
+ if (index_exists($xmldb_table, $xmldb_index)) {
+ $o.='' . $this->str['ok'] . '';
+ } else {
+ $o.='' . $this->str['missing'] . '';
+ /// Add the missing index to the list
+ $obj = new object;
+ $obj->table = $xmldb_table;
+ $obj->index = $xmldb_index;
+ $missing_indexes[] = $obj;
+ }
+ }
+ $o.='
';
+ }
+ $o.='
';
+ }
+ /// Indexes
+ if ($xmldb_indexes = $xmldb_table->getIndexes()) {
+ $o.=' ';
+ foreach ($xmldb_indexes as $xmldb_index) {
+ $o.=' - ' . $this->str['index'] . ': ' . $xmldb_index->readableInfo() . ' ';
+ /// Check if the index exists in DB
+ if (index_exists($xmldb_table, $xmldb_index)) {
+ $o.='' . $this->str['ok'] . '';
+ } else {
+ $o.='' . $this->str['missing'] . '';
+ /// Add the missing index to the list
+ $obj = new object;
+ $obj->table = $xmldb_table;
+ $obj->index = $xmldb_index;
+ $missing_indexes[] = $obj;
+ }
+ $o.='
';
+ }
+ $o.='
';
+ }
+ $o.=' ';
+ }
+ $o.='
';
+ }
+ $o.=' ';
+ }
+ $o.='';
+ }
+
+ /// We have finished, let's show the results of the search
+ $r = '';
+ $r.= ' ';
+ $r.= ' ' . $this->str['searchresults'] . '';
+ $r.= ' ' . $this->str['missingindexes'] . ': ' . count($missing_indexes) . ' ';
+ $r.= ' |
';
+ $r.= ' | ';
+
+ /// If we have found missing indexes inform about them
+ if (count($missing_indexes)) {
+ $r.= ' ' . $this->str['yesmissingindexesfound'] . ' ';
+ $r.= ' ';
+ } else {
+ $r.= ' ' . $this->str['nomissingindexesfound'] . ' ';
+ }
+ $r.= ' |
';
+ $r.= ' | ';
+ $r.= ' ' . $this->str['completelogbelow'] . ' ';
+ $r.= ' |
';
+ $r.= '
';
+
+ $this->output = $b . $r . $o;
+ }
+
+ /// Launch postaction if exists (leave this here!)
+ if ($this->getPostAction() && $result) {
+ return $this->launch($this->getPostAction());
+ }
+
+ /// Return ok if arrived here
+ return $result;
+ }
+}
+?>