From 9f5e5dee97837d889f408f2f6eb4a491903d2eda Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 23 Oct 2008 08:30:43 +0000 Subject: [PATCH] xmldb checks: MDL-16975 refactor the various checks to eliminate duplicated code. --- .../xmldb/actions/XMLDBCheckAction.class.php | 206 ++++++++++++ .../check_bigints/check_bigints.class.php | 293 ++++++----------- .../check_defaults/check_defaults.class.php | 290 ++++++----------- .../check_indexes/check_indexes.class.php | 300 ++++++------------ admin/xmldb/index.php | 2 +- 5 files changed, 489 insertions(+), 602 deletions(-) create mode 100644 admin/xmldb/actions/XMLDBCheckAction.class.php diff --git a/admin/xmldb/actions/XMLDBCheckAction.class.php b/admin/xmldb/actions/XMLDBCheckAction.class.php new file mode 100644 index 0000000000..378b678ace --- /dev/null +++ b/admin/xmldb/actions/XMLDBCheckAction.class.php @@ -0,0 +1,206 @@ +loadStrings(array( + $this->introstr => 'xmldb', + 'ok' => '', + 'wrong' => 'xmldb', + 'table' => 'xmldb', + 'field' => 'xmldb', + 'searchresults' => 'xmldb', + 'completelogbelow' => 'xmldb', + 'yes' => '', + 'no' => '', + 'error' => '', + '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, $DB; + + /// And we nedd some ddl suff + $dbman = $DB->get_manager(); + + /// Here we'll acummulate all the wrong fields found + $problemsfound = 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[$this->introstr] . '

'; + $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=''; + } + + /// Create a report of the problems found. + $r = $this->display_results($problemsfound); + + /// Combine the various bits of output. + $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; + } + + /** + * Do the checks necessary on one particular table. + * + * @param xmldb_table $xmldb_table the table definition from the install.xml file. + * @param array $metacolumns the column information read from the database. + * @return array an array with two elements: First, some additional progress output, + * for example a list (