<commit_before><?php  // $Id$

// This file keeps track of upgrades to
// the quiz 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 installtion 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.

function xmldb_quiz_upgrade($oldversion) {
    global $CFG, $DB;
    
    $dbman = $DB->get_manager();
    $result = true;

//===== 1.9.0 upgrade line ======//

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

    /// Define table quiz_report to be created
        $table = new xmldb_table('quiz_report');

    /// Adding fields to table quiz_report
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
        $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);

    /// Adding keys to table quiz_report
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

    /// Conditionally launch create table for quiz_report
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

        upgrade_mod_savepoint($result, 2008062000, 'quiz');
    }

    if ($result && $oldversion < 2008062001) {
        $reporttoinsert = new object();
        $reporttoinsert->name = 'overview';
        $reporttoinsert->displayorder = 10000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        $reporttoinsert = new object();
        $reporttoinsert->name = 'responses';
        $reporttoinsert->displayorder = 9000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        $reporttoinsert = new object();
        $reporttoinsert->name = 'statistics';
        $reporttoinsert->displayorder = 8000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        $reporttoinsert = new object();
        $reporttoinsert->name = 'regrade';
        $reporttoinsert->displayorder = 7000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        $reporttoinsert = new object();
        $reporttoinsert->name = 'grading';
        $reporttoinsert->displayorder = 6000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        upgrade_mod_savepoint($result, 2008062001, 'quiz');
    }
    
    if ($result && $oldversion < 2008072402) {

    /// Define field lastcron to be added to quiz_report
        $table = new xmldb_table('quiz_report');
        $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'displayorder');

    /// Conditionally launch add field lastcron
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

    /// Define field cron to be added to quiz_report
        $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lastcron');

    /// Conditionally launch add field cron
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

    /// quiz savepoint reached
        upgrade_mod_savepoint($result, 2008072402, 'quiz');
    }

    if ($result && $oldversion < 2008072900) {
    /// Delete the regrade report - it is now part of the overview report.
        $result = $result && $DB->delete_records('quiz_report', array('name' => 'regrade'));

    /// quiz savepoint reached
        upgrade_mod_savepoint($result, 2008072900, 'quiz');
    }

    if ($result && $oldversion < 2008081500) {
    /// Define table quiz_question_versions to be dropped
        $table = new xmldb_table('quiz_question_versions');

    /// Launch drop table for quiz_question_versions
        $dbman->drop_table($table);

    /// quiz savepoint reached
        upgrade_mod_savepoint($result, 2008081500, 'quiz');
    }

    /// Changing the type of all the columns that store grades to be NUMBER(10, 5) or similar.
    if ($result && $oldversion < 2008081501) {
        $table = new xmldb_table('quiz');
        $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'questions');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081501, 'quiz');
    }

    if ($result && $oldversion < 2008081502) {
        $table = new xmldb_table('quiz');
        $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'sumgrades');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081502, 'quiz');
    }

    if ($result && $oldversion < 2008081503) {
        $table = new xmldb_table('quiz_attempts');
        $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'attempt');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081503, 'quiz');
    }

    if ($result && $oldversion < 2008081504) {
        $table = new xmldb_table('quiz_feedback');
        $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'feedbacktext');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081504, 'quiz');
    }

    if ($result && $oldversion < 2008081505) {
        $table = new xmldb_table('quiz_feedback');
        $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'mingrade');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081505, 'quiz');
    }

    if ($result && $oldversion < 2008081506) {
        $table = new xmldb_table('quiz_grades');
        $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'userid');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081506, 'quiz');
    }

    if ($result && $oldversion < 2008081507) {
        $table = new xmldb_table('quiz_question_instances');
        $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'question');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081507, 'quiz');
    }

    /// Move all of the quiz config settings from $CFG to the config_plugins table.
    if ($result && $oldversion < 2008082200) {
        foreach (get_object_vars($CFG) as $name => $value) {
            if (strpos($name, 'quiz_') === 0) {
                $shortname = substr($name, 5);
                if ($shortname == 'fix_adaptive') {
                    // Special case - remove old inconsistency.
                    $shortname == 'fix_optionflags';
                }
                $result = $result && set_config($shortname, $value, 'quiz');
                $result = $result && unset_config($name);
            }
        }
        upgrade_mod_savepoint($result, 2008082200, 'quiz');
    }

    /// Now that the quiz is no longer responsible for creating all the question
    /// bank tables, and some of the tables are now the responsibility of the
    /// datasetdependent question type, which did not have a version.php file before,
    /// we need to say that these tables are already installed, otherwise XMLDB
    /// will try to create them again and give an error.
    if ($result && $oldversion < 2008082600) {
        set_config('qtype_datasetdependent_version', 2008082600);
        upgrade_mod_savepoint($result, 2008082600, 'quiz');
    }

    return $result;
}

?><commit_msg>MDL-16492: the fix for MDL-16411 broke the fix for MDL-16200. Fix it.<commit_after><?php  // $Id$

// This file keeps track of upgrades to
// the quiz 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 installtion 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.

