/** * 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&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; }
/** * 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; }
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; }
/** * Test behaviour of drop_enum_from_field() and related functions (find_check_constraint_name * and check_constraint_exists). Needed to be able to drop existing "enum" fields in the upgrade * from 1.9 to 2.0, will be completely deleted for Moodle 2.1 * * Because we already have dropped support for creation of enum fields in 2.0, we are going to * create them here "manually" (hardcoded DB-dependent SQL). Just to be able to test the * find and drop functions properly. * * TODO: Drop this tests completely from Moodle 2.1 */ public function test_drop_enum_from_field() { $DB = $this->tdb; // do not use global $DB! $dbman = $this->tdb->get_manager(); // Create normal table, no enums. $table = new xmldb_table('test_table_cust0'); $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'); $field = new xmldb_field('type'); $field->set_attributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general'); $table->addField($field); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $dbman->create_table($table); $this->assertTrue($dbman->table_exists($table)); $this->assertTrue($dbman->field_exists($table, $field)); // Check table hasn't enums at all $this->assertFalse($dbman->check_constraint_exists($table, $field)); $this->assertFalse($dbman->find_check_constraint_name($table, $field)); ob_start(); $this->assertFalse($dbman->drop_enum_from_field($table, $field)); // This just outputs debug warning if field hasn't enums ob_end_clean(); // Insert some info $record = new stdClass(); $record->course = 666; $record->type = 'qanda'; $this->assertTrue($DB->insert_record('test_table_cust0', $record, false)); // Hackery starts here, depending of the db family we are testing... execute // the needed SQL statements to get the "type" field defined as enum $stmt = ''; switch ($DB->get_dbfamily()) { case 'mysql': // It's ENUM field for mysql $stmt = "ALTER TABLE {$DB->get_prefix()}test_table_cust0 MODIFY type ENUM ('general', 'qanda', 'moodle') NOT NULL DEFAULT 'general'"; break; default: // It's check constraint for "normal" DBs $stmt = "ALTER TABLE {$DB->get_prefix()}test_table_cust0 ADD CONSTRAINT ttcu0_ck CHECK (type IN ('general', 'qanda', 'moodle'))"; } $DB->change_database_structure($stmt); // Check table has enums now $this->assertTrue($dbman->check_constraint_exists($table, $field)); $this->assertTrue($dbman->find_check_constraint_name($table, $field)); // Removing an enum value $dbman->drop_enum_from_field($table, $field); // Chech table hasn't enum anymore $this->assertFalse($dbman->check_constraint_exists($table, $field)); $this->assertFalse($dbman->find_check_constraint_name($table, $field)); $dbman->drop_table($table); }
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; }
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; }