From d63375cde59785f51aa0884b081ef03b85099740 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 8 Jul 2007 23:24:49 +0000 Subject: [PATCH] First cut of the utility embeded in the XMLDB Editor used to check any Moodle server looking for missing indexes. Tested under MySQL, PostgreSQL and MSSQL. No frontend available until tested for Oracle. MDL-7357 Merged from MOODLE_18_STABLE --- .../check_indexes/check_indexes.class.php | 267 ++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 admin/xmldb/actions/check_indexes/check_indexes.class.php 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 0000000000..8ad40b12fd --- /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.= '
'; + $o.= '

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

'; + $o.= ' '; + $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=''; + } + + /// We have finished, let's show the results of the search + $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 = $xmldb_table->getAddIndexSQL($CFG->dbtype, $CFG->prefix, $xmldb_index, false); + $r.= '
  • ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' . + $this->str['index'] . ': ' . $xmldb_index->readableInfo() . '
    ' . + '

    ' . implode('
    ', $sqlarr) . '

  • '; + + } + $r.= '
'; + } else { + $r.= '

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

'; + } + $r.= '
'; + $r.= '

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

'; + $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; + } +} +?> -- 2.39.5