Beispiel #1
0
 /**
  * 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_NONE;
     //$this->does_generate = ACTION_GENERATE_HTML;
     // These are always here
     global $CFG, $XMLDB;
     // Do the job, setting result as needed
     // Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . $dirpath;
     // Get the correct dirs
     if (!empty($XMLDB->dbdirs)) {
         $dbdir = $XMLDB->dbdirs[$dirpath];
     } else {
         return false;
     }
     if (!empty($XMLDB->editeddirs)) {
         $editeddir = $XMLDB->editeddirs[$dirpath];
         $structure = $editeddir->xml_file->getStructure();
     }
     // If the changeme table exists, just get it and continue
     $changeme_exists = false;
     if ($tables = $structure->getTables()) {
         if ($table = $structure->getTable('changeme')) {
             $changeme_exists = true;
         }
     }
     if (!$changeme_exists) {
         // Lets create the table
         $field = new xmldb_field('id');
         $field->setType(XMLDB_TYPE_INTEGER);
         $field->setLength(10);
         $field->setNotNull(true);
         $field->setSequence(true);
         $field->setLoaded(true);
         $field->setChanged(true);
         $key = new xmldb_key('primary');
         $key->setType(XMLDB_KEY_PRIMARY);
         $key->setFields(array('id'));
         $key->setLoaded(true);
         $key->setChanged(true);
         $table = new xmldb_table('changeme');
         $table->setComment('Default comment for the table, please edit me');
         $table->addField($field);
         $table->addKey($key);
         // Finally, add the whole retrofitted table to the structure
         // in the place specified
         $structure->addTable($table);
     }
     // Launch postaction if exists (leave this here!)
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     // Return ok if arrived here
     return $result;
 }
/**
 * @global moodle_database $DB
 * @param int $oldversion
 * @return bool
 */
function xmldb_plagiarism_vericite_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2015021000) {
        $table = new xmldb_table('plagiarism_vericite_files');
        $field1 = new xmldb_field('data', XMLDB_TYPE_TEXT, 'long', null, null, null, null, 'timeretrieved');
        $field2 = new xmldb_field('status', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, null, 'data');
        $field3 = new xmldb_field('attempts', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, 'status');
        if (!$dbman->field_exists($table, $field1)) {
            $dbman->add_field($table, $field1);
        }
        if (!$dbman->field_exists($table, $field2)) {
            $dbman->add_field($table, $field2);
        }
        if (!$dbman->field_exists($table, $field3)) {
            $dbman->add_field($table, $field3);
        }
        upgrade_plugin_savepoint(true, 2015021000, 'plagiarism', 'vericite');
    }
    if ($oldversion < 2015021202) {
        $table = new xmldb_table('plagiarism_vericite_score');
        if (!$dbman->table_exists($table)) {
            $field1 = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
            $field2 = new xmldb_field('cm', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
            $field3 = new xmldb_field('timeretrieved', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'cm');
            $key1 = new xmldb_key('primary');
            $key1->set_attributes(XMLDB_KEY_PRIMARY, array('id'), null, null);
            $key2 = new xmldb_key('cm');
            $key2->set_attributes(XMLDB_KEY_FOREIGN, array('cm'), 'course_modules', array('cm'));
            $table->addField($field1);
            $table->addField($field2);
            $table->addField($field3);
            $table->addKey($key1);
            $table->addKey($key2);
            $dbman->create_table($table);
        }
        upgrade_plugin_savepoint(true, 2015021202, 'plagiarism', 'vericite');
    }
    if ($oldversion < 2015021300) {
        //Nothing to update
        upgrade_plugin_savepoint(true, 2015021300, 'plagiarism', 'vericite');
    }
    return true;
}
 /**
  * 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;
     // Do the job, setting result as needed
     // Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . $dirpath;
     // Get the correct dirs
     if (!empty($XMLDB->dbdirs)) {
         $dbdir = $XMLDB->dbdirs[$dirpath];
     } else {
         return false;
     }
     if (!empty($XMLDB->editeddirs)) {
         $editeddir = $XMLDB->editeddirs[$dirpath];
         $structure = $editeddir->xml_file->getStructure();
     }
     $tableparam = optional_param('table', NULL, PARAM_CLEAN);
     // If no table, show form
     if (!$tableparam) {
         // No postaction here
         $this->postaction = NULL;
         // Get list of tables
         $dbtables = $DB->get_tables();
         $selecttables = array();
         foreach ($dbtables as $dbtable) {
             $i = $structure->findTableInArray($dbtable);
             if ($i === NULL) {
                 $selecttables[$dbtable] = $dbtable;
             }
         }
         // Get list of after tables
         $aftertables = array();
         if ($tables = $structure->getTables()) {
             foreach ($tables as $aftertable) {
                 $aftertables[$aftertable->getName()] = $aftertable->getName();
             }
         }
         if (!$selecttables) {
             $this->errormsg = 'No tables available to be retrofitted';
             return false;
         }
         // Now build the form
         $o = '<form id="form" action="index.php" method="post">';
         $o .= '<div>';
         $o .= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
         $o .= '    <input type="hidden" name ="action" value="new_table_from_mysql" />';
         $o .= '    <input type="hidden" name ="postaction" value="edit_table" />';
         $o .= '    <input type="hidden" name ="sesskey" value="' . sesskey() . '" />';
         $o .= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
         $o .= '      <tr><td><label for="menutable" accesskey="t">' . $this->str['createtable'] . ' </label>' . html_writer::select($selecttables, 'table') . '<label for="menuafter" accesskey="a">' . $this->str['aftertable'] . ' </label>' . html_writer::select($aftertables, 'after') . '</td></tr>';
         $o .= '      <tr><td colspan="2" align="center"><input type="submit" value="' . $this->str['create'] . '" /></td></tr>';
         $o .= '      <tr><td colspan="2" align="center"><a href="index.php?action=edit_xml_file&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a></td></tr>';
         $o .= '    </table>';
         $o .= '</div></form>';
         $this->output = $o;
         // If table, retrofit information and, if everything works,
         // go to the table edit action
     } else {
         // Get some params (table is mandatory here)
         $tableparam = required_param('table', PARAM_CLEAN);
         $afterparam = required_param('after', PARAM_CLEAN);
         // Create one new xmldb_table
         $table = new xmldb_table(strtolower(trim($tableparam)));
         $table->setComment($table->getName() . ' table retrofitted from MySQL');
         // Get fields info from ADODb
         $dbfields = $DB->get_columns($tableparam);
         if ($dbfields) {
             foreach ($dbfields as $dbfield) {
                 // Create new XMLDB field
                 $field = new xmldb_field($dbfield->name);
                 // Set field with info retrofitted
                 $field->setFromADOField($dbfield);
                 // Add field to the table
                 $table->addField($field);
             }
         }
         // Get PK, UK and indexes info from ADODb
         $dbindexes = $DB->get_indexes($tableparam);
         if ($dbindexes) {
             $lastkey = NULL;
             //To temp store the last key processed
             foreach ($dbindexes as $indexname => $dbindex) {
                 // Add the indexname to the array
                 $dbindex['name'] = $indexname;
                 // We are handling one xmldb_key (primaries + uniques)
                 if ($dbindex['unique']) {
                     $key = new xmldb_key(strtolower($dbindex['name']));
                     // Set key with info retrofitted
                     $key->setFromADOKey($dbindex);
                     // Set default comment to PKs
                     if ($key->getType() == XMLDB_KEY_PRIMARY) {
                     }
                     // Add key to the table
                     $table->addKey($key);
                     // We are handling one xmldb_index (non-uniques)
                 } else {
                     $index = new xmldb_index(strtolower($dbindex['name']));
                     // Set index with info retrofitted
                     $index->setFromADOIndex($dbindex);
                     // Add index to the table
                     $table->addIndex($index);
                 }
             }
         }
         // Finally, add the whole retroffited table to the structure
         // in the place specified
         $structure->addTable($table, $afterparam);
     }
     // Launch postaction if exists (leave this here!)
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     // Return ok if arrived here
     return $result;
 }
Beispiel #4
0
 /**
  * Load data from XML to the table
  */
 function arr2xmldb_table($xmlarr)
 {
     global $CFG;
     $result = true;
     /// Debug the table
     /// traverse_xmlize($xmlarr);                   //Debug
     /// print_object ($GLOBALS['traverse_array']);  //Debug
     /// $GLOBALS['traverse_array']="";              //Debug
     /// Process table attributes (name, comment, previoustable and nexttable)
     if (isset($xmlarr['@']['NAME'])) {
         $this->name = trim($xmlarr['@']['NAME']);
     } else {
         $this->errormsg = 'Missing NAME attribute';
         $this->debug($this->errormsg);
         $result = false;
     }
     if (isset($xmlarr['@']['COMMENT'])) {
         $this->comment = trim($xmlarr['@']['COMMENT']);
     } else {
         if (!empty($CFG->xmldbdisablecommentchecking)) {
             $this->comment = '';
         } else {
             $this->errormsg = 'Missing COMMENT attribute';
             $this->debug($this->errormsg);
             $result = false;
         }
     }
     if (isset($xmlarr['@']['PREVIOUS'])) {
         $this->previous = trim($xmlarr['@']['PREVIOUS']);
     }
     if (isset($xmlarr['@']['NEXT'])) {
         $this->next = trim($xmlarr['@']['NEXT']);
     }
     /// Iterate over fields
     if (isset($xmlarr['#']['FIELDS']['0']['#']['FIELD'])) {
         foreach ($xmlarr['#']['FIELDS']['0']['#']['FIELD'] as $xmlfield) {
             if (!$result) {
                 //Skip on error
                 continue;
             }
             $name = trim($xmlfield['@']['NAME']);
             $field = new xmldb_field($name);
             $field->arr2xmldb_field($xmlfield);
             $this->fields[] = $field;
             if (!$field->isLoaded()) {
                 $this->errormsg = 'Problem loading field ' . $name;
                 $this->debug($this->errormsg);
                 $result = false;
             }
         }
     } else {
         $this->errormsg = 'Missing FIELDS section';
         $this->debug($this->errormsg);
         $result = false;
     }
     /// Perform some general checks over fields
     if ($result && $this->fields) {
         /// Check field names are ok (lowercase, a-z _-)
         if (!$this->checkNameValues($this->fields)) {
             $this->errormsg = 'Some FIELDS name values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Check previous & next are ok (duplicates and existing fields)
         $this->fixPrevNext($this->fields);
         if ($result && !$this->checkPreviousNextValues($this->fields)) {
             $this->errormsg = 'Some FIELDS previous/next values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Order fields
         if ($result && !$this->orderFields($this->fields)) {
             $this->errormsg = 'Error ordering the fields';
             $this->debug($this->errormsg);
             $result = false;
         }
     }
     /// Iterate over keys
     if (isset($xmlarr['#']['KEYS']['0']['#']['KEY'])) {
         foreach ($xmlarr['#']['KEYS']['0']['#']['KEY'] as $xmlkey) {
             if (!$result) {
                 //Skip on error
                 continue;
             }
             $name = trim($xmlkey['@']['NAME']);
             $key = new xmldb_key($name);
             $key->arr2xmldb_key($xmlkey);
             $this->keys[] = $key;
             if (!$key->isLoaded()) {
                 $this->errormsg = 'Problem loading key ' . $name;
                 $this->debug($this->errormsg);
                 $result = false;
             }
         }
     } else {
         $this->errormsg = 'Missing KEYS section (at least one PK must exist)';
         $this->debug($this->errormsg);
         $result = false;
     }
     /// Perform some general checks over keys
     if ($result && $this->keys) {
         /// Check keys names are ok (lowercase, a-z _-)
         if (!$this->checkNameValues($this->keys)) {
             $this->errormsg = 'Some KEYS name values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Check previous & next are ok (duplicates and existing keys)
         $this->fixPrevNext($this->keys);
         if ($result && !$this->checkPreviousNextValues($this->keys)) {
             $this->errormsg = 'Some KEYS previous/next values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Order keys
         if ($result && !$this->orderKeys($this->keys)) {
             $this->errormsg = 'Error ordering the keys';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// TODO: Only one PK
         /// TODO: Not keys with repeated fields
         /// TODO: Check fields and reffieds exist in table
     }
     /// Iterate over indexes
     if (isset($xmlarr['#']['INDEXES']['0']['#']['INDEX'])) {
         foreach ($xmlarr['#']['INDEXES']['0']['#']['INDEX'] as $xmlindex) {
             if (!$result) {
                 //Skip on error
                 continue;
             }
             $name = trim($xmlindex['@']['NAME']);
             $index = new xmldb_index($name);
             $index->arr2xmldb_index($xmlindex);
             $this->indexes[] = $index;
             if (!$index->isLoaded()) {
                 $this->errormsg = 'Problem loading index ' . $name;
                 $this->debug($this->errormsg);
                 $result = false;
             }
         }
     }
     /// Perform some general checks over indexes
     if ($result && $this->indexes) {
         /// Check field names are ok (lowercase, a-z _-)
         if (!$this->checkNameValues($this->indexes)) {
             $this->errormsg = 'Some INDEXES name values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Check previous & next are ok (duplicates and existing INDEXES)
         $this->fixPrevNext($this->indexes);
         if ($result && !$this->checkPreviousNextValues($this->indexes)) {
             $this->errormsg = 'Some INDEXES previous/next values are incorrect';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// Order indexes
         if ($result && !$this->orderIndexes($this->indexes)) {
             $this->errormsg = 'Error ordering the indexes';
             $this->debug($this->errormsg);
             $result = false;
         }
         /// TODO: Not indexes with repeated fields
         /// TODO: Check fields exist in table
     }
     /// Set some attributes
     if ($result) {
         $this->loaded = true;
     }
     $this->calculateHash();
     return $result;
 }
Beispiel #5
0
 /**
  * Given one correct xmldb_key, returns its specs.
  *
  * @param xmldb_table $xmldb_table The table related to $xmldb_key.
  * @param xmldb_key $xmldb_key The xmldb_key's specifications requested.
  * @return string SQL statement about the xmldb_key.
  */
 public function getKeySQL($xmldb_table, $xmldb_key)
 {
     $key = '';
     switch ($xmldb_key->getType()) {
         case XMLDB_KEY_PRIMARY:
             if ($this->primary_keys) {
                 if ($this->primary_key_name !== null) {
                     $key = $this->getEncQuoted($this->primary_key_name);
                 } else {
                     $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'pk');
                 }
                 $key .= ' PRIMARY KEY (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')';
             }
             break;
         case XMLDB_KEY_UNIQUE:
             if ($this->unique_keys) {
                 $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'uk');
                 $key .= ' UNIQUE (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')';
             }
             break;
         case XMLDB_KEY_FOREIGN:
         case XMLDB_KEY_FOREIGN_UNIQUE:
             if ($this->foreign_keys) {
                 $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'fk');
                 $key .= ' FOREIGN KEY (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')';
                 $key .= ' REFERENCES ' . $this->getEncQuoted($this->prefix . $xmldb_key->getRefTable());
                 $key .= ' (' . implode(', ', $this->getEncQuoted($xmldb_key->getRefFields())) . ')';
             }
             break;
     }
     return $key;
 }
Beispiel #6
0
 public function testDropForeignKey()
 {
     $dbman = $this->tdb->get_manager();
     $table = $this->create_deftable('test_table1');
     $this->create_deftable('test_table0');
     $key = new xmldb_key('course');
     $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'test_table0', array('id'));
     $dbman->add_key($table, $key);
     $dbman->drop_key($table, $key);
 }
 public function testDropForeignKey()
 {
     $dbman = $this->tdb->get_manager();
     $table = $this->create_deftable('test_table1');
     $this->create_deftable('test_table0');
     $key = new xmldb_key('course');
     $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'test_table0', array('id'));
     $dbman->add_key($table, $key);
     $dbman->drop_key($table, $key);
     // No easy way to test it, this just makes sure no errors are encountered.
     $this->assertTrue(true);
 }