function xmldb_quiz_upgrade($oldversion) {
    global $CFG, $DB;
    
    $dbman = $DB->get_manager();
    $result = true;

//===== 1.9.0 upgrade line ======//

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

    /// Define table quiz_report to be created
        $table = new xmldb_table('quiz_report');

    /// Adding fields to table quiz_report
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
        $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);

    /// Adding keys to table quiz_report
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

    /// Conditionally launch create table for quiz_report
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

        upgrade_mod_savepoint($result, 2008062000, 'quiz');
    }

    if ($result && $oldversion < 2008062001) {
        $reporttoinsert = new object();
        $reporttoinsert->name = 'overview';
        $reporttoinsert->displayorder = 10000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        $reporttoinsert = new object();
        $reporttoinsert->name = 'responses';
        $reporttoinsert->displayorder = 9000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        $reporttoinsert = new object();
        $reporttoinsert->name = 'statistics';
        $reporttoinsert->displayorder = 8000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        $reporttoinsert = new object();
        $reporttoinsert->name = 'regrade';
        $reporttoinsert->displayorder = 7000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        $reporttoinsert = new object();
        $reporttoinsert->name = 'grading';
        $reporttoinsert->displayorder = 6000;
        $result = $result && $DB->insert_record('quiz_report', $reporttoinsert);

        upgrade_mod_savepoint($result, 2008062001, 'quiz');
    }
    
    if ($result && $oldversion < 2008072402) {

    /// Define field lastcron to be added to quiz_report
        $table = new xmldb_table('quiz_report');
        $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'displayorder');

    /// Conditionally launch add field lastcron
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

    /// Define field cron to be added to quiz_report
        $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lastcron');

    /// Conditionally launch add field cron
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

    /// quiz savepoint reached
        upgrade_mod_savepoint($result, 2008072402, 'quiz');
    }

    if ($result && $oldversion < 2008072900) {
    /// Delete the regrade report - it is now part of the overview report.
        $result = $result && $DB->delete_records('quiz_report', array('name' => 'regrade'));

    /// quiz savepoint reached
        upgrade_mod_savepoint($result, 2008072900, 'quiz');
    }

    if ($result && $oldversion < 2008081500) {
    /// Define table quiz_question_versions to be dropped
        $table = new xmldb_table('quiz_question_versions');

    /// Launch drop table for quiz_question_versions
        $dbman->drop_table($table);

    /// quiz savepoint reached
        upgrade_mod_savepoint($result, 2008081500, 'quiz');
    }

    /// Changing the type of all the columns that store grades to be NUMBER(10, 5) or similar.
    if ($result && $oldversion < 2008081501) {
        $table = new xmldb_table('quiz');
        $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'questions');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081501, 'quiz');
    }

    if ($result && $oldversion < 2008081502) {
        $table = new xmldb_table('quiz');
        $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'sumgrades');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081502, 'quiz');
    }

    if ($result && $oldversion < 2008081503) {
        $table = new xmldb_table('quiz_attempts');
        $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'attempt');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081503, 'quiz');
    }

    if ($result && $oldversion < 2008081504) {
        $table = new xmldb_table('quiz_feedback');
        $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'feedbacktext');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081504, 'quiz');
    }

    if ($result && $oldversion < 2008081505) {
        $table = new xmldb_table('quiz_feedback');
        $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'mingrade');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081505, 'quiz');
    }

    if ($result && $oldversion < 2008081506) {
        $table = new xmldb_table('quiz_grades');
        $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null, 'userid');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081506, 'quiz');
    }

    if ($result && $oldversion < 2008081507) {
        $table = new xmldb_table('quiz_question_instances');
        $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'question');
        $dbman->change_field_type($table, $field);
        upgrade_mod_savepoint($result, 2008081507, 'quiz');
    }

    /// Move all of the quiz config settings from $CFG to the config_plugins table.
    if ($result && $oldversion < 2008082200) {
        foreach (get_object_vars($CFG) as $name => $value) {
            if (strpos($name, 'quiz_') === 0) {
                $shortname = substr($name, 5);
                if ($shortname == 'fix_adaptive') {
                    // Special case - remove old inconsistency.
                    $shortname == 'fix_optionflags';
                }
                $result = $result && set_config($shortname, $value, 'quiz');
                $result = $result && unset_config($name);
            }
        }
        upgrade_mod_savepoint($result, 2008082200, 'quiz');
    }

    /// Now that the quiz is no longer responsible for creating all the question
    /// bank tables, and some of the tables are now the responsibility of the
    /// datasetdependent question type, which did not have a version.php file before,
    /// we need to say that these tables are already installed, otherwise XMLDB
    /// will try to create them again and give an error.
    if ($result && $oldversion < 2008082600) {
        set_config('version', 2008082600, 'qtype_datasetdependent');
        upgrade_mod_savepoint($result, 2008082600, 'quiz');
    }

    return $result;
}

?>
{'fraction_non_alphanumeric': 0.13836821352744919, 'fraction_numerical': 0.04373673036093418, 'mean_word_length': 3.0111922141119223, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 40}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1515554', 'n_tokens_mistral': 5732, 'n_tokens_neox': 5072, 'n_words': 1362}