<commit_before><?php  // $Id$

// This file keeps track of upgrades to 
// the calculated qtype plugin
//
// 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_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');
    }
    if ($result && $oldversion < 2009082000 ) { //New version in version.php

// this should be changed if merged to 1.9
//    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');
        $table->add_field('multichoice', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0','synchronize');
        $table->add_field('single', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0','multichoice');
        $table->add_field('shuffleanswers', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0','single');
        $table->add_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null,'shuffleanswers');
        $table->add_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'correctfeedback');
        $table->add_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'partiallycorrectfeedback');
        $table->add_field('answernumbering', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'abc', 'incorrectfeedback');


    /// 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)) {
            // $dbman->create_table doesnt return a result, we just have to trust it
            $dbman->create_table($table);
        }
        upgrade_plugin_savepoint($result, 2009092000, 'qtype', 'calculated');
    }
    if ($result && $oldversion >= 2009082000 && $oldversion < 2009092000 ) { //New version in version.php

    /// Define field multichoice to be added to question_calculated_options
        $table = new xmldb_table('question_calculated_options');
        $field = new xmldb_field('multichoice', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'synchronize');

    /// Conditionally launch add field multichoice
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
    /// Define field single to be added to question_calculated_options
        $table = new xmldb_table('question_calculated_options');
        $field = new xmldb_field('single', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'multichoice');

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

    /// Define field shuffleanswers to be added to question_calculated_options
        $table = new xmldb_table('question_calculated_options');
        $field = new xmldb_field('shuffleanswers', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'single');

    /// Conditionally launch add field shuffleanswers
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
    /// Define field correctfeedback to be added to question_calculated_options
        $table = new xmldb_table('question_calculated_options');<commit_msg>MDL-20522 correct the version numbers and  creating database field steps<commit_after><?php  // $Id$

// This file keeps track of upgrades to 
// the calculated qtype plugin
//
// 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_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');
    }
    if ($result && $oldversion < 2009082000 ) { //New version in version.php

// this should be changed if merged to 1.9
//    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)) {
            // $dbman->create_table doesnt return a result, we just have to trust it
            $dbman->create_table($table);
        }
        upgrade_plugin_savepoint($result, 2009082000 , 'qtype', 'calculated');
    }
    if ( $oldversion < 2009092000 ) { //New version in version.php

    /// Define field multichoice to be added to question_calculated_options
        $table = new xmldb_table('question_calculated_options');
        $field = new xmldb_field('multichoice', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'synchronize');

    /// Conditionally launch add field multichoice
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
    /// Define field single to be added to question_calculated_options
        $table = new xmldb_table('question_calculated_options');
        $field = new xmldb_field('single', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'multichoice');

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

    /// Define field shuffleanswers to be added to question_calculated_options
        $table = new xmldb_table('question_calculated_options');
        $field = new xmldb_field('shuffleanswers', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'single');

    /// Conditionally launch add field shuffleanswers
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
    /// Define field correctfeedback to be added to question_calculated_options
        $table = new xmldb_table('question_calculated_options');
{'fraction_non_alphanumeric': 0.12342933392638719, 'fraction_numerical': 0.0181252084954965, 'mean_word_length': 3.6123076923076924, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, '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': '4925055', 'n_tokens_mistral': 2838, 'n_tokens_neox': 2672, 'n_words': 757}