芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/.trash/cepali/admin/tool/xmldb/actions/XMLDBCheckAction.class.php
. /** * @package tool_xmldb * @copyright 2008 onwards Tim Hunt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * This is a base class for the various actions that interate over all the * tables and check some aspect of their definition. * * @package tool_xmldb * @copyright 2008 onwards Tim Hunt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class XMLDBCheckAction extends XMLDBAction { /** * @var string This string is displayed with a yes/no choice before the report is run. * You must set this to the name of a lang string in xmldb.php before calling init. */ protected $introstr = ''; /** * Init method, every subclass will have its own */ function init() { parent::init(); // Set own core attributes // Set own custom attributes // Get needed strings $this->loadStrings(array( $this->introstr => 'tool_xmldb', 'ok' => '', 'wrong' => 'tool_xmldb', 'table' => 'tool_xmldb', 'field' => 'tool_xmldb', 'searchresults' => 'tool_xmldb', 'completelogbelow' => 'tool_xmldb', 'yes' => '', 'no' => '', 'error' => '', 'back' => 'tool_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, $OUTPUT; // 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.= '
' . $this->str[$this->introstr] . '
'; $o.= '
'; $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='
'; foreach ($dbdirs as $dbdir) { // Only if the directory exists if (!$dbdir->path_exists) { continue; } // Load the XML file $xmldb_file = new xmldb_file($dbdir->path . '/install.xml'); // 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()) { echo $OUTPUT->notification('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 fields foreach ($xmldb_tables as $xmldb_table) { // Skip table if not exists if (!$dbman->table_exists($xmldb_table)) { continue; } // Fetch metadata from physical DB. All the columns info. if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) { // / Skip table if no metacolumns is available for it continue; } // Table processing starts here $o.='
' . $xmldb_table->getName(); // Do the specific check. list($output, $newproblems) = $this->check_table($xmldb_table, $metacolumns); $o.=$output; $problemsfound = array_merge($problemsfound, $newproblems); $o.='
'; // Give the script some more time (resetting to current if exists) if ($currenttl = @ini_get('max_execution_time')) { @ini_set('max_execution_time',$currenttl); } } $o.='
'; } $o.='
'; } $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 (
) of the things check each with an one work ok/not ok summary. * Second, an array giving the details of any problems found. These arrays * for all tables will be aggregated, and then passed to */ abstract protected function check_table(xmldb_table $xmldb_table, array $metacolumns); /** * Display a list of the problems found. * * @param array $problems_found an aggregation of all the problems found by * all the check_table calls. * @return string a display of all the problems found as HTML. */ abstract protected function display_results(array $problems_found); }