本文整理汇总了PHP中xmldb_table::add_key方法的典型用法代码示例。如果您正苦于以下问题:PHP xmldb_table::add_key方法的具体用法?PHP xmldb_table::add_key怎么用?PHP xmldb_table::add_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmldb_table
的用法示例。
在下文中一共展示了xmldb_table::add_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_qtype_calculated_upgrade
function xmldb_qtype_calculated_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
// MDL-16505.
if ($result && $oldversion < 2008091700) {
//New version in version.php
if (get_config('qtype_datasetdependent', 'version')) {
$result = $result && unset_config('version', 'qtype_datasetdependent');
}
upgrade_plugin_savepoint($result, 2008091700, 'qtype', 'calculated');
}
// let if ($dbman->table_exists()) replace the normal $oldversion test
// as in any case the question question_calculated_options should be created
/// Define table question_calculated_options to be created
$table = new xmldb_table('question_calculated_options');
/// Adding fields to table question_calculated_options
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('question', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('synchronize', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
/// Adding keys to table question_calculated_options
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
/// Conditionally launch create table for question_calculated_options
if (!$dbman->table_exists($table)) {
$result = $dbman->create_table($table);
}
/// calculated savepoint reached
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of database_manager methods
/// upgrade_plugin_savepoint($result, YYYYMMDD00, 'qtype', 'calculated');
/// }
return $result;
}
示例2: test_reorder_rows
public function test_reorder_rows()
{
global $DB;
$dbman = $DB->get_manager();
$this->resetAfterTest();
$table = new xmldb_table('test_table');
$table->setComment("This is a test'n drop table. You can drop it safely");
$tablename = $table->getName();
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('otherid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('otherdata', XMLDB_TYPE_TEXT, 'big', null, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('unique', XMLDB_KEY_UNIQUE, array('otherid', 'sortorder'));
$dbman->create_table($table);
// Rows intentionally added in a slightly 'random' order.
// Note we are testing hat the otherid = 1 rows don't get messed up,
// as well as testing that the otherid = 2 rows are updated correctly.
$DB->insert_record($tablename, array('otherid' => 2, 'sortorder' => 1, 'otherdata' => 'To become 4'));
$DB->insert_record($tablename, array('otherid' => 2, 'sortorder' => 2, 'otherdata' => 'To become 1'));
$DB->insert_record($tablename, array('otherid' => 1, 'sortorder' => 1, 'otherdata' => 'Other 1'));
$DB->insert_record($tablename, array('otherid' => 1, 'sortorder' => 2, 'otherdata' => 'Other 2'));
$DB->insert_record($tablename, array('otherid' => 2, 'sortorder' => 3, 'otherdata' => 'To stay at 3'));
$DB->insert_record($tablename, array('otherid' => 2, 'sortorder' => 4, 'otherdata' => 'To become 2'));
update_field_with_unique_index($tablename, 'sortorder', array(1 => 4, 2 => 1, 3 => 3, 4 => 2), array('otherid' => 2));
$this->assertEquals(array(3 => (object) array('id' => 3, 'otherid' => 1, 'sortorder' => 1, 'otherdata' => 'Other 1'), 4 => (object) array('id' => 4, 'otherid' => 1, 'sortorder' => 2, 'otherdata' => 'Other 2')), $DB->get_records($tablename, array('otherid' => 1), 'sortorder'));
$this->assertEquals(array(2 => (object) array('id' => 2, 'otherid' => 2, 'sortorder' => 1, 'otherdata' => 'To become 1'), 6 => (object) array('id' => 6, 'otherid' => 2, 'sortorder' => 2, 'otherdata' => 'To become 2'), 5 => (object) array('id' => 5, 'otherid' => 2, 'sortorder' => 3, 'otherdata' => 'To stay at 3'), 1 => (object) array('id' => 1, 'otherid' => 2, 'sortorder' => 4, 'otherdata' => 'To become 4')), $DB->get_records($tablename, array('otherid' => 2), 'sortorder'));
}
示例3: xmldb_qtype_essay_upgrade
/**
* Upgrade code for the essay question type.
* @param int $oldversion the version we are upgrading from.
*/
function xmldb_qtype_essay_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2011031000) {
// Define table qtype_essay_options to be created
$table = new xmldb_table('qtype_essay_options');
// Adding fields to table qtype_essay_options
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('responseformat', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, 'editor');
$table->add_field('responsefieldlines', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '15');
$table->add_field('attachments', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
$table->add_field('graderinfo', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('graderinfoformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
// Adding keys to table qtype_essay_options
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id'));
// Conditionally launch create table for qtype_essay_options
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// essay savepoint reached
upgrade_plugin_savepoint(true, 2011031000, 'qtype', 'essay');
}
if ($oldversion < 2011060300) {
// Insert a row into the qtype_essay_options table for each existing essay question.
$DB->execute("\n INSERT INTO {qtype_essay_options} (questionid, responseformat,\n responsefieldlines, attachments, graderinfo, graderinfoformat)\n SELECT q.id, 'editor', 15, 0, '', " . FORMAT_MOODLE . "\n FROM {question} q\n WHERE q.qtype = 'essay'\n AND NOT EXISTS (\n SELECT 'x'\n FROM {qtype_essay_options} qeo\n WHERE qeo.questionid = q.id)");
// essay savepoint reached
upgrade_plugin_savepoint(true, 2011060300, 'qtype', 'essay');
}
// Moodle v2.1.0 release upgrade line
// Put any upgrade step following this
return true;
}
示例4: xmldb_local_contextadmin_upgrade
/**
* @package eclass-local-contextadmin
* @author joshstagg
* @copyright Josh Stagg
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_local_contextadmin_upgrade($oldversion)
{
global $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2013100813) {
// Adding fields to table.
$table = new xmldb_table('cat_role_names');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
$table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id');
$table->add_field('catid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'roleid');
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'catid');
// Add keys to table.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
$table->add_key('catid', XMLDB_KEY_FOREIGN, array('catid'), 'course_categories', array('id'));
// Add indices.
$table->add_index('roleid-catid', XMLDB_INDEX_UNIQUE, array('roleid', 'catid'));
// Conditionally launch add table.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
// Main savepoint reached.
upgrade_plugin_savepoint(true, 2013100813, 'local', 'contextadmin');
}
}
}
示例5: xmldb_mediaboard_upgrade
function xmldb_mediaboard_upgrade($oldversion = 0)
{
global $CFG, $THEME, $DB;
$result = true;
$dbman = $DB->get_manager();
if ($oldversion < 2015030200) {
// Define table assign_user_mapping to be created.
$table = new xmldb_table('mediaboard_likes');
// Adding fields to table assign_user_mapping.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('instance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('fileid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('time', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
// Adding keys to table assign_user_mapping.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
// Conditionally launch create table for assign_user_mapping.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Assign savepoint reached.
upgrade_mod_savepoint(true, 2015030200, 'mediaboard');
}
return $result;
}
示例6: xmldb_enrol_flatfile_upgrade
function xmldb_enrol_flatfile_upgrade($oldversion)
{
global $CFG, $DB;
$result = TRUE;
$dbman = $DB->get_manager();
if ($oldversion < 2010091400) {
// Define table enrol_flatfile to be created
$table = new xmldb_table('enrol_flatfile');
// Adding fields to table enrol_flatfile
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('action', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
$table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('timestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('timeend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
// Adding keys to table enrol_flatfile
$table->add_key('id', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('courseid-id', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->add_key('userid-id', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->add_key('roleid-id', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
// Conditionally launch create table for enrol_flatfile
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// flatfile savepoint reached
upgrade_plugin_savepoint(true, 2010091400, 'enrol', 'flatfile');
}
return $result;
}
示例7: xmldb_editor_atto_upgrade
/**
* Run all Atto upgrade steps between the current DB version and the current version on disk.
* @param int $oldversion The old version of atto in the DB.
* @return bool
*/
function xmldb_editor_atto_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2014032800) {
// Make Atto the default.
$currenteditors = $CFG->texteditors;
$neweditors = array();
$list = explode(',', $currenteditors);
array_push($neweditors, 'atto');
foreach ($list as $editor) {
if ($editor != 'atto') {
array_push($neweditors, $editor);
}
}
set_config('texteditors', implode(',', $neweditors));
upgrade_plugin_savepoint(true, 2014032800, 'editor', 'atto');
}
// Moodle v2.7.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2014081400) {
// Define table editor_atto_autosave to be created.
$table = new xmldb_table('editor_atto_autosave');
// Adding fields to table editor_atto_autosave.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('elementid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('pagehash', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('drafttext', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('draftid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('pageinstance', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
// Adding keys to table editor_atto_autosave.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('autosave_uniq_key', XMLDB_KEY_UNIQUE, array('elementid', 'contextid', 'userid', 'pagehash'));
// Conditionally launch create table for editor_atto_autosave.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Atto savepoint reached.
upgrade_plugin_savepoint(true, 2014081400, 'editor', 'atto');
}
if ($oldversion < 2014081900) {
// Define field timemodified to be added to editor_atto_autosave.
$table = new xmldb_table('editor_atto_autosave');
$field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'pageinstance');
// Conditionally launch add field timemodified.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Atto savepoint reached.
upgrade_plugin_savepoint(true, 2014081900, 'editor', 'atto');
}
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
示例8: xmldb_forum_upgrade
/**
* This file keeps track of upgrades to
* the forum module
*
* Sometimes, changes between versions involve
* alterations to database structures and other
* major things that may break installations.
*
* The upgrade function in this file will attempt
* to perform all the necessary actions to upgrade
* your older installation to the current version.
*
* If there's something it cannot do itself, it
* will tell you what you need to do.
*
* The commands in here will all be database-neutral,
* using the methods of database_manager class
*
* Please do not forget to use upgrade_set_timeout()
* before any action that may take longer time to finish.
*
* @package mod-forum
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_forum_upgrade($oldversion)
{
global $CFG, $DB, $OUTPUT;
$dbman = $DB->get_manager();
// Loads ddl manager and xmldb classes.
// Moodle v2.2.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.3.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.4.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2013020500) {
// Define field displaywordcount to be added to forum.
$table = new xmldb_table('forum');
$field = new xmldb_field('displaywordcount', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'completionposts');
// Conditionally launch add field displaywordcount.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Forum savepoint reached.
upgrade_mod_savepoint(true, 2013020500, 'forum');
}
// Forcefully assign mod/forum:allowforcesubscribe to frontpage role, as we missed that when
// capability was introduced.
if ($oldversion < 2013021200) {
// If capability mod/forum:allowforcesubscribe is defined then set it for frontpage role.
if (get_capability_info('mod/forum:allowforcesubscribe')) {
assign_legacy_capabilities('mod/forum:allowforcesubscribe', array('frontpage' => CAP_ALLOW));
}
// Forum savepoint reached.
upgrade_mod_savepoint(true, 2013021200, 'forum');
}
// Moodle v2.5.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2013071000) {
// Define table forum_digests to be created.
$table = new xmldb_table('forum_digests');
// Adding fields to table forum_digests.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('maildigest', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '-1');
// Adding keys to table forum_digests.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id'));
$table->add_key('forumdigest', XMLDB_KEY_UNIQUE, array('forum', 'userid', 'maildigest'));
// Conditionally launch create table for forum_digests.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Forum savepoint reached.
upgrade_mod_savepoint(true, 2013071000, 'forum');
}
// Moodle v2.6.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
示例9: xmldb_qtype_numerical_upgrade
function xmldb_qtype_numerical_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
//===== 1.9.0 upgrade line ======//
if ($oldversion < 2009100100) {
//New version in version.php
/// Define table question_numerical_options to be created
$table = new xmldb_table('question_numerical_options');
/// Adding fields to table question_numerical_options
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('question', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('instructions', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('showunits', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('unitsleft', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
$table->add_field('unitgradingtype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('unitpenalty', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0.1');
/// Adding keys to table question_numerical_options
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
/// Conditionally launch create table for question_calculated_options
if (!$dbman->table_exists($table)) {
// $dbman->create_table doesnt return a result, we just have to trust it
$dbman->create_table($table);
}
//else
upgrade_plugin_savepoint(true, 2009100100, 'qtype', 'numerical');
}
if ($oldversion < 2009100101) {
// Define field instructionsformat to be added to question_numerical_options
$table = new xmldb_table('question_numerical_options');
$field = new xmldb_field('instructionsformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'instructions');
// Conditionally launch add field instructionsformat
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// In the past, question_match_sub.questiontext assumed to contain
// content of the same form as question.questiontextformat. If we are
// using the HTML editor, then convert FORMAT_MOODLE content to FORMAT_HTML.
$rs = $DB->get_recordset_sql('
SELECT qno.*, q.oldquestiontextformat
FROM {question_numerical_options} qno
JOIN {question} q ON qno.question = q.id');
foreach ($rs as $record) {
if ($CFG->texteditors !== 'textarea' && $record->oldquestiontextformat == FORMAT_MOODLE) {
$record->instructions = text_to_html($record->questiontext, false, false, true);
$record->instructionsformat = FORMAT_HTML;
} else {
$record->instructionsformat = $record->oldquestiontextformat;
}
$DB->update_record('question_numerical_options', $record);
}
$rs->close();
// numerical savepoint reached
upgrade_plugin_savepoint(true, 2009100101, 'qtype', 'numerical');
}
return true;
}
示例10: xmldb_voiceshadow_upgrade
function xmldb_voiceshadow_upgrade($oldversion = 0)
{
global $CFG, $THEME, $DB;
$result = true;
$dbman = $DB->get_manager();
if ($oldversion < 2013030200) {
$table = new xmldb_table('voiceshadow');
$field = new xmldb_field('allowmultiple', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'emailteachers');
// Conditionally launch add field requiresubmissionstatement.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Assign savepoint reached.
upgrade_mod_savepoint(true, 2013030200, 'voiceshadow');
}
if ($oldversion < 2014030200) {
// Define table assign_user_mapping to be created.
$table = new xmldb_table('voiceshadow_likes');
// Adding fields to table assign_user_mapping.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('instance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('fileid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('time', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
// Adding keys to table assign_user_mapping.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
// Conditionally launch create table for assign_user_mapping.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Assign savepoint reached.
upgrade_mod_savepoint(true, 2014030200, 'voiceshadow');
}
if ($oldversion < 2014080400) {
// Define table assign_user_mapping to be created.
$table = new xmldb_table('voiceshadow');
$field = new xmldb_field('gradet', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, '0', 'grade');
// Conditionally launch add field.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('grademethodt', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'default', 'grademethod');
// Conditionally launch add field.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Assign savepoint reached.
upgrade_mod_savepoint(true, 2014080400, 'voiceshadow');
}
return $result;
}
示例11: xmldb_chat_upgrade
function xmldb_chat_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
if ($result && $oldversion < 2008072400) {
/// Define table chat_messages_current to be created
$table = new xmldb_table('chat_messages_current');
/// Adding fields to table chat_messages_current
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('chatid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('system', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('message', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
$table->add_field('timestamp', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
/// Adding keys to table chat_messages_current
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('chatid', XMLDB_KEY_FOREIGN, array('chatid'), 'chat', array('id'));
/// Adding indexes to table chat_messages_current
$table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
$table->add_index('groupid', XMLDB_INDEX_NOTUNIQUE, array('groupid'));
$table->add_index('timestamp-chatid', XMLDB_INDEX_NOTUNIQUE, array('timestamp', 'chatid'));
/// create table for chat_messages_current
$dbman->create_table($table);
/// chat savepoint reached
upgrade_mod_savepoint($result, 2008072400, 'chat');
}
if ($result && $oldversion < 2009010600) {
/// Changing precision of field ip on table chat_users to (45)
$table = new xmldb_table('chat_users');
$field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'version');
/// Launch change of precision for field ip
$dbman->change_field_precision($table, $field);
/// chat savepoint reached
upgrade_mod_savepoint($result, 2009010600, 'chat');
}
if ($result && $oldversion < 2009042000) {
/// Define field introformat to be added to chat
$table = new xmldb_table('chat');
$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);
/// chat savepoint reached
upgrade_mod_savepoint($result, 2009042000, 'chat');
}
return $result;
}
示例12: xmldb_editor_atto_upgrade
/**
* Run all Atto upgrade steps between the current DB version and the current version on disk.
* @param int $oldversion The old version of atto in the DB.
* @return bool
*/
function xmldb_editor_atto_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2014081400) {
// Define table editor_atto_autosave to be created.
$table = new xmldb_table('editor_atto_autosave');
// Adding fields to table editor_atto_autosave.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('elementid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('pagehash', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('drafttext', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('draftid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('pageinstance', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
// Adding keys to table editor_atto_autosave.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('autosave_uniq_key', XMLDB_KEY_UNIQUE, array('elementid', 'contextid', 'userid', 'pagehash'));
// Conditionally launch create table for editor_atto_autosave.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Atto savepoint reached.
upgrade_plugin_savepoint(true, 2014081400, 'editor', 'atto');
}
if ($oldversion < 2014081900) {
// Define field timemodified to be added to editor_atto_autosave.
$table = new xmldb_table('editor_atto_autosave');
$field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'pageinstance');
// Conditionally launch add field timemodified.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Atto savepoint reached.
upgrade_plugin_savepoint(true, 2014081900, 'editor', 'atto');
}
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.0.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
示例13: xmldb_message_popup_upgrade
/**
* Upgrade code for the popup message processor
*
* @param int $oldversion The version that we are upgrading from
*/
function xmldb_message_popup_upgrade($oldversion)
{
global $CFG, $DB;
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.0.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
$dbman = $DB->get_manager();
if ($oldversion < 2016052309) {
// Define table message_popup to be created.
$table = new xmldb_table('message_popup');
// Adding fields to table message_popup.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('messageid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('isread', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
// Adding keys to table message_popup.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Adding indexes to table message_popup.
$table->add_index('messageid-isread', XMLDB_INDEX_UNIQUE, array('messageid', 'isread'));
// Conditionally launch create table for message_popup.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Popup savepoint reached.
upgrade_plugin_savepoint(true, 2016052309, 'message', 'popup');
}
return true;
}
示例14: xmldb_tool_mergeusers_upgrade
/**
* Take actions on upgrading mergeusers tool.
* @package tool_mergeusers
* @global moodle_database $DB
* @param int $oldversion old plugin version.
* @return boolean true when success, false on error.
*/
function xmldb_tool_mergeusers_upgrade($oldversion)
{
global $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2013112912) {
// Define table tool_mergeusers to be created
$table = new xmldb_table('tool_mergeusers');
// Adding fields to table tool_mergeusers
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('touserid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('fromuserid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('success', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('log', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
// Adding keys to table tool_mergeusers
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Adding indexes to table tool_mergeusers
$table->add_index('mdl_toolmerg_tou_ix', XMLDB_INDEX_NOTUNIQUE, array('touserid'));
$table->add_index('mdl_toolmerg_fru_ix', XMLDB_INDEX_NOTUNIQUE, array('fromuserid'));
$table->add_index('mdl_toolmerg_suc_ix', XMLDB_INDEX_NOTUNIQUE, array('success'));
$table->add_index('mdl_toolmerg_tfs_ix', XMLDB_INDEX_NOTUNIQUE, array('touserid', 'fromuserid', 'success'));
// Conditionally launch create table for tool_mergeusersr
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// mergeusers savepoint reached
upgrade_plugin_savepoint(true, 2013112912, 'tool', 'mergeusers');
}
return true;
}
示例15: xmldb_quiz_overview_upgrade
function xmldb_quiz_overview_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
//===== 1.9.0 upgrade line ======//
if ($oldversion < 2009091400) {
/// Define table quiz_question_regrade to be created
$table = new xmldb_table('quiz_question_regrade');
/// Adding fields to table quiz_question_regrade
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('attemptid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('newgrade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, null);
$table->add_field('oldgrade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, null);
$table->add_field('regraded', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
/// Adding keys to table quiz_question_regrade
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Conditionally launch create table for quiz_question_regrade
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// overview savepoint reached
upgrade_plugin_savepoint(true, 2009091400, 'quizreport', 'overview');
}
return true;
}