Ejemplo n.º 1
0
function xmldb_assignment_team_upgrade($oldversion)
{
    global $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2011013000) {
        //add table 'assignment_team'
        $table1 = new XMLDBTable('assignment_team');
        $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_NOTNULL, XMLDB_UNSIGNED, XMLDB_SEQUENCE, 'assignment');
        $table1->add_field('assignment', XMLDB_TYPE_INTEGER, '10', XMLDB_NOTNULL, XMLDB_UNSIGNED, XMLDB_SEQUENCE, 'id', 'name');
        $table1->add_field('name', XMLDB_TYPE_CHAR, '100', XMLDB_NOTNULL, XMLDB_SEQUENCE, 'assignment', 'membershipopen');
        $table1->add_field('membershipopen', XMLDB_TYPE_INTEGER, '1', XMLDB_NOTNULL, XMLDB_UNSIGNED, XMLDB_SEQUENCE, 'name', 'timemodified');
        $table1->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_NOTNULL, XMLDB_UNSIGNED, XMLDB_SEQUENCE, 'membershipopen');
        $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table1->add_key('assignment', XMLDB_KEY_FOREIGN, array('assignment'));
        if (!$dbman->table_exists($table1)) {
            $dbman->create_table($table1);
        }
        //add table 'assignment_team_student'
        $table2 = new XMLDBTable('assignment_team_student');
        $table2->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_NOTNULL, XMLDB_UNSIGNED, XMLDB_SEQUENCE, 'true');
        $table2->add_field('student', XMLDB_TYPE_INTEGER, '10', XMLDB_NOTNULL, XMLDB_UNSIGNED, XMLDB_SEQUENCE, 'id', 'team');
        $table2->add_field('team', XMLDB_TYPE_INTEGER, '10', XMLDB_NOTNULL, XMLDB_UNSIGNED, XMLDB_SEQUENCE, 'student', 'timemodified');
        $table2->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_NOTNULL, XMLDB_UNSIGNED, XMLDB_SEQUENCE, 'team');
        $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table2->add_key('student', XMLDB_KEY_FOREIGN, array('student'));
        $table2->add_key('team', XMLDB_KEY_FOREIGN, array('team'));
        $table2->add_index('student-team', XMLDB_INDEX_UNIQUE, array('student', 'team'));
        if (!$dbman->table_exists($table2)) {
            $dbman->create_table($table2);
        }
        upgrade_plugin_savepoint(true, 2011013000, 'assignment', 'team');
    }
    return true;
}
Ejemplo n.º 2
0
function xmldb_hotquestion_upgrade($oldversion = 0)
{
    global $CFG, $DB;
    $result = true;
    //===== 1.9.0 upgrade line ======//
    if ($result && $oldversion < 2007040100) {
        /// Define field course to be added to hotquestion
        $table = new XMLDBTable('hotquestion');
        $field = new XMLDBField('course');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
        /// Launch add field course
        $result = $result && $table->add_field($field);
        /// Define field intro to be added to hotquestion
        $field = new xmldb_field('intro');
        $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'name');
        /// Launch add field intro
        $result = $result && $table->add_field($field);
        /// Define field introformat to be added to hotquestion
        $field = new xmldb_field('introformat');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'intro');
        /// Launch add field introformat
        $result = $result && $table->add_field($field);
    }
    if ($result && $oldversion < 2007040101) {
        /// Define field timecreated to be added to hotquestion
        $table = new xmldb_table('hotquestion');
        $field = new xmldb_field('timecreated');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'introformat');
        /// Launch add field timecreated
        $result = $result && $table->add_field($field);
        $field = new xmldb_field('timemodified');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timecreated');
        /// Launch add field timemodified
        $result = $result && $table->add_field($table, $field);
        /// Define index course (not unique) to be added to hotquestion
        $result = $result && $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
    }
    if ($result && $oldversion < 2007040200) {
        /// Add some actions to get them properly displayed in the logs
        $rec = new stdClass();
        $rec->module = 'hotquestion';
        $rec->action = 'add';
        $rec->mtable = 'hotquestion';
        $rec->filed = 'name';
        /// Insert the add action in log_display
        $result = $DB->insert_record('log_display', $rec);
        /// Now the update action
        $rec->action = 'update';
        $result = $DB->insert_record('log_display', $rec);
        /// Now the view action
        $rec->action = 'view';
        $result = $DB->insert_record('log_display', $rec);
    }
    //===== 2.0 upgrade start here ======//
    return $result;
}
Ejemplo n.º 3
0
function xmldb_attforblock_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $DB;
    $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 ($result && $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;
                }
            }
        }
    }
    if ($oldversion < 2008102401 and $result) {
        $table = new XMLDBTable('attforblock');
        $field = new XMLDBField('grade');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '100', 'name');
        $result = $result && $table->add_field($table, $field);
        $table = new XMLDBTable('attendance_sessions');
        $field = new XMLDBField('courseid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
        $result = $result && $table->change_field_unsigned($table, $field);
        //        $field = new XMLDBField('creator');
        //        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid');
        //        $result = $result && change_field_unsigned($table, $field);
        $field = new XMLDBField('sessdate');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'creator');
        $result = $result && change_field_unsigned($table, $field);
        $field = new XMLDBField('duration');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'sessdate');
        $result = $result && add_field($table, $field);
        $field = new XMLDBField('timetaken');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'takenby');
        $result = $result && change_field_unsigned($table, $field);
        $result = $result && rename_field($table, $field, 'lasttaken');
        $field = new XMLDBField('takenby');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lasttaken');
        $result = $result && change_field_unsigned($table, $field);
        $result = $result && rename_field($table, $field, 'lasttakenby');
        $field = new XMLDBField('timemodified');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'lasttaken');
        $result = $result && change_field_unsigned($table, $field);
        $table = new XMLDBTable('attendance_log');
        $field = new XMLDBField('attsid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
        $result = $result && change_field_unsigned($table, $field);
        $field = new XMLDBField('studentid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'attsid');
        $result = $result && change_field_unsigned($table, $field);
        $field = new XMLDBField('statusid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'status');
        $result = $result && add_field($table, $field);
        $field = new XMLDBField('statusset');
        $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'statusid');
        $result = $result && add_field($table, $field);
        $field = new XMLDBField('timetaken');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'statusid');
        $result = $result && add_field($table, $field);
        $field = new XMLDBField('takenby');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timetaken');
        $result = $result && add_field($table, $field);
        //Indexes
        $index = new XMLDBIndex('statusid');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('statusid'));
        $result = $result && add_index($table, $index);
        $index = new XMLDBIndex('attsid');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('attsid'));
        $result = $result && drop_index($table, $index);
        $field = new XMLDBField('attsid');
        //Rename field
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
        $result = $result && rename_field($table, $field, 'sessionid');
        $index = new XMLDBIndex('sessionid');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid'));
        $result = $result && add_index($table, $index);
        $table = new XMLDBTable('attendance_settings');
        $field = new XMLDBField('courseid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
        $result = $result && change_field_unsigned($table, $field);
        $field = new XMLDBField('visible');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'grade');
        $result = $result && add_field($table, $field);
        $field = new XMLDBField('deleted');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'visible');
        $result = $result && add_field($table, $field);
        //Indexes
        $index = new XMLDBIndex('visible');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('visible'));
        $result = $result && add_index($table, $index);
        $index = new XMLDBIndex('deleted');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('deleted'));
        $result = $result && add_index($table, $index);
        $result = $result && rename_table($table, 'attendance_statuses');
    }
    if ($oldversion < 2008102406 and $result) {
        if ($courses = $DB->get_records_sql("SELECT courseid FROM {attendance_sessions} GROUP BY courseid")) {
            foreach ($courses as $c) {
                //Adding own status for course (now it must have own)
                if (!$DB->count_records('attendance_statuses', array('courseid' => $c->courseid))) {
                    $statuses = $DB->get_records('attendance_statuses', array('courseid' => 0));
                    foreach ($statuses as $stat) {
                        $rec = $stat;
                        $rec->courseid = $c->courseid;
                        $DB->insert_record('attendance_statuses', $rec);
                    }
                }
                $statuses = $DB->get_records('attendance_statuses', array('courseid' => $c->courseid));
                $statlist = implode(',', array_keys($statuses));
                $sess = $DB->get_records_select_menu('attendance_sessions', "courseid = ? AND lasttakenby > 0", array($c->courseid));
                $sesslist = implode(',', array_keys($sess));
                foreach ($statuses as $stat) {
                    execute_sql("UPDATE {$CFG->prefix}attendance_log\n                                        SET statusid = {$stat->id}, statusset = '{$statlist}'\n                                  WHERE sessionid IN ({$sesslist}) AND status = '{$stat->status}'");
                }
                $sessions = get_records_list('attendance_sessions', 'id', $sesslist);
                foreach ($sessions as $sess) {
                    execute_sql("UPDATE {$CFG->prefix}attendance_log\n                                    SET timetaken = {$sess->lasttaken},\n                                            takenby = {$sess->lasttakenby}\n                              WHERE sessionid = {$sess->id}");
                }
            }
        }
    }
    if ($oldversion < 2008102409 and $result) {
        $table = new XMLDBTable('attendance_statuses');
        $field = new XMLDBField('status');
        $result = $result && drop_field($table, $field);
        $index = new XMLDBIndex('status');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
        $result = $result && drop_index($table, $index);
        $table = new XMLDBTable('attendance_log');
        $field = new XMLDBField('status');
        $result = $result && drop_field($table, $field);
        $index = new XMLDBIndex('status');
        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status'));
        $result = $result && drop_index($table, $index);
        $table = new XMLDBTable('attendance_sessions');
        $field = new XMLDBField('creator');
        $result = $result && drop_field($table, $field);
    }
    return $result;
}