当前位置: 首页>>代码示例>>PHP>>正文


PHP xmldb_index::set_attributes方法代码示例

本文整理汇总了PHP中xmldb_index::set_attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP xmldb_index::set_attributes方法的具体用法?PHP xmldb_index::set_attributes怎么用?PHP xmldb_index::set_attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xmldb_index的用法示例。


在下文中一共展示了xmldb_index::set_attributes方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: xmldb_main_upgrade


//.........这里部分代码省略.........
        }
        /// Define index idnumber (not unique) to be dropped form user
        $table = new xmldb_table('user');
        $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
        /// Launch drop index idnumber
        if ($dbman->index_exists($table, $index)) {
            $dbman->drop_index($table, $index);
        }
        /// Changing precision of field idnumber on table user to (255)
        $table = new xmldb_table('user');
        $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password');
        /// Launch change of precision for field idnumber
        $dbman->change_field_precision($table, $field);
        /// Launch add index idnumber again
        $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
        $dbman->add_index($table, $index);
        /// Main savepoint reached
        upgrade_main_savepoint(true, 2008051201);
    }
    if ($oldversion < 2008051203) {
        $table = new xmldb_table('mnet_enrol_course');
        $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
        $dbman->change_field_precision($table, $field);
        upgrade_main_savepoint(true, 2008051203);
    }
    if ($oldversion < 2008063001) {
        upgrade_set_timeout(60 * 20);
        // this may take a while
        // table to be modified
        $table = new xmldb_table('tag_instance');
        // add field
        $field = new xmldb_field('tiuserid');
        if (!$dbman->field_exists($table, $field)) {
            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
            $dbman->add_field($table, $field);
        }
        // modify index
        $index = new xmldb_index('itemtype-itemid-tagid');
        $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
        if ($dbman->index_exists($table, $index)) {
            $dbman->drop_index($table, $index);
        }
        $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
        $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }
        /// Main savepoint reached
        upgrade_main_savepoint(true, 2008063001);
    }
    if ($oldversion < 2008070300) {
        $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
        upgrade_main_savepoint(true, 2008070300);
    }
    if ($oldversion < 2008070701) {
        /// Define table portfolio_instance to be created
        $table = new xmldb_table('portfolio_instance');
        /// Adding fields to table portfolio_instance
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
        /// Adding keys to table portfolio_instance
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        /// Conditionally launch create table for portfolio_instance
        if (!$dbman->table_exists($table)) {
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:67,代码来源:upgrade.php

示例2: testDropIndex

 public function testDropIndex()
 {
     $DB = $this->tdb;
     // Do not use global $DB!
     $dbman = $this->tdb->get_manager();
     $table = $this->create_deftable('test_table1');
     $index = new xmldb_index('secondname');
     $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
     $dbman->add_index($table, $index);
     $dbman->drop_index($table, $index);
     $this->assertFalse($dbman->find_index_name($table, $index));
     // Test we are able to drop indexes having hyphens MDL-22804.
     // Create index with hyphens (by hand).
     $indexname = 'test-index-with-hyphens';
     switch ($DB->get_dbfamily()) {
         case 'mysql':
             $indexname = '`' . $indexname . '`';
             break;
         default:
             $indexname = '"' . $indexname . '"';
     }
     $stmt = "CREATE INDEX {$indexname} ON {$DB->get_prefix()}test_table1 (course, name)";
     $DB->change_database_structure($stmt);
     $this->assertNotEmpty($dbman->find_index_name($table, $index));
     // Index created, let's drop it using db manager stuff.
     $index = new xmldb_index('indexname', XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
     $dbman->drop_index($table, $index);
     $this->assertFalse($dbman->find_index_name($table, $index));
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:29,代码来源:ddl_test.php

示例3: testDropIndex

 public function testDropIndex()
 {
     $dbman = $this->tdb->get_manager();
     $table = $this->create_deftable('test_table1');
     $index = new xmldb_index('secondname');
     $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
     $dbman->add_index($table, $index);
     $dbman->drop_index($table, $index);
     $this->assertFalse($dbman->find_index_name($table, $index));
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:10,代码来源:testddl.php

示例4: xmldb_block_email_list_upgrade

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);
//.........这里部分代码省略.........
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:101,代码来源:upgrade.php

示例5: xmldb_block_helpmenow_upgrade

function xmldb_block_helpmenow_upgrade($oldversion = 0)
{
    global $CFG, $USER, $DB;
    $dbman = $DB->get_manager();
    $result = true;
    if ($result && $oldversion < 2012082101) {
        /// Define field notify to be added to block_helpmenow_message
        $table = new xmldb_table('block_helpmenow_message');
        $field = new xmldb_field('notify');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'message');
        /// Launch add field notify
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2012082102) {
        /// system messages are no longer using get_admin()->id for userid, but instead null
        $result = $result && $DB->set_field('block_helpmenow_message', 'userid', null, array('userid' => get_admin()->id));
    }
    if ($result && $oldversion < 2012082400) {
        /// Define field last_message to be added to block_helpmenow_session2user
        $table = new xmldb_table('block_helpmenow_session2user');
        $field = new xmldb_field('last_message');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'last_refresh');
        /// Launch add field last_message
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2012091200) {
        /// Define field last_message to be added to block_helpmenow_session
        $table = new xmldb_table('block_helpmenow_session');
        $field = new xmldb_field('last_message');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'timecreated');
        /// Launch add field last_message
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2012091400) {
        /// Changing the default of field last_message on table block_helpmenow_session2user to 0
        $table = new xmldb_table('block_helpmenow_session2user');
        $field = new xmldb_field('last_message');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, '0', 'last_refresh');
        /// Launch change of default for field last_message
        $result = $result && $dbman->change_field_default($table, $field);
        /// Changing the default of field last_message on table block_helpmenow_session to 0
        $table = new xmldb_table('block_helpmenow_session');
        $field = new xmldb_field('last_message');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, '0', 'timecreated');
        /// Launch change of default for field last_message
        $result = $result && $dbman->change_field_default($table, $field);
    }
    if ($result && $oldversion < 2012092100) {
        /// Define field lastaccess to be added to block_helpmenow_user
        $table = new xmldb_table('block_helpmenow_user');
        $field = new xmldb_field('lastaccess');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'motd');
        /// Launch add field lastaccess
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2012121900) {
        /// Define field optimistic_last_message to be added to block_helpmenow_session2user
        $table = new xmldb_table('block_helpmenow_session2user');
        $field = new xmldb_field('optimistic_last_message');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'last_message');
        /// Launch add field optimistic_last_message
        $result = $result && $dbman->add_field($table, $field);
        /// Define field cache to be added to block_helpmenow_session2user
        $table = new xmldb_table('block_helpmenow_session2user');
        $field = new xmldb_field('cache');
        $field->set_attributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, 'optimistic_last_message');
        /// Launch add field cache
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2012122700) {
        /// Define table block_helpmenow_error_log to be created
        $table = new xmldb_table('block_helpmenow_error_log');
        /// Adding fields to table block_helpmenow_error_log
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('error', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('details', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null);
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        /// Adding keys to table block_helpmenow_error_log
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        /// Launch create table for block_helpmenow_error_log
        $result = $result && $dbman->create_table($table);
    }
    if ($result && $oldversion < 2012123100) {
        /// Define field userid to be added to block_helpmenow_error_log
        $table = new xmldb_table('block_helpmenow_error_log');
        $field = new xmldb_field('userid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null, 'timecreated');
        /// Launch add field userid
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2013011800) {
        /// Define table block_helpmenow_contact to be created
        $table = new xmldb_table('block_helpmenow_contact');
        /// Adding fields to table block_helpmenow_contact
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('contact_userid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        /// Adding keys to table block_helpmenow_contact
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
//.........这里部分代码省略.........
开发者ID:anilch,项目名称:Personel,代码行数:101,代码来源:upgrade.php

示例6: xmldb_facetoface_upgrade

function xmldb_facetoface_upgrade($oldversion = 0)
{
    global $CFG, $USER, $DB;
    $dbman = $DB->get_manager();
    // Loads ddl manager and xmldb classes.
    require_once $CFG->dirroot . '/mod/facetoface/lib.php';
    $result = true;
    if ($result && $oldversion < 2008050500) {
        $table = new xmldb_table('facetoface');
        $field = new xmldb_field('thirdpartywaitlist');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'thirdparty');
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2008061000) {
        $table = new xmldb_table('facetoface_submissions');
        $field = new xmldb_field('notificationtype');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified');
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2008080100) {
        echo $OUTPUT->notification(get_string('upgradeprocessinggrades', 'facetoface'), 'notifysuccess');
        require_once $CFG->dirroot . '/mod/facetoface/lib.php';
        $transaction = $DB->start_delegated_transaction();
        $DB->debug = false;
        // Too much debug output.
        // Migrate the grades to the gradebook.
        $sql = "SELECT f.id, f.name, f.course, s.grade, s.timegraded, s.userid,\n            cm.idnumber as cmidnumber\n            FROM {facetoface_submissions} s\n            JOIN {facetoface} f ON s.facetoface = f.id\n            JOIN {course_modules} cm ON cm.instance = f.id\n            JOIN {modules} m ON m.id = cm.module\n            WHERE m.name='facetoface'";
        if ($rs = $DB->get_recordset_sql($sql)) {
            foreach ($rs as $facetoface) {
                $grade = new stdclass();
                $grade->userid = $facetoface->userid;
                $grade->rawgrade = $facetoface->grade;
                $grade->rawgrademin = 0;
                $grade->rawgrademax = 100;
                $grade->timecreated = $facetoface->timegraded;
                $grade->timemodified = $facetoface->timegraded;
                $result = $result && GRADE_UPDATE_OK == facetoface_grade_item_update($facetoface, $grade);
            }
            $rs->close();
        }
        $DB->debug = true;
        // Remove the grade and timegraded fields from facetoface_submissions.
        if ($result) {
            $table = new xmldb_table('facetoface_submissions');
            $field1 = new xmldb_field('grade');
            $field2 = new xmldb_field('timegraded');
            $result = $result && $dbman->drop_field($table, $field1, false, true);
            $result = $result && $dbman->drop_field($table, $field2, false, true);
        }
        $transaction->allow_commit();
    }
    if ($result && $oldversion < 2008090800) {
        // Define field timemodified to be added to facetoface_submissions.
        $table = new xmldb_table('facetoface_submissions');
        $field = new xmldb_field('timecancelled');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'timemodified');
        // Launch add field.
        $result = $result && $dbman->add_field($table, $field);
    }
    if ($result && $oldversion < 2009111300) {
        // New fields necessary for the training calendar.
        $table = new xmldb_table('facetoface');
        $field1 = new xmldb_field('shortname');
        $field1->set_attributes(XMLDB_TYPE_CHAR, '32', null, null, null, null, 'timemodified');
        $result = $result && $dbman->add_field($table, $field1);
        $field2 = new xmldb_field('description');
        $field2->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'shortname');
        $result = $result && $dbman->add_field($table, $field2);
        $field3 = new xmldb_field('showoncalendar');
        $field3->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'description');
        $result = $result && $dbman->add_field($table, $field3);
    }
    if ($result && $oldversion < 2009111600) {
        $table1 = new xmldb_table('facetoface_session_field');
        $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table1->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table1->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table1->add_field('type', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table1->add_field('possiblevalues', XMLDB_TYPE_TEXT, 'medium', null, null, null, null);
        $table1->add_field('required', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table1->add_field('defaultvalue', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table1->add_field('isfilter', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
        $table1->add_field('showinsummary', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
        $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $result = $result && $dbman->create_table($table1);
        $table2 = new xmldb_table('facetoface_session_data');
        $table2->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table2->add_field('fieldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table2->add_field('sessionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table2->add_field('data', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $result = $result && $dbman->create_table($table2);
    }
    if ($result && $oldversion < 2009111900) {
        // Remove unused field.
        $table = new xmldb_table('facetoface_sessions');
        $field = new xmldb_field('closed');
        $result = $result && $dbman->drop_field($table, $field);
    }
    // Migration of old Location, Venue and Room fields.
//.........这里部分代码省略.........
开发者ID:CWRTP,项目名称:facetoface-2.0,代码行数:101,代码来源:upgrade.php

示例7: xmldb_referentiel_upgrade

/**
 * This file keeps track of upgrades to
 * the referentiel 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}
 * @copyright 2011 onwards Jean Fruitet(jfruitet) {@link http://www.univ-nantes.fr}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function xmldb_referentiel_upgrade($oldversion)
{
    global $CFG, $DB, $OUTPUT;
    $dbman = $DB->get_manager();
    // loads ddl manager and xmldb classes
    // VERSION Moodle 2.x
    /// Add intro to table referentiel description
    $table = new xmldb_table('referentiel');
    /// Adding fields
    $field = new xmldb_field('intro');
    $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'config_impression');
    if (!$dbman->field_exists($table, $field)) {
        $dbman->add_field($table, $field);
        $rs = $DB->get_recordset_sql("SELECT * FROM {referentiel}", null);
        foreach ($rs as $res) {
            if (!empty($res->description_instance)) {
                $res->intro = $res->description_instance;
            }
            $DB->update_record('referentiel', $res);
        }
        $rs->close();
    }
    /// Adding fields
    $field = new xmldb_field('introformat');
    $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'intro');
    if (!$dbman->field_exists($table, $field)) {
        $dbman->add_field($table, $field);
    }
    /// And upgrade begins here.
    //===== 1.9.0 upgrade line ======//
    if ($oldversion < 2008052700) {
        /// Define field evaluation to be added to referentiel_certificat
        $table = new xmldb_table('referentiel_certificat');
        $field = new xmldb_field('evaluation');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'valide');
        /// Launch add field evaluation
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2008052700, 'referentiel');
    }
    if ($oldversion < 2008052800) {
        /// Define field logo_etablissement to be added to referentiel_etablissement
        $table = new xmldb_table('referentiel_etablissement');
        $field = new xmldb_field('logo_etablissement');
        $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'adresse_etablissement');
        /// Launch add field referentiel_etablissement
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        /// Add some values to referentiel_etablissement
        $rec = new stdClass();
        $rec->num_etablissement = 'INCONNU';
        $rec->nom_etablissement = 'A COMPLETER';
        $rec->adresse_etablissement = 'A COMPLETER';
        $rec->logo_etablissement = ' ';
        /// Insert the add action in log_display
        $DB->insert_record('referentiel_etablissement', $rec, false, false);
        upgrade_mod_savepoint(true, 2008052800, 'referentiel');
    }
    if ($oldversion < 2008062300) {
        // VERSION 1.2
        /// Define new  field liste_codes_competence to be added to referentiel_referentiel
        $table1 = new xmldb_table('referentiel_referentiel');
        $field1 = new xmldb_field('liste_codes_competence');
        $field1->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'nb_domaines');
        /// Launch add field referentiel_referentiel
        if (!$dbman->field_exists($table1, $field1)) {
            $dbman->add_field($table1, $field1);
        }
        /// Define new  field liste_empreintes_competence to be added to referentiel_referentiel
        $field2 = new xmldb_field('liste_empreintes_competence');
        $field2->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'liste_codes_competence');
        /// Launch add field referentiel_referentiel
//.........这里部分代码省略.........
开发者ID:jfruitet,项目名称:moodle_referentiel,代码行数:101,代码来源:upgrade.php

示例8: xmldb_questionnaire_upgrade

function xmldb_questionnaire_upgrade($oldversion = 0)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    // Loads ddl manager and xmldb classes.
    $result = true;
    if ($oldversion < 2007120101) {
        $result &= questionnaire_upgrade_2007120101();
        // Questionnaire savepoint reached.
        upgrade_mod_savepoint(true, 2007120101, 'questionnaire');
    }
    if ($oldversion < 2007120102) {
        // Change enum values to lower case for all tables using them.
        $enumvals = array('y', 'n');
        $table = new xmldb_table('questionnaire_question');
        $field = new xmldb_field('required');
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, false, null, 'n');
        $dbman->change_field_enum($table, $field);
        $DB->set_field('questionnaire_question', 'required', 'y', array('required' => 'Y'));
        $DB->set_field('questionnaire_question', 'required', 'n', array('required' => 'N'));
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, XMLDB_ENUM, array('y', 'n'), 'n');
        $dbman->change_field_enum($table, $field);
        $dbman->change_field_default($table, $field);
        unset($field);
        $field = new xmldb_field('deleted');
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, false, null, 'n');
        $dbman->change_field_enum($table, $field);
        $DB->set_field('questionnaire_question', 'deleted', 'y', array('deleted' => 'Y'));
        $DB->set_field('questionnaire_question', 'deleted', 'n', array('deleted' => 'N'));
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, XMLDB_ENUM, array('y', 'n'), 'n');
        $dbman->change_field_enum($table, $field);
        $dbman->change_field_default($table, $field);
        unset($field);
        $field = new xmldb_field('public');
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, false, null, 'n');
        $dbman->change_field_enum($table, $field);
        $DB->set_field('questionnaire_question', 'public', 'y', array('public' => 'Y'));
        $DB->set_field('questionnaire_question', 'public', 'n', array('public' => 'N'));
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, XMLDB_ENUM, array('y', 'n'), 'y');
        $dbman->change_field_enum($table, $field);
        $dbman->change_field_default($table, $field);
        unset($field);
        unset($table);
        $table = new xmldb_table('questionnaire_question_type');
        $field = new xmldb_field('has_choices');
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, false, null, 'n');
        $dbman->change_field_enum($table, $field);
        $DB->set_field('questionnaire_question_type', 'has_choices', 'y', array('has_choices' => 'Y'));
        $DB->set_field('questionnaire_question_type', 'has_choices', 'n', array('has_choices' => 'N'));
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, XMLDB_ENUM, array('y', 'n'), 'y');
        $dbman->change_field_enum($table, $field);
        $dbman->change_field_default($table, $field);
        unset($field);
        unset($table);
        $table = new xmldb_table('questionnaire_response');
        $field = new xmldb_field('complete');
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, false, null, 'n');
        $dbman->change_field_enum($table, $field);
        $DB->set_field('questionnaire_response', 'complete', 'y', array('complete' => 'Y'));
        $DB->set_field('questionnaire_response', 'complete', 'n', array('complete' => 'N'));
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, XMLDB_ENUM, array('y', 'n'), 'n');
        $dbman->change_field_enum($table, $field);
        $dbman->change_field_default($table, $field);
        unset($field);
        unset($table);
        $table = new xmldb_table('questionnaire_response_bool');
        $field = new xmldb_field('choice_id');
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, false, null, 'n');
        $dbman->change_field_enum($table, $field);
        $DB->set_field('questionnaire_response_bool', 'choice_id', 'y', array('choice_id' => 'Y'));
        $DB->set_field('questionnaire_response_bool', 'choice_id', 'n', array('choice_id' => 'N'));
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, XMLDB_ENUM, array('y', 'n'), 'y');
        $dbman->change_field_enum($table, $field);
        $dbman->change_field_default($table, $field);
        unset($field);
        unset($table);
        $table = new xmldb_table('questionnaire_survey');
        $field = new xmldb_field('public');
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, false, null, 'n');
        $dbman->change_field_enum($table, $field);
        $DB->set_field('questionnaire_survey', 'public', 'y', array('public' => 'Y'));
        $DB->set_field('questionnaire_survey', 'public', 'n', array('public' => 'N'));
        $field->set_attributes(XMLDB_TYPE_CHAR, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, XMLDB_ENUM, array('y', 'n'), 'y');
        $dbman->change_field_enum($table, $field);
        $dbman->change_field_default($table, $field);
        unset($field);
        // Upgrade question_type table with corrected 'response_table' fields.
        $DB->set_field('questionnaire_question_type', 'response_table', 'resp_single', array('response_table' => 'response_single'));
        $DB->set_field('questionnaire_question_type', 'response_table', 'resp_multiple', array('response_table' => 'response_multiple'));
        // Questionnaire savepoint reached..
        upgrade_mod_savepoint(true, 2007120102, 'questionnaire');
    }
    if ($oldversion < 2008031902) {
        $table = new xmldb_table('questionnaire');
        $field = new xmldb_field('grade');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', false, true, false, false, null, 0, 'navigate');
        $dbman->add_field($table, $field);
        unset($field);
        unset($table);
        $table = new xmldb_table('questionnaire_response');
//.........这里部分代码省略.........
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:101,代码来源:upgrade.php

示例9: xmldb_teambuilder_upgrade

function xmldb_teambuilder_upgrade($oldversion = 0)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    /// 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 < YYYYMMDD00) { //New version in version.php
    ///     $result = result of "/lib/ddllib.php" function calls
    /// }
    /// Lines below (this included)  MUST BE DELETED once you get the first version
    /// of your module ready to be installed. They are here only
    /// for demonstrative purposes and to show how the teambuilder
    /// iself has been upgraded.
    /// For each upgrade block, the file teambuilder/version.php
    /// needs to be updated . Such change allows Moodle to know
    /// that this file has to be processed.
    /// To know more about how to write correct DB upgrade scripts it's
    /// highly recommended to read information available at:
    ///   http://docs.moodle.org/en/Development:XMLDB_Documentation
    /// and to play with the XMLDB Editor (in the admin menu) and its
    /// PHP generation posibilities.
    /// First example, some fields were added to the module on 20070400
    if ($oldversion < 2007040100) {
        /// Define field course to be added to teambuilder
        $table = new xmldb_table('teambuilder');
        $field = new xmldb_field('course');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
        /// Launch add field course
        $dbman->add_field($table, $field);
        /// Define field intro to be added to teambuilder
        $table = new xmldb_table('teambuilder');
        $field = new xmldb_field('intro');
        $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'name');
        /// Launch add field intro
        $dbman->add_field($table, $field);
        /// Define field introformat to be added to teambuilder
        $table = new xmldb_table('teambuilder');
        $field = new xmldb_field('introformat');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
        /// Launch add field introformat
        $dbman->add_field($table, $field);
        upgrade_mod_savepoint(true, 2007040100, 'teambuilder');
    }
    /// Second example, some hours later, the same day 20070401
    /// two more fields and one index were added (note the increment
    /// "01" in the last two digits of the version
    if ($oldversion < 2007040101) {
        /// Define field timecreated to be added to teambuilder
        $table = new xmldb_table('teambuilder');
        $field = new xmldb_field('timecreated');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'introformat');
        /// Launch add field timecreated
        $dbman->add_field($table, $field);
        /// Define field timemodified to be added to teambuilder
        $table = new xmldb_table('teambuilder');
        $field = new xmldb_field('timemodified');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timecreated');
        /// Launch add field timemodified
        $dbman->add_field($table, $field);
        /// Define index course (not unique) to be added to teambuilder
        $table = new xmldb_table('teambuilder');
        $index = new xmldb_index('course');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
        /// Launch add index course
        $dbman->add_index($table, $index);
        upgrade_mod_savepoint(true, 2007040101, 'teambuilder');
    }
    /// Third example, the next day, 20070402 (with the trailing 00), some inserts were performed, related with the module
    if ($oldversion < 2007040200) {
        /// Add some actions to get them properly displayed in the logs
        $rec = new stdClass();
        $rec->module = 'teambuilder';
        $rec->action = 'add';
        $rec->mtable = 'teambuilder';
        $rec->filed = 'name';
        /// Insert the add action in log_display
        $DB->insert_record('log_display', $rec);
        /// Now the update action
        $rec->action = 'update';
        $DB->insert_record('log_display', $rec);
        /// Now the view action
        $rec->action = 'view';
        $DB->insert_record('log_display', $rec);
        upgrade_mod_savepoint(true, 2007040200, 'teambuilder');
    }
    if ($oldversion < 2011051702) {
        $table = new xmldb_table('teambuilder');
        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
        // Launch add field introformat
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2011051702, 'teambuilder');
    }
    /// And that's all. Please, examine and understand the 3 example blocks above. Also
    /// it's interesting to look how other modules are using this script. Remember that
    /// the basic idea is to have "blocks" of code (each one being executed only once,
    /// when the module version (version.php) is updated.
//.........这里部分代码省略.........
开发者ID:netspotau,项目名称:moodle-mod_teambuilder,代码行数:101,代码来源:upgrade.php

示例10: xmldb_main_upgrade


//.........这里部分代码省略.........
        /// Launch change of precision for field idnumber
        $dbman->change_field_precision($table, $field);
        /// Launch add index idnumber again
        $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
        $dbman->add_index($table, $index);
        /// Main savepoint reached
        upgrade_main_savepoint($result, 2008051201);
    }
    if ($result && $oldversion < 2008051202) {
        $log_action = new object();
        $log_action->module = 'course';
        $log_action->action = 'unenrol';
        $log_action->mtable = 'course';
        $log_action->field = 'fullname';
        if (!$DB->record_exists('log_display', array('action' => 'unenrol', 'module' => 'course'))) {
            $result = $result && $DB->insert_record('log_display', $log_action);
        }
        upgrade_main_savepoint($result, 2008051202);
    }
    if ($result && $oldversion < 2008051203) {
        $table = new xmldb_table('mnet_enrol_course');
        $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
        $dbman->change_field_precision($table, $field);
        upgrade_main_savepoint($result, 2008051203);
    }
    if ($result && $oldversion < 2008063001) {
        upgrade_set_timeout(60 * 20);
        // this may take a while
        // table to be modified
        $table = new xmldb_table('tag_instance');
        // add field
        $field = new xmldb_field('tiuserid');
        if (!$dbman->field_exists($table, $field)) {
            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
            $dbman->add_field($table, $field);
        }
        // modify index
        $index = new xmldb_index('itemtype-itemid-tagid');
        $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
        if ($dbman->index_exists($table, $index)) {
            $dbman->drop_index($table, $index);
        }
        $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
        $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }
        /// Main savepoint reached
        upgrade_main_savepoint($result, 2008063001);
    }
    if ($result && $oldversion < 2008070300) {
        $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
        upgrade_main_savepoint($result, 2008070300);
    }
    if ($result && $oldversion < 2008070700) {
        if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) {
            // guest can not be selected in defaultuserroleid!
            unset_config('defaultuserroleid');
        }
        upgrade_main_savepoint($result, 2008070700);
    }
    if ($result && $oldversion < 2008070701) {
        /// Define table portfolio_instance to be created
        $table = new xmldb_table('portfolio_instance');
        /// Adding fields to table portfolio_instance
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
开发者ID:ajv,项目名称:Offline-Caching,代码行数:67,代码来源:upgrade.php

示例11: xmldb_block_lockdownbrowser_upgrade

function xmldb_block_lockdownbrowser_upgrade($oldversion = 0)
{
    global $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2012082000) {
        // table names limited to 28 characters in Moodle 2.3+
        $table = new xmldb_table("block_lockdownbrowser_settings");
        if ($dbman->table_exists($table)) {
            $dbman->rename_table($table, "block_lockdownbrowser_sett");
        }
        $table = new xmldb_table("block_lockdownbrowser_tokens");
        if ($dbman->table_exists($table)) {
            $dbman->rename_table($table, "block_lockdownbrowser_toke");
        }
        $table = new xmldb_table("block_lockdownbrowser_sessions");
        if ($dbman->table_exists($table)) {
            $dbman->rename_table($table, "block_lockdownbrowser_sess");
        }
        upgrade_block_savepoint(true, 2012082000, "lockdownbrowser");
    }
    if ($oldversion < 2013011800) {
        $table = new xmldb_table("block_lockdownbrowser");
        $index = new xmldb_index("course_ix");
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array("course"));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }
        $table = new xmldb_table("block_lockdownbrowser_sett");
        $field = new xmldb_field("course", XMLDB_TYPE_INTEGER, "10", XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, "id");
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field("monitor", XMLDB_TYPE_TEXT, "small", null, null, null, null, "password");
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $index = new xmldb_index("course_ix");
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array("course"));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }
        $index = new xmldb_index("quiz_ix");
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array("quizid"));
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }
        upgrade_block_savepoint(true, 2013011800, "lockdownbrowser");
    }
    if ($oldversion < 2013012800) {
        // no db stuff to upgrade
    }
    if ($oldversion < 2013020500) {
        // no db stuff to upgrade
    }
    if ($oldversion < 2013021500) {
        // no db stuff to upgrade
    }
    if ($oldversion < 2013022000) {
        // no db stuff to upgrade
    }
    if ($oldversion < 2013022100) {
        // no db stuff to upgrade
    }
    if ($oldversion < 2013022800) {
        // no db stuff to upgrade
    }
    if ($oldversion < 2013031900) {
        // no db stuff to upgrade
    }
    if ($oldversion < 2013032600) {
        // no db stuff to upgrade
    }
    return true;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:74,代码来源:upgrade.php

示例12: xmldb_facetoface_upgrade

function xmldb_facetoface_upgrade($oldversion=0) {
    global $CFG, $USER, $DB, $OUTPUT;

    $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes

    require_once($CFG->dirroot . '/mod/facetoface/lib.php');

    $result = true;

    if ($result && $oldversion < 2008050500) {
        $table = new xmldb_table('facetoface');
        $field = new xmldb_field('thirdpartywaitlist');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'thirdparty');
        $result = $result && $dbman->add_field($table, $field);
    }

    if ($result && $oldversion < 2008061000) {
        $table = new xmldb_table('facetoface_submissions');
        $field = new xmldb_field('notificationtype');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timemodified');
        $result = $result && $dbman->add_field($table, $field);
    }

    if ($result && $oldversion < 2008080100) {
        echo $OUTPUT->notification(get_string('upgradeprocessinggrades', 'facetoface'), 'notifysuccess');
        require_once $CFG->dirroot.'/mod/facetoface/lib.php';

        $transaction = $DB->start_delegated_transaction();
        $DB->debug = false; // too much debug output

        // Migrate the grades to the gradebook
        $sql = "SELECT f.id, f.name, f.course, s.grade, s.timegraded, s.userid,
            cm.idnumber as cmidnumber
            FROM {facetoface_submissions} s
            JOIN {facetoface} f ON s.facetoface = f.id
            JOIN {course_modules} cm ON cm.instance = f.id
            JOIN {modules} m ON m.id = cm.module
            WHERE m.name='facetoface'";
        if ($rs = $DB->get_recordset_sql($sql)) {
            foreach ($rs as $facetoface) {
                $grade = new stdclass();
                $grade->userid = $facetoface->userid;
                $grade->rawgrade = $facetoface->grade;
                $grade->rawgrademin = 0;
                $grade->rawgrademax = 100;
                $grade->timecreated = $facetoface->timegraded;
                $grade->timemodified = $facetoface->timegraded;

                $result = $result && (GRADE_UPDATE_OK == facetoface_grade_item_update($facetoface, $grade));
            }
            $rs->close();
        }
        $DB->debug = true;

        // Remove the grade and timegraded fields from facetoface_submissions
        if ($result) {
            $table = new xmldb_table('facetoface_submissions');
            $field1 = new xmldb_field('grade');
            $field2 = new xmldb_field('timegraded');
            $result = $result && $dbman->drop_field($table, $field1, false, true);
            $result = $result && $dbman->drop_field($table, $field2, false, true);
        }

        $transaction->allow_commit();
    }

    if ($result && $oldversion < 2008090800) {

        // Define field timemodified to be added to facetoface_submissions
        $table = new xmldb_table('facetoface_submissions');
        $field = new xmldb_field('timecancelled');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, 0, 'timemodified');

        // Launch add field
        $result = $result && $dbman->add_field($table, $field);
    }

    if ($result && $oldversion < 2009111300) {
        // New fields necessary for the training calendar
        $table = new xmldb_table('facetoface');
        $field1 = new xmldb_field('shortname');
        $field1->set_attributes(XMLDB_TYPE_CHAR, '32', null, null, null, null, 'timemodified');
        $result = $result && $dbman->add_field($table, $field1);

        $field2 = new xmldb_field('description');
        $field2->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'shortname');
        $result = $result && $dbman->add_field($table, $field2);

        $field3 = new xmldb_field('showoncalendar');
        $field3->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'description');
        $result = $result && $dbman->add_field($table, $field3);
    }

    if ($result && $oldversion < 2009111600) {

        $table1 = new xmldb_table('facetoface_session_field');
        $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table1->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table1->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table1->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
//.........这里部分代码省略.........
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:101,代码来源:upgrade.php

示例13: invoke


//.........这里部分代码省略.........
         /// 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);
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:67,代码来源:test.class.php

示例14: xmldb_attforblock_upgrade

function xmldb_attforblock_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $DB;
    $dbman = $DB->get_manager();
    /// loads ddl manager and xmldb classes
    $result = 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 ($oldversion < 2008021904) {
        //New version in version.php
        global $USER;
        if ($sessions = $DB->get_records('attendance_sessions', array('takenby' => 0))) {
            foreach ($sessions as $sess) {
                if ($DB->count_records('attendance_log', array('attsid' => $sess->id)) > 0) {
                    $sess->takenby = $USER->id;
                    $sess->timetaken = $sess->timemodified ? $sess->timemodified : time();
                    $sess->description = addslashes($sess->description);
                    $result = $DB->update_record('attendance_sessions', $sess) and $result;
                }
            }
        }
        upgrade_mod_savepoint(true, 2008021904, 'attforblock');
    }
    if ($oldversion < 2008102401) {
        $table = new xmldb_table('attforblock');
        $field = new xmldb_field('grade');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '100', 'name');
        $dbman->add_field($table, $field);
        $table = new xmldb_table('attendance_sessions');
        $field = new xmldb_field('courseid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
        $dbman->change_field_unsigned($table, $field);
        //        $field = new xmldb_field('creator');
        //        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid');
        //        change_field_unsigned($table, $field);
        $field = new xmldb_field('sessdate');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'creator');
        $dbman->change_field_unsigned($table, $field);
        $field = new xmldb_field('duration');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'sessdate');
        $dbman->add_field($table, $field);
        $field = new xmldb_field('timetaken');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'takenby');
        $dbman->change_field_unsigned($table, $field);
        $dbman->rename_field($table, $field, 'lasttaken');
        $field = new xmldb_field('takenby');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lasttaken');
        $dbman->change_field_unsigned($table, $field);
        $dbman->rename_field($table, $field, 'lasttakenby');
        $field = new xmldb_field('timemodified');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'lasttaken');
        $dbman->change_field_unsigned($table, $field);
        $table = new xmldb_table('attendance_log');
        $field = new xmldb_field('attsid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
        $dbman->change_field_unsigned($table, $field);
        $field = new xmldb_field('studentid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'attsid');
        $dbman->change_field_unsigned($table, $field);
        $field = new xmldb_field('statusid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'status');
        $dbman->add_field($table, $field);
        $field = new xmldb_field('statusset');
        $field->set_attributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, 'statusid');
        $dbman->add_field($table, $field);
        $field = new xmldb_field('timetaken');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'statusid');
        $dbman->add_field($table, $field);
        $field = new xmldb_field('takenby');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timetaken');
        $dbman->add_field($table, $field);
        //Indexes
        $index = new xmldb_index('statusid');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('statusid'));
        $dbman->add_index($table, $index);
        $index = new xmldb_index('attsid');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('attsid'));
        $dbman->drop_index($table, $index);
        $field = new xmldb_field('attsid');
        //Rename field
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
        $dbman->rename_field($table, $field, 'sessionid');
        $index = new xmldb_index('sessionid');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid'));
        $dbman->add_index($table, $index);
        $table = new xmldb_table('attendance_settings');
        $field = new xmldb_field('courseid');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
        $dbman->change_field_unsigned($table, $field);
        $field = new xmldb_field('visible');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'grade');
        $dbman->add_field($table, $field);
        $field = new xmldb_field('deleted');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'visible');
        $dbman->add_field($table, $field);
        //Indexes
        $index = new xmldb_index('visible');
        $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('visible'));
//.........这里部分代码省略.........
开发者ID:e-rasvet,项目名称:attforblockup,代码行数:101,代码来源:upgrade.php


注:本文中的xmldb_index::set_attributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。