. /** * @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 */ defined('MOODLE_INTERNAL') || die(); /** * This class will check all the default values existing in the DB * match those specified in the xml specs * and providing one SQL script to fix all them. * * @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_defaults extends XMLDBCheckAction { /** * Init method, every subclass will have its own */ public function init() { $this->introstr = 'confirmcheckdefaults'; parent::init(); // Set own core attributes. // Set own custom attributes. // Get needed strings. $this->loadStrings(array( 'wrongdefaults' => 'tool_xmldb', 'nowrongdefaultsfound' => 'tool_xmldb', 'yeswrongdefaultsfound' => 'tool_xmldb', 'expected' => 'tool_xmldb', 'actual' => 'tool_xmldb', )); } protected function check_table(xmldb_table $xmldbtable, array $metacolumns) { $o = ''; $wrongfields = array(); // Get and process XMLDB fields. if ($xmldbfields = $xmldbtable->getFields()) { $o .= ' '; } return array($o, $wrongfields); } /** * Converts a default value suitable for display. * * @param string|null $defaultvalue Default value * @return string Displayed version */ protected static function display_default($defaultvalue) { if ($defaultvalue === null) { return '-'; } else { return "'" . s($defaultvalue) . "'"; } } protected function display_results(array $wrongfields) { global $DB; $dbman = $DB->get_manager(); $s = ''; $r = ''; $r .= ' '; $r .= ' '; $r .= ' '; $r .= '
'; $r .= '

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

'; $r .= '

' . $this->str['wrongdefaults'] . ': ' . count($wrongfields) . '

'; $r .= '
'; // If we have found wrong defaults inform about them. if (count($wrongfields)) { $r .= '

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

'; $r .= '
    '; foreach ($wrongfields as $obj) { $xmldbtable = $obj->table; $xmldbfield = $obj->field; $physicaltext = self::display_default($obj->physicaldefault); $xmldbtext = self::display_default($obj->xmldbdefault); // Get the alter table command. $sqlarr = $dbman->generator->getAlterFieldSQL($xmldbtable, $xmldbfield); $r .= '
  • ' . $this->str['table'] . ': ' . $xmldbtable->getName() . '. ' . $this->str['field'] . ': ' . $xmldbfield->getName() . ', ' . $this->str['expected'] . ' ' . $xmldbtext . ' ' . $this->str['actual'] . ' ' . $physicaltext . '
  • '; // Add to output if we have sentences. if ($sqlarr) { $sqlarr = $dbman->generator->getEndedStatements($sqlarr); $s .= '' . str_replace("\n", '
    ', implode('
    ', $sqlarr)) . '

    '; } } $r .= '
'; // Add the SQL statements (all together). $r .= '
' . $s; } else { $r .= '

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

'; } $r .= '
'; // Add the complete log message. $r .= '

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

'; $r .= '
'; return $r; } }