loadStrings(array( 'confirmcheckbigints' => 'xmldb', 'ok' => '', 'wrong' => 'xmldb', 'table' => 'xmldb', 'field' => 'xmldb', 'searchresults' => 'xmldb', 'wrongints' => 'xmldb', 'completelogbelow' => 'xmldb', 'nowrongintsfound' => 'xmldb', 'yeswrongintsfound' => 'xmldb', 'mysqlextracheckbigints' => '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 require_once ($CFG->libdir . '/ddllib.php'); /// Here we'll acummulate all the wrong fields found $wrong_fields = array(); /// Correct fields must be type bigint for MySQL and int8 for PostgreSQL switch ($CFG->dbfamily) { case 'mysql': $correct_type = 'bigint'; break; case 'postgres': $correct_type = 'int8'; break; default: $correct_type = NULL; } /// 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['confirmcheckbigints'] . '

'; if ($CFG->dbfamily == 'mysql') { $o.= '

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

'; } $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=''; } /// We have finished, let's show the results of the search $s = ''; $r = ''; $r.= ' '; $r.= ' '; $r.= ' '; $r.= '
'; $r.= '

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

'; $r.= '

' . $this->str['wrongints'] . ': ' . count($wrong_fields) . '

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

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

'; $r.= '
    '; foreach ($wrong_fields as $obj) { $xmldb_table = $obj->table; $xmldb_field = $obj->field; /// MySQL directly supports this if ($CFG->dbfamily == 'mysql') { $sqlarr = $xmldb_table->getAlterFieldSQL($CFG->dbtype, $CFG->prefix, $xmldb_field, true); /// PostgreSQL (XMLDB implementation) is a bit, er... imperfect. } else if ($CFG->dbfamily == 'postgres') { $sqlarr = array('ALTER TABLE ' . $CFG->prefix . $xmldb_table->getName() . ' ALTER COLUMN ' . $xmldb_field->getName() . ' TYPE BIGINT;'); } $r.= '
  • ' . $this->str['table'] . ': ' . $xmldb_table->getName() . '. ' . $this->str['field'] . ': ' . $xmldb_field->getName() . '
  • '; /// Add to output if we have sentences if ($sqlarr) { $s.= '' . str_replace("\n", '
    ', implode('
    ', $sqlarr)) . '

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

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

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

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

'; $r.= '
'; $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; } } ?>