Beispiel #8
0
function xmldb_block_quickmail_upgrade($oldversion)
{
    global $DB;
    $result = true;
    $dbman = $DB->get_manager();
    // 1.9 to 2.0 upgrade
    if ($oldversion < 2011021812) {
        // Changing type of field attachment on table block_quickmail_log to text
        $table = new xmldb_table('block_quickmail_log');
        $field = new xmldb_field('attachment', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'message');
        // Launch change of type for field attachment
        $dbman->change_field_type($table, $field);
        // Rename field timesent on table block_quickmail_log to time
        $table = new xmldb_table('block_quickmail_log');
        $field = new xmldb_field('timesent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'format');
        // Conditionally launch rename field timesent
        if ($dbman->field_exists($table, $field)) {
            $dbman->rename_field($table, $field, 'time');
        }
        // Define table block_quickmail_signatures to be created
        $table = new xmldb_table('block_quickmail_signatures');
        // Adding fields to table block_quickmail_signatures
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('title', XMLDB_TYPE_CHAR, '125', null, null, null, null);
        $table->add_field('signature', XMLDB_TYPE_TEXT, 'medium', null, null, null, null);
        $table->add_field('default_flag', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
        // Adding keys to table block_quickmail_signatures
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_quickmail_signatures
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table block_quickmail_drafts to be created
        $table = new xmldb_table('block_quickmail_drafts');
        // Adding fields to table block_quickmail_drafts
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('mailto', XMLDB_TYPE_TEXT, 'medium', null, null, null, null);
        $table->add_field('subject', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
        $table->add_field('message', XMLDB_TYPE_TEXT, 'medium', null, null, null, null);
        $table->add_field('attachment', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
        $table->add_field('format', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
        $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
        // Adding keys to table block_quickmail_drafts
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_quickmail_drafts
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table block_quickmail_config to be created
        $table = new xmldb_table('block_quickmail_config');
        // Adding fields to table block_quickmail_config
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('coursesid', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null);
        $table->add_field('value', XMLDB_TYPE_CHAR, '125', null, null, null, null);
        // Adding keys to table block_quickmail_config
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_quickmail_config
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // quickmail savepoint reached
        upgrade_block_savepoint($result, 2011021812, 'quickmail');
    }
    if ($oldversion < 2012021014) {
        $table = new xmldb_table('block_quickmail_alternate');
        $field = new xmldb_field('id');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
        $table->addField($field);
        $field = new xmldb_field('courseid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, 'id');
        $table->addField($field);
        $field = new xmldb_field('address');
        $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, false, null, 'courseid');
        $table->addField($field);
        $field = new xmldb_field('valid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', 'address');
        $table->addField($field);
        $key = new xmldb_key('PRIMARY');
        $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
        $table->addKey($key);
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        foreach (array('log', 'drafts') as $table) {
            // Define field alternateid to be added to block_quickmail_log
            $table = new xmldb_table('block_quickmail_' . $table);
            $field = new xmldb_field('alternateid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'userid');
            // Conditionally launch add field alternateid
            if (!$dbman->field_exists($table, $field)) {
                $dbman->add_field($table, $field);
            }
        }
        // quickmail savepoint reached
        upgrade_block_savepoint($result, 2012021014, 'quickmail');
    }
    if ($oldversion < 2012061112) {
        // Restructure database references to the new filearea locations
        foreach (array('log', 'drafts') as $type) {
            $params = array('component' => 'block_quickmail_' . $type, 'filearea' => 'attachment');
            $attachments = $DB->get_records('files', $params);
            foreach ($attachments as $attachment) {
                $attachment->filearea = 'attachment_' . $type;
                $attachment->component = 'block_quickmail';
                $result = $result && $DB->update_record('files', $attachment);
            }
        }
        upgrade_block_savepoint($result, 2012061112, 'quickmail');
    }
    if ($oldversion < 2012061112) {
        migrate_quickmail_20();
    }
    if ($oldversion < 2014042914) {
        // Define field status to be dropped from block_quickmail_log.
        $table = new xmldb_table('block_quickmail_log');
        $field = new xmldb_field('status');
        // Conditionally launch drop field status.
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }
        // Define field status to be added to block_quickmail_log.
        $table = new xmldb_table('block_quickmail_log');
        $field = new xmldb_field('failuserids', XMLDB_TYPE_TEXT, null, null, null, null, null, 'time');
        $field2 = new xmldb_field('additional_emails', XMLDB_TYPE_TEXT, null, null, null, null, null, 'failuserids');
        // Conditionally launch add field status.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        if (!$dbman->field_exists($table, $field2)) {
            $dbman->add_field($table, $field2);
        }
        // Define field additional_emails to be added to block_quickmail_drafts.
        $table = new xmldb_table('block_quickmail_drafts');
        $field = new xmldb_field('additional_emails', XMLDB_TYPE_TEXT, null, null, null, null, null, 'time');
        // Conditionally launch add field additional_emails.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Quickmail savepoint reached.
        upgrade_block_savepoint(true, 2014042914, 'quickmail');
    }
    return $result;
}
Beispiel #9
0
function xmldb_block_email_list_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $DB;
    $dbman = $DB->get_manager();
    /// loads ddl manager and xmldb classes
    $result = true;
    // If is set upgrade_blocks_savepoint function
    $existfunction = false;
    if (!function_exists('upgrade_blocks_savepoint')) {
        $existfunction = true;
    }
    /// And upgrade begins here. For each one, you'll need one
    /// block of code similar to the next one. Please, delete
    /// this comment lines once this file start handling proper
    /// upgrade code.
    if ($result && $oldversion < 2007062205) {
        $fields = array('mod/email:viewmail', 'mod/email:addmail', 'mod/email:reply', 'mod/email:replyall', 'mod/email:forward', 'mod/email:addsubfolder', 'mod/email:updatesubfolder', 'mod/email:removesubfolder');
        /// Remove no more used fields
        $table = new xmldb_table('capabilities');
        foreach ($fields as $name) {
            $field = new xmldb_field($name);
            $result = $result && $dbman->drop_field($table, $field);
        }
        // Active cron block of email_list
        if ($result) {
            if ($email_list = $DB->get_record('block', array('name' => 'email_list'))) {
                $email_list->cron = 1;
                update_record('block', $email_list);
            }
        }
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2007062205, 'email_list');
        }
    }
    // force
    $result = true;
    if ($result && $oldversion < 2007072003) {
        // Add marriedfolder2courses flag on email_preferences
        $table = new xmldb_table('email_preference');
        $field = new xmldb_field('marriedfolders2courses');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $result = $result && $dbman->add_field($table, $field);
        // Add course ID on email_folder
        $table = new xmldb_table('email_folder');
        $field = new xmldb_field('course');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $result = $result && $dbman->add_field($table, $field);
        // Add index
        $key = new xmldb_key('course');
        $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'course', array('id'));
        $result = $result && $dbman->add_key($table, $key);
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2007072003, 'email_list');
        }
    }
    if ($result && $oldversion < 2008061400) {
        // Add reply and forwarded info field on email_mail.
        $table = new xmldb_table('email_send');
        $field = new xmldb_field('answered');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $result = $result && $dbman->add_field($table, $field);
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2008061400, 'email_list');
        }
    }
    // Solve old problems
    if ($result && $oldversion < 2008061600) {
        $table = new xmldb_table('email_preference');
        $field = new xmldb_field('marriedfolders2courses');
        if (!$dbman->field_exists($table, $field)) {
            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
            $result = $result && $dbman->add_field($table, $field);
        }
        $table = new xmldb_table('email_folder');
        $field = new xmldb_field('course');
        if (!$dbman->field_exists($table, $field)) {
            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
            $result = $result && $dbman->add_field($table, $field);
            // Add index
            $key = new xmldb_key('course');
            $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'course', array('id'));
            $result = $result && $dbman->add_key($table, $key);
        }
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2008061600, 'email_list');
        }
    }
    // Add new index
    if ($result and $oldversion < 2008081602) {
        // Add combine key on foldermail
        $table = new xmldb_table('email_foldermail');
        $index = new xmldb_index('folderid-mailid');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('folderid', 'mailid'));
        if (!$dbman->index_exists($table, $index)) {
            /// Launch add index
            $result = $result && $dbman->add_index($table, $index);
        }
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2008081602, 'email_list');
        }
    }
    // Upgrading to Moodle 2.0
    if ($result and $oldversion < 2009040200) {
        // Portable SQL staments to Oracle, MySQL and PostgreSQL NOT APPLYCABLE to MSSQL
        if ($CFG->dbname != 'mssql') {
            // Moodle 1.9 or prior
            if ($CFG->version < '2009011541') {
                // Filter
                $result = $DB->execute_sql("ALTER TABLE {email_filter} RENAME TO {block_email_list_filter}");
                // Folder
                $result = $DB->execute_sql("ALTER TABLE {email_folder} RENAME TO {block_email_list_folder}") && $result;
                // Foldermail
                $result = $DB->execute_sql("ALTER TABLE {email_foldermail} RENAME TO {block_email_list_foldermail}") && $result;
                // Mail
                $result = $DB->execute_sql("ALTER TABLE {email_mail} RENAME TO {block_email_list_mail}") && $result;
                // Preference
                $result = $DB->execute_sql("ALTER TABLE {email_preference} RENAME TO {block_email_list_preference}") && $result;
                // Send
                $result = $DB->execute_sql("ALTER TABLE {email_send} RENAME TO {block_email_list_send}") && $result;
                // Subfolder
                $result = $DB->execute_sql("ALTER TABLE {email_subfolder} RENAME TO {block_email_list_subfolder}") && $result;
            } else {
                // Filter
                $DB->execute("ALTER TABLE {email_filter} RENAME TO {block_email_list_filter}");
                // Folder
                $DB->execute("ALTER TABLE {email_folder} RENAME TO {block_email_list_folder}");
                // Foldermail
                $DB->execute("ALTER TABLE {email_foldermail} RENAME TO {block_email_list_foldermail}");
                // Mail
                $DB->execute("ALTER TABLE {email_mail} RENAME TO {block_email_list_mail}");
                // Preference
                $DB->execute("ALTER TABLE {email_preference} RENAME TO {block_email_list_preference}");
                // Send
                $DB->execute("ALTER TABLE {email_send} RENAME TO {block_email_list_send}");
                // Subfolder
                $DB->execute("ALTER TABLE {email_subfolder} RENAME TO {block_email_list_subfolder}");
            }
        }
        // Change module name to Standard eMail name.
        if ($logs = $DB->get_records('log_display', array('module' => 'email'))) {
            foreach ($logs as $log) {
                $DB->set_field('log_display', array('module' => 'block_email_list'), array('id' => $log->id));
            }
        }
        // Only compatible with 1.9 or prior versions
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2009040200, 'block_email_list');
        }
    }
    // Add field respondedid into block_email_list_mail table because, if one mail has replied, know this parent.
    if ($result and $oldversion < 2010021400) {
        $table = new xmldb_table('block_email_list_mail');
        $field = new xmldb_field('respondedid');
        if (!$dbman->field_exists($table, $field)) {
            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
            $result = $result && $dbman->add_field($table, $field);
        }
        // Only compatible with 1.9 or prior versions
        if ($existfunction) {
            /// Block savepoint reached
            upgrade_blocks_savepoint($result, 2010021400, 'block_email_list');
        }
    }
    return $result;
}
 /**
  * This function will drop the key in the table passed as arguments
  *
  * @param xmldb_table $xmldb_table Table object (just the name is mandatory).
  * @param xmldb_key $xmldb_key Key object (full specs are required).
  * @return void
  */
 public function drop_key(xmldb_table $xmldb_table, xmldb_key $xmldb_key)
 {
     if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) {
         // Prevent PRIMARY to be dropped (only in drop table, being serious  :-P)
         throw new ddl_exception('ddlunknownerror', null, 'Primary Keys can be deleted at table drop time only');
     }
     if (!($sqlarr = $this->generator->getDropKeySQL($xmldb_table, $xmldb_key))) {
         return;
         //Empty array = nothing to do = no error
     }
     $this->execute_sql_arr($sqlarr);
 }
