Merged branch 'ou-messaging-release' of git://git.luns.net.uk/moodle with conflict...
authorSam Hemelryk <sam@moodle.com>
Wed, 8 Jun 2011 03:07:22 +0000 (11:07 +0800)
committerSam Hemelryk <sam@moodle.com>
Wed, 8 Jun 2011 03:07:22 +0000 (11:07 +0800)
1  2 
lang/en/admin.php
lang/en/message.php
lib/adminlib.php
lib/db/install.xml
lib/db/upgrade.php
version.php

Simple merge
Simple merge
Simple merge
Simple merge
@@@ -6112,408 -6112,23 +6112,425 @@@ WHERE gradeitemid IS NOT NULL AND grade
          upgrade_main_savepoint(true, 2011052300.02);
      }
  
 -    if ($oldversion < 2011052500.01) {
 -        // Add enabled filed to message_processors
 +    // Question engine 2 changes (14) start here
 +    if ($oldversion < 2011060300) {
 +        // Changing the default of field penalty on table question to 0.3333333
 +        $table = new xmldb_table('question');
 +        $field = new xmldb_field('penalty');
 +        $field->set_attributes(XMLDB_TYPE_NUMBER, '12, 7', null,
 +                XMLDB_NOTNULL, null, '0.3333333');
 +
 +        // Launch change of default for field penalty
 +        $dbman->change_field_default($table, $field);
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060300);
 +    }
 +
 +    if ($oldversion < 2011060301) {
 +
 +        // Rename field defaultgrade on table question to defaultmark
 +        $table = new xmldb_table('question');
 +        $field = new xmldb_field('defaultgrade');
 +        $field->set_attributes(XMLDB_TYPE_NUMBER, '12, 7', null,
 +                XMLDB_NOTNULL, null, '1');
 +
 +        // Launch rename field defaultmark
 +        if ($dbman->field_exists($table, $field)) {
 +            $dbman->rename_field($table, $field, 'defaultmark');
 +        }
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060301);
 +    }
 +
 +    if ($oldversion < 2011060302) {
 +
 +        // Rename the question_attempts table to question_usages.
 +        $table = new xmldb_table('question_attempts');
 +        if (!$dbman->table_exists('question_usages')) {
 +            $dbman->rename_table($table, 'question_usages');
 +        }
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060302);
 +    }
 +
 +    if ($oldversion < 2011060303) {
 +
 +        // Rename the modulename field to component ...
 +        $table = new xmldb_table('question_usages');
 +        $field = new xmldb_field('modulename');
 +        $field->set_attributes(XMLDB_TYPE_CHAR, '255', null,
 +                XMLDB_NOTNULL, null, null, 'contextid');
 +
 +        if ($dbman->field_exists($table, $field)) {
 +            $dbman->rename_field($table, $field, 'component');
 +        }
 +
 +        // ... and update its contents.
 +        $DB->set_field('question_usages', 'component', 'mod_quiz', array('component' => 'quiz'));
 +
 +        // Add the contextid field.
 +        $field = new xmldb_field('contextid');
 +        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                null, null, null, 'id');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +
 +            // And populate it.
 +            $quizmoduleid = $DB->get_field('modules', 'id', array('name' => 'quiz'));
 +            $DB->execute("
 +                UPDATE {question_usages} SET contextid = (
 +                    SELECT ctx.id
 +                    FROM {context} ctx
 +                    JOIN {course_modules} cm ON cm.id = ctx.instanceid AND cm.module = $quizmoduleid
 +                    JOIN {quiz_attempts} quiza ON quiza.quiz = cm.instance
 +                    WHERE ctx.contextlevel = " . CONTEXT_MODULE . "
 +                    AND quiza.uniqueid = {question_usages}.id
 +                )
 +            ");
 +
 +            // Then make it NOT NULL.
 +            $field = new xmldb_field('contextid');
 +            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null, 'id');
 +            $dbman->change_field_notnull($table, $field);
 +        }
 +
 +        // Add the preferredbehaviour column. Populate it with a dummy value
 +        // for now. We will fill in the appropriate behaviour name when
 +        // updating all the rest of the attempt data.
 +        $field = new xmldb_field('preferredbehaviour');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $field->set_attributes(XMLDB_TYPE_CHAR, '32', null,
 +                    XMLDB_NOTNULL, null, 'to_be_set_later', 'component');
 +            $dbman->add_field($table, $field);
 +
 +            // Then remove the default value, now the column is populated.
 +            $field = new xmldb_field('preferredbehaviour');
 +            $field->set_attributes(XMLDB_TYPE_CHAR, '32', null,
 +                    XMLDB_NOTNULL, null, null, 'component');
 +            $dbman->change_field_default($table, $field);
 +        }
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060303);
 +    }
 +
 +    if ($oldversion < 2011060304) {
 +
 +        // Define key contextid (foreign) to be added to question_usages
 +        $table = new xmldb_table('question_usages');
 +        $key = new XMLDBKey('contextid');
 +        $key->set_attributes(XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
 +
 +        // Launch add key contextid
 +        $dbman->add_key($table, $key);
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060304);
 +    }
 +
 +    if ($oldversion < 2011060305) {
 +
 +        // Changing precision of field component on table question_usages to (255)
 +        // This was missed during the upgrade from old versions.
 +        $table = new xmldb_table('question_usages');
 +        $field = new xmldb_field('component');
 +        $field->set_attributes(XMLDB_TYPE_CHAR, '255', null,
 +                XMLDB_NOTNULL, null, null, 'contextid');
 +
 +        // Launch change of precision for field component
 +        $dbman->change_field_precision($table, $field);
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060305);
 +    }
 +
 +    if ($oldversion < 2011060306) {
 +
 +        // Define table question_attempts to be created
 +        $table = new xmldb_table('question_attempts');
 +        if (!$dbman->table_exists($table)) {
 +
 +            // Adding fields to table question_attempts
 +            $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
 +            $table->add_field('questionusageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('slot', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('behaviour', XMLDB_TYPE_CHAR, '32', null,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', null,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('minfraction', XMLDB_TYPE_NUMBER, '12, 7', null,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('flagged', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, '0');
 +            $table->add_field('questionsummary', XMLDB_TYPE_TEXT, 'small', null,
 +                    null, null, null);
 +            $table->add_field('rightanswer', XMLDB_TYPE_TEXT, 'small', null,
 +                    null, null, null);
 +            $table->add_field('responsesummary', XMLDB_TYPE_TEXT, 'small', null,
 +                    null, null, null);
 +            $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null);
 +
 +            // Adding keys to table question_attempts
 +            $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
 +            $table->add_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'),
 +                    'question', array('id'));
 +            $table->add_key('questionusageid', XMLDB_KEY_FOREIGN, array('questionusageid'),
 +                    'question_usages', array('id'));
 +
 +            // Adding indexes to table question_attempts
 +            $table->add_index('questionusageid-slot', XMLDB_INDEX_UNIQUE,
 +                    array('questionusageid', 'slot'));
 +
 +            // Launch create table for question_attempts
 +            $dbman->create_table($table);
 +        }
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060306);
 +    }
 +
 +    if ($oldversion < 2011060307) {
 +
 +        // Define table question_attempt_steps to be created
 +        $table = new xmldb_table('question_attempt_steps');
 +        if (!$dbman->table_exists($table)) {
 +
 +            // Adding fields to table question_attempt_steps
 +            $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
 +            $table->add_field('questionattemptid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('sequencenumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('state', XMLDB_TYPE_CHAR, '13', null,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null,
 +                    null, null, null);
 +            $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    null, null, null);
 +
 +            // Adding keys to table question_attempt_steps
 +            $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
 +            $table->add_key('questionattemptid', XMLDB_KEY_FOREIGN,
 +                    array('questionattemptid'), 'question_attempts_new', array('id'));
 +            $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'),
 +                    'user', array('id'));
 +
 +            // Adding indexes to table question_attempt_steps
 +            $table->add_index('questionattemptid-sequencenumber', XMLDB_INDEX_UNIQUE,
 +                    array('questionattemptid', 'sequencenumber'));
 +
 +            // Launch create table for question_attempt_steps
 +            $dbman->create_table($table);
 +        }
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060307);
 +    }
 +
 +    if ($oldversion < 2011060308) {
 +
 +        // Define table question_attempt_step_data to be created
 +        $table = new xmldb_table('question_attempt_step_data');
 +        if (!$dbman->table_exists($table)) {
 +
 +            // Adding fields to table question_attempt_step_data
 +            $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
 +            $table->add_field('attemptstepid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('name', XMLDB_TYPE_CHAR, '32', null,
 +                    XMLDB_NOTNULL, null, null);
 +            $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null,
 +                    null, null, null);
 +
 +            // Adding keys to table question_attempt_step_data
 +            $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
 +            $table->add_key('attemptstepid', XMLDB_KEY_FOREIGN, array('attemptstepid'),
 +                    'question_attempt_steps', array('id'));
 +
 +            // Adding indexes to table question_attempt_step_data
 +            $table->add_index('attemptstepid-name', XMLDB_INDEX_UNIQUE,
 +                    array('attemptstepid', 'name'));
 +
 +            // Launch create table for question_attempt_step_data
 +            $dbman->create_table($table);
 +        }
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060308);
 +    }
 +
 +    if ($oldversion < 2011060309) {
 +
 +        // Define table question_hints to be created
 +        $table = new xmldb_table('question_hints');
 +
 +        // Adding fields to table question_hints
 +        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
 +        $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                XMLDB_NOTNULL, null, null);
 +        $table->add_field('hint', XMLDB_TYPE_TEXT, 'small', null,
 +                XMLDB_NOTNULL, null, null);
 +        $table->add_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
 +                XMLDB_NOTNULL, null, '0');
 +        $table->add_field('shownumcorrect', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
 +                null, null, null);
 +        $table->add_field('clearwrong', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
 +                null, null, null);
 +        $table->add_field('options', XMLDB_TYPE_CHAR, '255', null,
 +                null, null, null);
 +
 +        // Adding keys to table question_hints
 +        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
 +        $table->add_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'),
 +                'question', array('id'));
 +
 +        // Conditionally launch create table for question_hints
 +        if (!$dbman->table_exists($table)) {
 +            $dbman->create_table($table);
 +        }
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060309);
 +    }
 +
 +    if ($oldversion < 2011060310) {
 +
 +        // In the past, question_answer fractions were stored with rather
 +        // sloppy rounding. Now update them to the new standard of 7 d.p.
 +        $changes = array(
 +            '-0.66666'  => '-0.6666667',
 +            '-0.33333'  => '-0.3333333',
 +            '-0.16666'  => '-0.1666667',
 +            '-0.142857' => '-0.1428571',
 +             '0.11111'  =>  '0.1111111',
 +             '0.142857' =>  '0.1428571',
 +             '0.16666'  =>  '0.1666667',
 +             '0.33333'  =>  '0.3333333',
 +             '0.333333' =>  '0.3333333',
 +             '0.66666'  =>  '0.6666667',
 +        );
 +        foreach ($changes as $from => $to) {
 +            $DB->set_field('question_answers',
 +                    'fraction', $to, array('fraction' => $from));
 +        }
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060310);
 +    }
 +
 +    if ($oldversion < 2011060311) {
 +
 +        // In the past, question penalties were stored with rather
 +        // sloppy rounding. Now update them to the new standard of 7 d.p.
 +        $DB->set_field('question',
 +                'penalty', 0.3333333, array('penalty' => 33.3));
 +        $DB->set_field_select('question',
 +                'penalty', 0.3333333, 'penalty >= 0.33 AND penalty <= 0.34');
 +        $DB->set_field_select('question',
 +                'penalty', 0.6666667, 'penalty >= 0.66 AND penalty <= 0.67');
 +        $DB->set_field_select('question',
 +                'penalty', 1, 'penalty > 1');
 +
 +        // quiz savepoint reached
 +        upgrade_main_savepoint(true, 2011060311);
 +    }
 +
 +    if ($oldversion < 2011060312) {
 +
 +        // Define field hintformat to be added to question_hints table.
 +        $table = new xmldb_table('question_hints');
 +        $field = new xmldb_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
 +                XMLDB_NOTNULL, null, '0');
 +
 +        // Conditionally launch add field partiallycorrectfeedbackformat
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        upgrade_main_savepoint(true, 2011060312);
 +    }
 +
 +    if ($oldversion < 2011060313) {
 +        // Define field variant to be added to question_attempts
 +        $table = new xmldb_table('question_attempts');
 +        $field = new xmldb_field('variant', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
 +                XMLDB_NOTNULL, null, 1, 'questionid');
 +
 +        // Launch add field component
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        // Main savepoint reached
 +        upgrade_main_savepoint(true, 2011060313);
 +    }
 +    // Question engine 2 changes (14) end here
 +
 +    if ($oldversion < 2011060500) {
 +
 +         // Define index uniqueuserrating (not unique) to be dropped from rating
 +        $table = new xmldb_table('rating');
 +        $index = new xmldb_index('uniqueuserrating', XMLDB_INDEX_NOTUNIQUE,
 +                         array('component', 'ratingarea', 'contextid', 'itemid'));
 +
 +        // Drop dependent index before changing fields specs
 +        if ($dbman->index_exists($table, $index)) {
 +            $dbman->drop_index($table, $index);
 +        }
 +
 +        // Changing the default of field component on table rating to drop it
 +        $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'contextid');
 +
 +        // Launch change of default for field component
 +        $dbman->change_field_default($table, $field);
 +
 +        // Changing the default of field ratingarea on table rating to drop it
 +        $field = new xmldb_field('ratingarea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'component');
 +
 +        // Launch change of default for field ratingarea
 +        $dbman->change_field_default($table, $field);
 +
 +        // Add dependent index back
 +        if (!$dbman->index_exists($table, $index)) {
 +            $dbman->add_index($table, $index);
 +        }
 +
 +        // Main savepoint reached
 +        upgrade_main_savepoint(true, 2011060500);
 +    }
 +
++    if ($oldversion < 2011060800) {
++        // Add enabled field to message_processors
+         $table = new xmldb_table('message_processors');
+         $field = new xmldb_field('enabled');
+         $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'name');
+         // Launch add field addition
+         if (!$dbman->field_exists($table,$field)) {
+             $dbman->add_field($table, $field);
+         }
+         // Populate default messaging settings
+         upgrade_populate_default_messaging_prefs();
 -        upgrade_main_savepoint(true, 2011052500.01);
++        upgrade_main_savepoint(true, 2011060800);
+     }
      return true;
  }
  
diff --cc version.php
@@@ -30,7 -30,7 +30,8 @@@
  defined('MOODLE_INTERNAL') || die();
  
  
- $version  = 2011060500.03;              // YYYYMMDD      = weekly release date of this DEV branch
 -$version  = 2011052500.01;              // YYYYMMDD      = weekly release date of this DEV branch
++
++$version  = 2011060800.00;              // YYYYMMDD      = weekly release date of this DEV branch
                                          //         RR    = release increments - 00 in DEV branches
                                          //           .XX = incremental changes