. /** * @package tool_xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * This class will look for data in the database that violates the foreign * key definitions found in the XMLDB definitions. * * Note that by default, this check does not complain about foreign key * violations from, say, a userid column defined as NOT NULL DEFAULT '0'. * Each 0 in that column will violate the foreign key, but we ignore them. * If you want a strict check performed, then add &strict=1 to the URL. * * @package tool_xmldb * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class check_foreign_keys extends XMLDBCheckAction { /** * Init method, every subclass will have its own */ function init() { $this->introstr = 'confirmcheckforeignkeys'; parent::init(); // Set own core attributes // Set own custom attributes // Get needed strings $this->loadStrings(array( 'key' => 'tool_xmldb', 'violatedforeignkeys' => 'tool_xmldb', 'noviolatedforeignkeysfound' => 'tool_xmldb', 'violatedforeignkeysfound' => 'tool_xmldb', 'violations' => 'tool_xmldb', 'unknowntable' => 'tool_xmldb', 'unknownfield' => 'tool_xmldb', )); } protected function check_table(xmldb_table $xmldb_table, array $metacolumns) { global $DB; $dbman = $DB->get_manager(); $strictchecks = optional_param('strict', false, PARAM_BOOL); $o = ''; $violatedkeys = array(); // Keys if ($xmldb_keys = $xmldb_table->getKeys()) { $o.='
';
$r.= ' ' . $this->str['searchresults'] . ''; $r.= '' . $this->str['violatedforeignkeys'] . ': ' . count($violatedkeys) . ' '; $r.= ' |
';
// If we have found wrong integers inform about them
if (count($violatedkeys)) {
$r.= ' ' . $this->str['violatedforeignkeysfound'] . ' '; $r.= '
' . $this->str['noviolatedforeignkeysfound'] . ' '; } $r.= ' |
';
// Add the complete log message
$r.= ' ' . $this->str['completelogbelow'] . ' '; $r.= ' |