/** * @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; }
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); }
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; }
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; }
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; }
/** * 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; }