. /** * @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.= '
'; $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 (