Beispiel #11
0
 function __construct($name)
 {
     parent::__construct($name);
 }
 /**
  * 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_NONE;
     $this->does_generate = ACTION_GENERATE_HTML;
     /// These are always here
     global $CFG, $XMLDB;
     /// Do the job, setting result as needed
     if (!data_submitted()) {
         ///Basic prevention
         print_error('wrongcall', 'error');
     }
     /// Get parameters
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . $dirpath;
     $tableparam = strtolower(required_param('table', PARAM_PATH));
     $keyparam = strtolower(required_param('key', PARAM_PATH));
     $name = trim(strtolower(optional_param('name', $keyparam, PARAM_PATH)));
     $comment = required_param('comment', PARAM_CLEAN);
     $comment = trim($comment);
     $type = required_param('type', PARAM_INT);
     $fields = required_param('fields', PARAM_CLEAN);
     $fields = str_replace(' ', '', trim(strtolower($fields)));
     if ($type == XMLDB_KEY_FOREIGN || $type == XMLDB_KEY_FOREIGN_UNIQUE) {
         $reftable = trim(strtolower(required_param('reftable', PARAM_PATH)));
         $reffields = required_param('reffields', PARAM_CLEAN);
         $reffields = str_replace(' ', '', trim(strtolower($reffields)));
     }
     $editeddir =& $XMLDB->editeddirs[$dirpath];
     $structure =& $editeddir->xml_file->getStructure();
     $table =& $structure->getTable($tableparam);
     $key =& $table->getKey($keyparam);
     $oldhash = $key->getHash();
     $errors = array();
     /// To store all the errors found
     /// Perform some checks
     /// Check empty name
     if (empty($name)) {
         $errors[] = $this->str['keynameempty'];
     }
     /// Check incorrect name
     if ($name == 'changeme') {
         $errors[] = $this->str['incorrectkeyname'];
     }
     /// Check duplicate name
     if ($keyparam != $name && $table->getKey($name)) {
         $errors[] = $this->str['duplicatekeyname'];
     }
     $fieldsarr = explode(',', $fields);
     /// Check the fields isn't empty
     if (empty($fieldsarr[0])) {
         $errors[] = $this->str['nofieldsspecified'];
     } else {
         /// Check that there aren't duplicate column names
         $uniquearr = array_unique($fieldsarr);
         if (count($fieldsarr) != count($uniquearr)) {
             $errors[] = $this->str['duplicatefieldsused'];
         }
         /// Check that all the fields in belong to the table
         foreach ($fieldsarr as $field) {
             if (!$table->getField($field)) {
                 $errors[] = $this->str['fieldsnotintable'];
                 break;
             }
         }
         /// If primary, check that all the fields are not null
         if ($type == XMLDB_KEY_PRIMARY) {
             foreach ($fieldsarr as $field) {
                 if ($fi = $table->getField($field)) {
                     if (!$fi->getNotNull()) {
                         $errors[] = $this->str['primarykeyonlyallownotnullfields'];
                         break;
                     }
                 }
             }
         }
         /// Check that there isn't any key using exactly the same fields
         $tablekeys = $table->getKeys();
         if ($tablekeys) {
             foreach ($tablekeys as $tablekey) {
                 /// Skip checking against itself
                 if ($keyparam == $tablekey->getName()) {
                     continue;
                 }
                 $keyfieldsarr = $tablekey->getFields();
                 /// Compare both arrays, looking for diferences
                 $diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
                 if (empty($diferences)) {
                     $errors[] = $this->str['fieldsusedinkey'];
                     break;
                 }
             }
         }
         /// Check that there isn't any index using exactlt the same fields
         $tableindexes = $table->getIndexes();
         if ($tableindexes) {
             foreach ($tableindexes as $tableindex) {
                 $indexfieldsarr = $tableindex->getFields();
                 /// Compare both arrays, looking for diferences
                 $diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
                 if (empty($diferences)) {
                     $errors[] = $this->str['fieldsusedinindex'];
                     break;
                 }
             }
         }
         /// If foreign key
         if ($type == XMLDB_KEY_FOREIGN || $type == XMLDB_KEY_FOREIGN_UNIQUE) {
             $reffieldsarr = explode(',', $reffields);
             /// Check reftable is not empty
             if (empty($reftable)) {
                 $errors[] = $this->str['noreftablespecified'];
             } else {
                 /// Check reffields are not empty
                 if (empty($reffieldsarr[0])) {
                     $errors[] = $this->str['noreffieldsspecified'];
                 } else {
                     /// Check the number of fields is correct
                     if (count($fieldsarr) != count($reffieldsarr)) {
                         $errors[] = $this->str['wrongnumberofreffields'];
                     } else {
                         /// Check, if pointing to one structure table, that there is one master key for this key
                         if ($rt = $structure->getTable($reftable)) {
                             $masterfound = false;
                             $reftablekeys = $rt->getKeys();
                             if ($reftablekeys) {
                                 foreach ($reftablekeys as $reftablekey) {
                                     /// Only compare with primary and unique keys
                                     if ($reftablekey->getType() != XMLDB_KEY_PRIMARY && $reftablekey->getType() != XMLDB_KEY_UNIQUE) {
                                         continue;
                                     }
                                     $keyfieldsarr = $reftablekey->getFields();
                                     /// Compare both arrays, looking for diferences
                                     $diferences = array_merge(array_diff($reffieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $reffieldsarr));
                                     if (empty($diferences)) {
                                         $masterfound = true;
                                         break;
                                     }
                                 }
                                 if (!$masterfound) {
                                     $errors[] = $this->str['nomasterprimaryuniquefound'];
                                 } else {
                                     /// Quick test of the order
                                     if (implode(',', $reffieldsarr) != implode(',', $keyfieldsarr)) {
                                         $errors[] = $this->str['masterprimaryuniqueordernomatch'];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($errors)) {
         $tempkey = new xmldb_key($name);
         $tempkey->setType($type);
         $tempkey->setFields($fieldsarr);
         if ($type == XMLDB_KEY_FOREIGN || $type == XMLDB_KEY_FOREIGN_UNIQUE) {
             $tempkey->setRefTable($reftable);
             $tempkey->setRefFields($reffieldsarr);
         }
         /// Prepare the output
         $o = '<p>' . implode(', ', $errors) . '</p>
               <p>' . $name . ': ' . $tempkey->readableInfo() . '</p>';
         $o .= '<a href="index.php?action=edit_key&amp;key=' . $key->getName() . '&amp;table=' . $table->getName() . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
         $this->output = $o;
     }
     /// Continue if we aren't under errors
     if (empty($errors)) {
         /// If there is one name change, do it, changing the prev and next
         /// atributes of the adjacent fields
         if ($keyparam != $name) {
             $key->setName($name);
             if ($key->getPrevious()) {
                 $prev =& $table->getKey($key->getPrevious());
                 $prev->setNext($name);
                 $prev->setChanged(true);
             }
             if ($key->getNext()) {
                 $next =& $table->getKey($key->getNext());
                 $next->setPrevious($name);
                 $next->setChanged(true);
             }
         }
         /// Set comment
         $key->setComment($comment);
         /// Set the rest of fields
         $key->setType($type);
         $key->setFields($fieldsarr);
         if ($type == XMLDB_KEY_FOREIGN || $type == XMLDB_KEY_FOREIGN_UNIQUE) {
             $key->setRefTable($reftable);
             $key->setRefFields($reffieldsarr);
         }
         /// If the hash has changed from the old one, change the version
         /// and mark the structure as changed
         $key->calculateHash(true);
         if ($oldhash != $key->getHash()) {
             $key->setChanged(true);
             $table->setChanged(true);
             /// Recalculate the structure hash
             $structure->calculateHash(true);
             $structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
             /// Mark as changed
             $structure->setChanged(true);
         }
         /// Launch postaction if exists (leave this here!)
         if ($this->getPostAction() && $result) {
             return $this->launch($this->getPostAction());
         }
     }
     /// Return ok if arrived here
     return $result;
 }
Beispiel #13
0
function xmldb_feedback_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2007012310) {
        //create a new table feedback_completedtmp and the field-definition
        $table = new xmldb_table('feedback_completedtmp');
        $field = new xmldb_field('id');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
        $table->addField($field);
        $field = new xmldb_field('feedback');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('userid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('guestid');
        $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, false, '', null);
        $table->addField($field);
        $field = new xmldb_field('timemodified');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $key = new xmldb_key('PRIMARY');
        $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
        $table->addKey($key);
        $key = new xmldb_key('feedback');
        $key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
        $table->addKey($key);
        $dbman->create_table($table);
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        //create a new table feedback_valuetmp and the field-definition
        $table = new xmldb_table('feedback_valuetmp');
        $field = new xmldb_field('id');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
        $table->addField($field);
        $field = new xmldb_field('course_id');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('item');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('completed');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('tmp_completed');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('value');
        $field->set_attributes(XMLDB_TYPE_TEXT, null, null, null, false, '', null);
        $table->addField($field);
        $key = new xmldb_key('PRIMARY');
        $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
        $table->addKey($key);
        $key = new xmldb_key('feedback');
        $key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
        $table->addKey($key);
        $dbman->create_table($table);
        ////////////////////////////////////////////////////////////
        upgrade_mod_savepoint(true, 2007012310, 'feedback');
    }
    if ($oldversion < 2007050504) {
        /// Define field random_response to be added to feedback_completed
        $table = new xmldb_table('feedback_completed');
        $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        /// Launch add field1
        $dbman->add_field($table, $field);
        /// Define field anonymous_response to be added to feedback_completed
        $table = new xmldb_table('feedback_completed');
        $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
        /// Launch add field2
        $dbman->add_field($table, $field);
        /// Define field random_response to be added to feedback_completed
        $table = new xmldb_table('feedback_completedtmp');
        $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        /// Launch add field1
        $dbman->add_field($table, $field);
        /// Define field anonymous_response to be added to feedback_completed
        $table = new xmldb_table('feedback_completedtmp');
        $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
        /// Launch add field2
        $dbman->add_field($table, $field);
        ////////////////////////////////////////////////////////////
        upgrade_mod_savepoint(true, 2007050504, 'feedback');
    }
    if ($oldversion < 2007102600) {
        // public is a reserved word on Oracle
        $table = new xmldb_table('feedback_template');
        $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2007102600, 'feedback');
    }
    if ($oldversion < 2008042400) {
        //New version in version.php
        if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', array('anonymous' => 2))) {
            $update_sql = 'UPDATE {feedback_completed}
                            SET anonymous_response = 2
                            WHERE feedback = ';
            foreach ($all_nonanonymous_feedbacks as $fb) {
                $DB->execute($update_sql . $fb->id);
            }
        }
        upgrade_mod_savepoint(true, 2008042400, 'feedback');
    }
    if ($oldversion < 2008042401) {
        //New version in version.php
        $concat_radio = $DB->sql_concat("'r>>>>>'", 'presentation');
        $concat_check = $DB->sql_concat("'c>>>>>'", 'presentation');
        $concat_dropdown = $DB->sql_concat("'d>>>>>'", 'presentation');
        $update_sql1 = "UPDATE {feedback_item}\n                        SET presentation = " . $concat_radio . "\n                        WHERE typ IN('radio','radiorated')";
        $update_sql2 = "UPDATE {feedback_item}\n                        SET presentation = " . $concat_dropdown . "\n                        WHERE typ IN('dropdown','dropdownrated')";
        $update_sql3 = "UPDATE {feedback_item}\n                        SET presentation = " . $concat_check . "\n                        WHERE typ = 'check'";
        $DB->execute($update_sql1);
        $DB->execute($update_sql2);
        $DB->execute($update_sql3);
        $update_sql1 = "UPDATE {feedback_item}\n                        SET typ = 'multichoice'\n                        WHERE typ IN('radio','check','dropdown')";
        $update_sql2 = "UPDATE {feedback_item}\n                        SET typ = 'multichoicerated'\n                        WHERE typ IN('radiorated','dropdownrated')";
        $DB->execute($update_sql1);
        $DB->execute($update_sql2);
        upgrade_mod_savepoint(true, 2008042401, 'feedback');
    }
    if ($oldversion < 2008042900) {
        /// Define field autonumbering to be added to feedback
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit');
        /// Launch add field2
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint(true, 2008042900, 'feedback');
    }
    if ($oldversion < 2008050104) {
        /// Define field site_after_submit to be added to feedback
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'autonumbering');
        /// Launch add field2
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint(true, 2008050104, 'feedback');
    }
    if ($oldversion < 2008050105) {
        //field count is not more needed
        $table = new xmldb_table('feedback_tracking');
        $field = new xmldb_field('count');
        $dbman->drop_field($table, $field);
        upgrade_mod_savepoint(true, 2008050105, 'feedback');
    }
    if ($oldversion < 2008073002) {
        $update_sql = "UPDATE {feedback_item}\n                        SET presentation = '-|-'\n                        WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND\n                            typ = 'numeric'";
        $DB->execute($update_sql);
        upgrade_mod_savepoint(true, 2008073002, 'feedback');
    }
    if ($oldversion < 2009031301) {
        /// Define field label to be added to feedback_item
        $table = new xmldb_table('feedback_item');
        $field = new xmldb_field('label', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'name');
        /// Launch add field2
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint(true, 2009031301, 'feedback');
    }
    if ($oldversion < 2009042000) {
        /// Rename field summary on table feedback to intro
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name');
        /// Launch rename field summary
        $dbman->rename_field($table, $field, 'intro');
        /// feedback savepoint reached
        upgrade_mod_savepoint(true, 2009042000, 'feedback');
    }
    if ($oldversion < 2009042001) {
        /// Define field introformat to be added to feedback
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
        /// Launch add field introformat
        $dbman->add_field($table, $field);
        /// feedback savepoint reached
        upgrade_mod_savepoint(true, 2009042001, 'feedback');
    }
    if ($oldversion < 2009112000) {
        /// Define field page_after_submitformat to be added to feedback
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit');
        if (!$dbman->field_exists($table, $field)) {
            // Launch add field page_after_submitformat
            $dbman->add_field($table, $field);
        }
        // feedback savepoint reached
        upgrade_mod_savepoint(true, 2009112000, 'feedback');
    }
    if ($oldversion < 2010051101) {
        /// Define field options to be added to feedback_item
        $table = new xmldb_table('feedback_item');
        $field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'required');
        /// Launch add field
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint(true, 2010051101, 'feedback');
    }
    if ($oldversion < 2010051600) {
        /// Define field options to be added to feedback_item
        $table = new xmldb_table('feedback_item');
        $field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required');
        /// Launch add field
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint(true, 2010051600, 'feedback');
    }
    if ($oldversion < 2010051601) {
        /// Define field options to be added to feedback_item
        $table = new xmldb_table('feedback_item');
        $field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'dependitem');
        /// Launch add field
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint(true, 2010051601, 'feedback');
    }
    if ($oldversion < 2010102300) {
        // Define field completionsubmit to be added to feedback
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'timemodified');
        // Conditionally launch add field completionsubmit
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // feedback savepoint reached
        upgrade_mod_savepoint(true, 2010102300, 'feedback');
    }
    // Moodle v2.1.0 release upgrade line
    // Put any upgrade step following this
    return true;
}
Beispiel #14
0
function xmldb_feedback_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    $result = true;
    if ($result && $oldversion < 2007012310) {
        //create a new table feedback_completedtmp and the field-definition
        $table = new xmldb_table('feedback_completedtmp');
        $field = new xmldb_field('id');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
        $table->addField($field);
        $field = new xmldb_field('feedback');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('userid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('guestid');
        $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, false, '', null);
        $table->addField($field);
        $field = new xmldb_field('timemodified');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $key = new xmldb_key('PRIMARY');
        $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
        $table->addKey($key);
        $key = new xmldb_key('feedback');
        $key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
        $table->addKey($key);
        $dbman->create_table($table);
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        //create a new table feedback_valuetmp and the field-definition
        $table = new xmldb_table('feedback_valuetmp');
        $field = new xmldb_field('id');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
        $table->addField($field);
        $field = new xmldb_field('course_id');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('item');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('completed');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('tmp_completed');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        $table->addField($field);
        $field = new xmldb_field('value');
        $field->set_attributes(XMLDB_TYPE_TEXT, null, null, null, false, '', null);
        $table->addField($field);
        $key = new xmldb_key('PRIMARY');
        $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
        $table->addKey($key);
        $key = new xmldb_key('feedback');
        $key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
        $table->addKey($key);
        $dbman->create_table($table);
        ////////////////////////////////////////////////////////////
        upgrade_mod_savepoint($result, 2007012310, 'feedback');
    }
    if ($result && $oldversion < 2007050504) {
        /// Define field random_response to be added to feedback_completed
        $table = new xmldb_table('feedback_completed');
        $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        /// Launch add field1
        $dbman->add_field($table, $field);
        /// Define field anonymous_response to be added to feedback_completed
        $table = new xmldb_table('feedback_completed');
        $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
        /// Launch add field2
        $dbman->add_field($table, $field);
        /// Define field random_response to be added to feedback_completed
        $table = new xmldb_table('feedback_completedtmp');
        $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
        /// Launch add field1
        $dbman->add_field($table, $field);
        /// Define field anonymous_response to be added to feedback_completed
        $table = new xmldb_table('feedback_completedtmp');
        $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
        /// Launch add field2
        $dbman->add_field($table, $field);
        ////////////////////////////////////////////////////////////
        upgrade_mod_savepoint($result, 2007050504, 'feedback');
    }
    if ($result && $oldversion < 2007102600) {
        // public is a reserved word on Oracle
        $table = new xmldb_table('feedback_template');
        $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint($result, 2007102600, 'feedback');
    }
    if ($result && $oldversion < 2008042400) {
        //New version in version.php
        if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', 'anonymous', 2)) {
            $update_sql = 'UPDATE {feedback_completed} SET anonymous_response = 2 WHERE feedback = ';
            foreach ($all_nonanonymous_feedbacks as $fb) {
                $result = $result && $DB->execute($update_sql . $fb->id);
            }
        }
        upgrade_mod_savepoint($result, 2008042400, 'feedback');
    }
    if ($result && $oldversion < 2008042401) {
        //New version in version.php
        if ($result) {
            $concat_radio = $DB->sql_concat("'r>>>>>'", 'presentation');
            $concat_check = $DB->sql_concat("'c>>>>>'", 'presentation');
            $concat_dropdown = $DB->sql_concat("'d>>>>>'", 'presentation');
            $update_sql1 = "UPDATE {feedback_item} SET presentation = " . $concat_radio . " WHERE typ IN('radio','radiorated')";
            $update_sql2 = "UPDATE {feedback_item} SET presentation = " . $concat_dropdown . " WHERE typ IN('dropdown','dropdownrated')";
            $update_sql3 = "UPDATE {feedback_item} SET presentation = " . $concat_check . " WHERE typ = 'check'";
            $result = $result && $DB->execute($update_sql1);
            $result = $result && $DB->execute($update_sql2);
            $result = $result && $DB->execute($update_sql3);
        }
        if ($result) {
            $update_sql1 = "UPDATE {feedback_item} SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')";
            $update_sql2 = "UPDATE {feedback_item} SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')";
            $result = $result && $DB->execute($update_sql1);
            $result = $result && $DB->execute($update_sql2);
        }
        upgrade_mod_savepoint($result, 2008042401, 'feedback');
    }
    if ($result && $oldversion < 2008042801) {
        $new_log_display = new object();
        $new_log_display->module = 'feedback';
        $new_log_display->action = 'startcomplete';
        $new_log_display->mtable = 'feedback';
        $new_log_display->field = 'name';
        $result = $result && $DB->insert_record('log_display', $new_log_display);
        $new_log_display = clone $new_log_display;
        $new_log_display->action = 'submit';
        $result = $result && $DB->insert_record('log_display', $new_log_display);
        $new_log_display = clone $new_log_display;
        $new_log_display->action = 'delete';
        $result = $result && $DB->insert_record('log_display', $new_log_display);
        $new_log_display = clone $new_log_display;
        $new_log_display->action = 'view';
        $result = $result && $DB->insert_record('log_display', $new_log_display);
        $new_log_display = clone $new_log_display;
        $new_log_display->action = 'view all';
        $new_log_display->mtable = 'course';
        $new_log_display->field = 'shortname';
        $result = $result && $DB->insert_record('log_display', $new_log_display);
        upgrade_mod_savepoint($result, 2008042801, 'feedback');
    }
    if ($result && $oldversion < 2008042900) {
        /// Define field autonumbering to be added to feedback
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit');
        /// Launch add field2
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint($result, 2008042900, 'feedback');
    }
    if ($result && $oldversion < 2008050104) {
        /// Define field site_after_submit to be added to feedback
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'autonumbering');
        /// Launch add field2
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint($result, 2008050104, 'feedback');
    }
    if ($result && $oldversion < 2008050105) {
        //field count is not more needed
        $table = new xmldb_table('feedback_tracking');
        $field = new xmldb_field('count');
        $dbman->drop_field($table, $field);
        upgrade_mod_savepoint($result, 2008050105, 'feedback');
    }
    if ($result && $oldversion < 2008073002) {
        $update_sql = "UPDATE {feedback_item} SET presentation = '-|-' WHERE presentation = '0|0' AND typ = 'numeric'";
        $result = $result && $DB->execute($update_sql);
        upgrade_mod_savepoint($result, 2008073002, 'feedback');
    }
    if ($result && $oldversion < 2009031301) {
        /// Define field label to be added to feedback_item
        $table = new xmldb_table('feedback_item');
        $field = new xmldb_field('label', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'name');
        /// Launch add field2
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint($result, 2009031301, 'feedback');
    }
    if ($result && $oldversion < 2009042000) {
        /// Rename field summary on table feedback to intro
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name');
        /// Launch rename field summary
        $dbman->rename_field($table, $field, 'intro');
        /// feedback savepoint reached
        upgrade_mod_savepoint($result, 2009042000, 'feedback');
    }
    if ($result && $oldversion < 2009042001) {
        /// Define field introformat to be added to feedback
        $table = new xmldb_table('feedback');
        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
        /// Launch add field introformat
        $dbman->add_field($table, $field);
        /// feedback savepoint reached
        upgrade_mod_savepoint($result, 2009042001, 'feedback');
    }
    return $result;
}
 /**
  * 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_NONE;
     $this->does_generate = ACTION_GENERATE_HTML;
     /// These are always here
     global $XMLDB, $DB, $CFG;
     $dbman = $DB->get_manager();
     $gen = $dbman->generator;
     $dbfamily = $DB->get_dbfamily();
     /// Where all the tests will be stored
     $tests = array();
     /// The back to edit table button
     $b = ' <p class="centerpara buttons">';
     $b .= '<a href="index.php">[' . $this->str['back'] . ']</a>';
     $b .= '</p>';
     $o = $b;
     /// Silenty drop any previous test tables
     $table = new xmldb_table('testtable');
     if ($dbman->table_exists($table)) {
         $dbman->drop_table($table);
     }
     $table = new xmldb_table('anothertest');
     if ($dbman->table_exists($table)) {
         $dbman->drop_table($table);
     }
     $table = new xmldb_table('newnameforthetable');
     if ($dbman->table_exists($table)) {
         $dbman->drop_table($table);
     }
     /// 1st test. Complete table creation.
     $table = new xmldb_table('testtable');
     $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
     $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general');
     $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null);
     $table->add_field('intro', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
     $table->add_field('logo', XMLDB_TYPE_BINARY, 'big', null, XMLDB_NOTNULL, null);
     $table->add_field('assessed', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('assesstimestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('assesstimefinish', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('scale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
     $table->add_field('maxbytes', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('forcesubscribe', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('trackingtype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
     $table->add_field('rsstype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('rssarticles', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('grade', XMLDB_TYPE_NUMBER, '20,0', XMLDB_UNSIGNED, null, null, null);
     $table->add_field('percent', XMLDB_TYPE_NUMBER, '5,2', null, null, null, null);
     $table->add_field('warnafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('blockafter', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_field('blockperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
     $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
     $table->add_key('type-name', XMLDB_KEY_UNIQUE, array('type', 'name'));
     $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
     $table->add_index('rsstype', XMLDB_INDEX_UNIQUE, array('rsstype'));
     $table->setComment("This is a test'n drop table. You can drop it safely");
     /// Get SQL code and execute it
     $test = new stdClass();
     $test->sql = $gen->getCreateTableSQL($table);
     try {
         $dbman->create_table($table);
         $test->status = true;
     } catch (moodle_exception $e) {
         $test->status = false;
         $test->error = $DB->get_last_error() . "\n" . $e;
     }
     $tests['create table'] = $test;
     /// 2nd test. drop table
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getDropTableSQL($table);
         try {
             $dbman->drop_table($table);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop table'] = $test;
     }
     /// 3rd test. creating another, smaller table
     if ($test->status) {
         $table = new xmldb_table('anothertest');
         $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
         $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
         $table->add_field('name', XMLDB_TYPE_CHAR, '30', null, null, null, 'Moodle');
         $table->add_field('secondname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
         $table->add_field('intro', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
         $table->add_field('avatar', XMLDB_TYPE_BINARY, 'medium', null, null, null, null);
         $table->add_field('grade', XMLDB_TYPE_NUMBER, '20,10', null, null, null);
         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getCreateTableSQL($table);
         try {
             $dbman->create_table($table);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['create table - 2'] = $test;
     }
     if ($test->status) {
         /// Insert two records to do the work with real data
         $rec = new stdClass();
         $rec->course = 1;
         $rec->name = 'Martin';
         $rec->secondname = 'Dougiamas';
         $rec->intro = 'The creator of Moodle';
         $rec->grade = 10.0001;
         $DB->insert_record('anothertest', $rec);
         $rec->course = 2;
         $rec->name = 'Eloy';
         $rec->secondname = 'Lafuente';
         $rec->intro = 'One poor developer';
         $rec->grade = 9.99;
         $DB->insert_record('anothertest', $rec);
     }
     /// 4th test. Adding one field
     if ($test->status) {
         /// Create a new field with complex specs
         $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getAddFieldSQL($table, $field);
         try {
             $dbman->add_field($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add field'] = $test;
     }
     /// 5th test. Dropping one complex field
     if ($test->status) {
         /// Create a new field with complex specs
         $test = new stdClass();
         $test->sql = $gen->getDropFieldSQL($table, $field);
         try {
             $dbman->drop_field($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop field'] = $test;
     }
     /// 6th test. Adding one complex field again
     if ($test->status) {
         /// Create a new field with complex specs
         $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getAddFieldSQL($table, $field);
         try {
             $dbman->add_field($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add field again'] = $test;
     }
     /// 7th test. Dropping one complex field again
     if ($test->status) {
         /// Create a new field with complex specs
         $field = new xmldb_field('type');
         $test = new stdClass();
         $test->sql = $gen->getDropFieldSQL($table, $field);
         try {
             $dbman->drop_field($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop field again'] = $test;
     }
     /// 8th test. Adding one numeric field
     if ($test->status) {
         /// Create a new field (numeric)
         $field = new xmldb_field('onenumber', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'course');
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getAddFieldSQL($table, $field);
         try {
             $dbman->add_field($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add numeric field'] = $test;
     }
     /// 9th test. Change the type of one column from integer to varchar
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('course', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, '0');
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_type($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field type (int2char)'] = $test;
     }
     /// 10th test. Change the type of one column from varchar to integer
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_type($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field type (char2int)'] = $test;
     }
     /// 11th test. Change the type of one column from number to varchar
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, "test'n drop");
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_type($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field type (number2char)'] = $test;
     }
     /// 12th test. Change the type of one column from varchar to float
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('grade', XMLDB_TYPE_FLOAT, '20,10', XMLDB_UNSIGNED, null, null, null);
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_type($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field type (char2float)'] = $test;
     }
     /// 13th test. Change the type of one column from float to char
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('grade', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'test');
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_type($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field type (float2char)'] = $test;
     }
     /// 14th test. Change the type of one column from char to number
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '20,10', XMLDB_UNSIGNED, null, null, null);
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_type($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field type (char2number)'] = $test;
     }
     /// 15th test. Change the precision of one text field
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('intro');
         $field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null);
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_precision($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field precision (text)'] = $test;
     }
     /// 16th test. Change the precision of one char field
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('secondname');
         $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_precision($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field precision (char)'] = $test;
     }
     /// 17th test. Change the precision of one numeric field
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('grade');
         $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null);
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_precision($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field precision (number)'] = $test;
     }
     /// 18th test. Change the precision of one integer field to a smaller one
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('course');
         $field->set_attributes(XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_precision($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field precision (integer) to smaller one'] = $test;
     }
     /// 19th test. Change the sign of one numeric field to unsigned
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('grade');
         $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null);
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_unsigned($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field sign (unsigned)'] = $test;
     }
     /// 20th test. Change the sign of one numeric field to signed
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('grade');
         $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null);
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_unsigned($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field sign (signed)'] = $test;
     }
     /// 21th test. Change the nullability of one char field to not null
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('name');
         $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'Moodle');
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_notnull($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field nullability (not null)'] = $test;
     }
     /// 22th test. Change the nullability of one char field to null
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('name');
         $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, 'Moodle');
         $test->sql = $gen->getAlterFieldSQL($table, $field);
         try {
             $dbman->change_field_notnull($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['change field nullability (null)'] = $test;
     }
     /// 23th test. Dropping the default of one field
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('name');
         $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, null);
         $test->sql = $gen->getModifyDefaultSQL($table, $field);
         try {
             $dbman->change_field_default($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop field default of NULL field'] = $test;
     }
     /// 24th test. Creating the default for one field
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('name');
         $field->set_attributes(XMLDB_TYPE_CHAR, '30', null, null, null, 'Moodle');
         $test->sql = $gen->getModifyDefaultSQL($table, $field);
         try {
             $dbman->change_field_default($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add field default of NULL field'] = $test;
     }
     /// 25th test. Creating the default for one field
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('secondname');
         $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'Moodle2');
         $test->sql = $gen->getModifyDefaultSQL($table, $field);
         try {
             $dbman->change_field_default($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add field default of NOT NULL field'] = $test;
     }
     /// 26th test. Dropping the default of one NOT NULL field
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('secondname');
         $field->set_attributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
         $test->sql = $gen->getModifyDefaultSQL($table, $field);
         try {
             $dbman->change_field_default($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop field default of NOT NULL field'] = $test;
     }
     /// 27th test. Adding one unique index to the table
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $index = new xmldb_index('secondname');
         $index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'secondname', 'grade'));
         $test->sql = $gen->getAddIndexSQL($table, $index);
         try {
             $dbman->add_index($table, $index, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add unique index'] = $test;
     }
     /// 28th test. Adding one not unique index to the table
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $index = new xmldb_index('secondname');
         $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
         $test->sql = $gen->getAddIndexSQL($table, $index);
         try {
             $dbman->add_index($table, $index, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add not unique index'] = $test;
     }
     /// 29th test. Re-add the same index than previous test. Check find_index_name() works.
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $index = new xmldb_index('secondname');
         $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('name', 'course'));
         if ($indexfound = $dbman->find_index_name($table, $index)) {
             $test->status = true;
             $test->sql = array();
         } else {
             $test->status = true;
             $test->error = 'Index not found!';
             $test->sql = array();
         }
         $tests['check find_index_name()'] = $test;
     }
     /// 30th test. Dropping one index from the table
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $index = new xmldb_index('name');
         $index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'grade', 'secondname'));
         $test->sql = $gen->getDropIndexSQL($table, $index);
         try {
             $dbman->drop_index($table, $index, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop index'] = $test;
     }
     /// 31th test. Adding one unique key to the table
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $key = new xmldb_key('id-course-grade');
         $key->set_attributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
         $test->sql = $gen->getAddKeySQL($table, $key);
         try {
             $dbman->add_key($table, $key, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add unique key'] = $test;
     }
     /// 32th test. Adding one foreign+unique key to the table
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $key = new xmldb_key('course');
         $key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
         $test->sql = $gen->getAddKeySQL($table, $key);
         try {
             $dbman->add_key($table, $key, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add foreign+unique key'] = $test;
     }
     /// 33th test. Drop one key
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $key = new xmldb_key('course');
         $key->set_attributes(XMLDB_KEY_FOREIGN_UNIQUE, array('course'), 'anothertest', array('id'));
         $test->sql = $gen->getDropKeySQL($table, $key);
         try {
             $dbman->drop_key($table, $key, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop foreign+unique key'] = $test;
     }
     /// 34th test. Adding one foreign key to the table
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $key = new xmldb_key('course');
         $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
         $test->sql = $gen->getAddKeySQL($table, $key);
         try {
             $dbman->add_key($table, $key, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add foreign key'] = $test;
     }
     /// 35th test. Drop one foreign key
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $key = new xmldb_key('course');
         $key->set_attributes(XMLDB_KEY_FOREIGN, array('course'), 'anothertest', array('id'));
         $test->sql = $gen->getDropKeySQL($table, $key);
         try {
             $dbman->drop_key($table, $key, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop foreign key'] = $test;
     }
     /// 36th test. Adding one complex field and forcing creation of enum/ck manually (to test dropping latter)
     /// TODO: Drop this test in Moodle 2.1
     if ($test->status) {
         /// Create a new field with complex specs (enums are good candidates)
         $field = new xmldb_field('type');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getAddFieldSQL($table, $field);
         try {
             $dbman->add_field($table, $field, false, false);
             $test->status = true;
             /// Now, let's add one enum/check manually, because XMLDB stuff hasn't support for that
             /// anymore. We are dropping enums support, but need to check dropping them until Moodle 2.1.
             switch ($dbfamily) {
                 case 'mysql':
                     $create_enum = "ALTER TABLE {anothertest} MODIFY COLUMN type enum('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda') NOT NULL DEFAULT 'general'";
                     break;
                 case 'mssql':
                 case 'oracle':
                 case 'postgres':
                     $create_enum = "ALTER TABLE {anothertest} ADD CONSTRAINT xmldb_ck CHECK (type IN ('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'))";
                     break;
             }
             $test->sql[] = $create_enum;
             $DB->execute($create_enum);
             /// Create the enum/check. Not the best way but works for this needed test
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add field with enum/ck manually'] = $test;
     }
     /// 37th test. Dropping one field containing enum/ck
     /// TODO: Drop this test in Moodle 2.1
     if ($test->status) {
         $test = new stdClass();
         $test->sql = $gen->getDropFieldSQL($table, $field);
         $field = new xmldb_field('type');
         try {
             $dbman->drop_field($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop field with enum/ck'] = $test;
     }
     /// 38th test. Adding one complex field and forcing creation of enum/ck manually (to test dropping latter)
     /// TODO: Drop this test in Moodle 2.1
     if ($test->status) {
         /// Create a new field with complex specs (enums are good candidates)
         $field = new xmldb_field('type');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getAddFieldSQL($table, $field);
         try {
             $dbman->add_field($table, $field, false, false);
             $test->status = true;
             /// Now, let's add one enum/check manually, because XMLDB stuff hasn't support for that
             /// anymore. We are dropping enums support, but need to check dropping them until Moodle 2.1.
             switch ($dbfamily) {
                 case 'mysql':
                     $create_enum = "ALTER TABLE {anothertest} MODIFY COLUMN type enum('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda') NOT NULL DEFAULT 'general'";
                     break;
                 case 'mssql':
                 case 'oracle':
                 case 'postgres':
                     $create_enum = "ALTER TABLE {anothertest} ADD CONSTRAINT xmldb_ck CHECK (type IN ('single', 'news', 'general', 'social', 'eachuser', 'teacher', 'qanda'))";
                     break;
             }
             $test->sql[] = $create_enum;
             $DB->execute($create_enum);
             /// Create the enum/check. Not the best way but works for this needed test
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['add field with enum/ck manually again'] = $test;
     }
     /// 39th test. Dropping the enum from one field
     /// TODO: Drop this test in Moodle 2.1
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('type');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
         $test->sql = $gen->getDropEnumSQL($table, $field);
         try {
             $dbman->drop_enum_from_field($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop enum/ck from field containing enum'] = $test;
     }
     /// 40th test. Drop enum from field not containing enum
     /// TODO: Drop this test in Moodle 2.1
     if ($test->status) {
         /// Drop enum from field not containing enum
         $field = new xmldb_field('type');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getDropEnumSQL($table, $field);
         try {
             $dbman->drop_enum_from_field($table, $field, false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['drop enum/ck from field not containing enum'] = $test;
     }
     /// 41th test. Renaming one index
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $index = new xmldb_index('anyname');
         $index->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'course'));
         $test->sql = $gen->getRenameIndexSQL($table, $index, 'newnamefortheindex');
         try {
             $dbman->rename_index($table, $index, 'newnamefortheindex', false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . "Getting this error is the expected behaviour. Function is experimental and ins't used in code at all. Don't worry!";
         }
         $tests['rename index (experimental. DO NOT USE IT)'] = $test;
         $test = new stdClass();
         $test->status = true;
         // ignore errors here
     }
     /// 42th test. Renaming one key
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $key = new xmldb_key('anyname');
         $key->set_attributes(XMLDB_KEY_UNIQUE, array('id', 'course', 'grade'));
         $test->sql = $gen->getRenameKeySQL($table, $key, 'newnameforthekey', true);
         $olddebug = $CFG->debug;
         if ($olddebug > DEBUG_ALL) {
             $CFG->debug = DEBUG_ALL;
             // do not show experimental debug warning
         }
         try {
             $dbman->rename_key($table, $key, 'newnameforthekey', false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . "Getting this error is the expected behaviour. Function is experimental and ins't used in code at all. Don't worry!";
         }
         $CFG->debug = $olddebug;
         $tests['rename key (experimental. DO NOT USE IT)'] = $test;
         $test = new stdClass();
         $test->status = true;
         // ignore errors here
     }
     /// 43th test. Renaming one field
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $field = new xmldb_field('type');
         $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
         $test->sql = $gen->getRenameFieldSQL($table, $field, 'newnameforthefield', true);
         try {
             $dbman->rename_field($table, $field, 'newnameforthefield', false, false);
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['rename field'] = $test;
     }
     /// 44th test. Renaming one table
     if ($test->status) {
         /// Get SQL code and execute it
         $test = new stdClass();
         $test->sql = $gen->getRenameTableSQL($table, 'newnameforthetable', true);
         try {
             $dbman->rename_table($table, 'newnameforthetable');
             $test->status = true;
         } catch (moodle_exception $e) {
             $test->status = false;
             $test->error = $DB->get_last_error() . "\n" . $e;
         }
         $tests['rename table'] = $test;
     }
     /// 45th test. Getting the PK sequence name for one table
     if ($test->status) {
         $table->setName('newnameforthetable');
         $test = new stdClass();
         $test->sql = array($dbman->find_sequence_name($table));
         $test->status = $dbman->find_sequence_name($table);
         if (!$test->status) {
             if (!($test->error = $DB->get_last_error())) {
                 //If no db errors, result is ok. Just the driver doesn't support this
                 $test->sql = array('Not needed for this DB. Correct.');
                 $test->status = true;
             } else {
                 $test->error .= "\n" . $e;
             }
         }
         $tests['find sequence name'] = $test;
     }
     /// 46th test. Inserting TEXT contents
     $textlib = textlib_get_instance();
     if ($test->status) {
         $test = new stdClass();
         $test->status = false;
         $test->sql = array();
         $basetext = "\\ ''語 • Русский • Deutsch • English • Español • Français • Italiano • Nederlands • Polski • Português • Svenska • العربية • فارسی 한국어 • עברית • ไทย中文  Ελληνικά • Български • Српски • Українська • Bosanski • Català • Česky • Dansk • Eesti • Simple English • Esperanto • Euskara • Galego • Hrvatski • Ido • Bahasa Indonesia • Íslenska • Lëtzebuergesch • Lietuvių • Magyar • Bahasa Melayu اردو • ئۇيغۇرچه • हिन्दी • नेपाल भाषा मराठी • தமிழ் Հայերեն • Беларуская • Чăваш • Ирон æвзаг • Македонски • Сибирской говор • Afrikaans • Aragonés • Arpitan • Asturianu • Kreyòl Ayisyen • Azərbaycan • Bân-lâm-gú • Basa Banyumasan • Brezhoneg • Corsu • Cymraeg • Deitsch • Føroyskt • Frysk • Furlan • Gaeilge • Gàidhlig • Ilokano • Interlingua • Basa Jawa • Kapampangan • Kernewek • Kurdî  كوردی • Ladino  לאדינו • Latina • Latviešu • Limburgs • Lumbaart • Nedersaksisch • Nouormand • Occitan • O‘zbek • Piemontèis • Plattdüütsch • Ripoarisch • Sámegiella • Scots • Shqip • Sicilianu • Sinugboanon • Srpskohrvatski / Српскохрватски • Basa Sunda • Kiswahili • Tagalog • Tatarça • Walon • Winaray  Авар • Башҡорт • Кыргызча  Монгол • Қазақша • Тоҷикӣ • Удмурт • Armãneashce • Bamanankan • Eald Englisc • Gaelg • Interlingue • Kaszëbsczi • Kongo • Ligure • Lingála • lojban • Malagasy • Malti • Māori • Nāhuatl • Ekakairũ Naoero • Novial • Pangasinán • Tok Pisin • Romani / रोमानी • Rumantsch • Runa Simi • Sardu • Tetun • Türkmen / تركمن / Туркмен • Vèneto • Volapük • Võro • West-Vlaoms • Wollof • Zazaki • Žemaitėška";
         /// Create one big text (1.500.000 chars)
         $fulltext = '';
         for ($i = 0; $i < 1000; $i++) {
             //1500 * 1000 chars
             $fulltext .= $basetext;
         }
         /// Build the record to insert
         $rec->intro = $fulltext;
         $rec->name = 'texttest';
         /// Calculate its length
         $textlen = $textlib->strlen($fulltext);
         if ($rec->id = $DB->insert_record('newnameforthetable', $rec)) {
             if ($new = $DB->get_record('newnameforthetable', array('id' => $rec->id))) {
                 $DB->delete_records('newnameforthetable', array('id' => $new->id));
                 $newtextlen = $textlib->strlen($new->intro);
                 if ($fulltext === $new->intro) {
                     $test->sql = array($newtextlen . ' cc. (text) sent and received ok');
                     $test->status = true;
                 } else {
                     $test->error = $DB->get_last_error();
                     $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
                     $test->status = false;
                 }
             } else {
                 $test->error = $DB->get_last_error() . 'xx';
             }
         } else {
             $test->error = $DB->get_last_error() . 'yy' . var_export($rec->id, true);
         }
         $tests['insert record ' . $textlen . ' cc. (text)'] = $test;
     }
     /// 47th test. Inserting BINARY contents
     if ($test->status) {
         $test = new stdClass();
         $test->status = false;
         /// Build the record to insert
         $rec->avatar = $fulltext;
         $rec->name = 'binarytest';
         /// Calculate its length
         $textlen = strlen($rec->avatar);
         if ($rec->id = $DB->insert_record('newnameforthetable', $rec)) {
             if ($new = $DB->get_record('newnameforthetable', array('id' => $rec->id))) {
                 $newtextlen = strlen($new->avatar);
                 if ($rec->avatar === $new->avatar) {
                     $test->sql = array($newtextlen . ' bytes (binary) sent and received ok');
                     $test->status = true;
                 } else {
                     $test->error = $DB->get_last_error();
                     $test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!');
                     $test->status = false;
                 }
             } else {
                 $test->error = $DB->get_last_error();
             }
         } else {
             $test->error = $DB->get_last_error();
         }
         $tests['insert record ' . $textlen . ' bytes (binary)'] = $test;
     }
     /// 48th test. $DB->update_record with TEXT and BINARY contents
     if ($test->status) {
         $test = new stdClass();
         $test->status = false;
         $test->sql = array();
         /// Build the record to insert
         $rec->intro = $basetext;
         $rec->avatar = $basetext;
         $rec->name = 'updatelobs';
         /// Calculate its length
         $textlen = $textlib->strlen($basetext);
         $imglen = strlen($basetext);
         if ($DB->update_record('newnameforthetable', $rec)) {
             if ($new = $DB->get_record('newnameforthetable', array('id' => $rec->id))) {
                 $newtextlen = $textlib->strlen($new->intro);
                 $newimglen = strlen($new->avatar);
                 if ($basetext === $new->avatar && $basetext === $new->intro) {
                     $test->sql = array($newtextlen . ' cc. (text) sent and received ok', $newimglen . ' bytes (binary) sent and received ok');
                     $test->status = true;
                 } else {
                     if ($rec->avatar !== $new->avatar) {
                         $test->error = $DB->get_last_error();
                         $test->sql = array($newimglen . ' bytes (binary) transfer failed. Data changed!');
                         $test->status = false;
                     } else {
                         $test->error = $DB->get_last_error();
                         $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
                         $test->status = false;
                     }
                 }
             } else {
                 $test->error = $DB->get_last_error();
             }
         } else {
             $test->error = $DB->get_last_error();
         }
         $tests['update record ' . $textlen . ' cc. (text) and ' . $imglen . ' bytes (binary)'] = $test;
     }
     /// 49th test. $DB->set_field with TEXT contents
     if ($test->status) {
         $test = new stdClass();
         $test->status = false;
         $test->sql = array();
         /// Build the record to insert
         $rec->intro = $fulltext;
         $rec->name = 'updatelobs';
         /// Calculate its length
         $textlen = $textlib->strlen($fulltext);
         if ($DB->set_field('newnameforthetable', 'intro', $rec->intro, array('name' => $rec->name))) {
             if ($new = $DB->get_record('newnameforthetable', array('id' => $rec->id))) {
                 $newtextlen = $textlib->strlen($new->intro);
                 if ($fulltext === $new->intro) {
                     $test->sql = array($newtextlen . ' cc. (text) sent and received ok');
                     $test->status = true;
                 } else {
                     $test->error = $DB->get_last_error();
                     $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
                     $test->status = false;
                 }
             } else {
                 $test->error = $DB->get_last_error();
             }
         } else {
             $test->error = $DB->get_last_error();
         }
         $tests['set field ' . $textlen . ' cc. (text)'] = $test;
     }
     /// 50th test. $DB->set_field with BINARY contents
     if ($test->status) {
         $test = new stdClass();
         $test->status = false;
         $test->sql = array();
         /// Build the record to insert
         $rec->avatar = $fulltext;
         $rec->name = 'updatelobs';
         /// Calculate its length
         $textlen = strlen($rec->avatar);
         if ($DB->set_field('newnameforthetable', 'avatar', $rec->avatar, array('name' => $rec->name))) {
             if ($new = $DB->get_record('newnameforthetable', array('id' => $rec->id))) {
                 $newtextlen = strlen($new->avatar);
                 if ($rec->avatar === $new->avatar) {
                     $test->sql = array($newtextlen . ' bytes (binary) sent and received ok');
                     $test->status = true;
                 } else {
                     $test->error = $DB->get_last_error();
                     $test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!');
                     $test->status = false;
                 }
             } else {
                 $test->error = $DB->get_last_error();
             }
         } else {
             $test->error = $DB->get_last_error();
         }
         $tests['set field ' . $textlen . ' bytes (binary)'] = $test;
     }
     /// TODO: Check here values of the inserted records to see that everything has the correct value
     /// Iterate over tests, showing information as needed
     $o .= '<ol>';
     foreach ($tests as $key => $test) {
         $o .= '<li>' . $key . ($test->status ? '<font color="green"> Ok</font>' : ' <font color="red">Error</font>');
         if (!$test->status) {
             $o .= '<br/><font color="red">' . $test->error . '</font>';
         }
         $o .= '<pre>' . implode('<br/>', $test->sql) . '</pre>';
         $o .= '</li>';
     }
     $o .= '</ol>';
     $this->output = $o;
     /// Launch postaction if exists (leave this here!)
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     /// Return ok if arrived here
     return $result;
 }