Merged branch 'MLD-27551' of git://github.com/mouneyrac/moodle.git with changes
authorSam Hemelryk <sam@moodle.com>
Wed, 8 Jun 2011 09:34:17 +0000 (17:34 +0800)
committerSam Hemelryk <sam@moodle.com>
Wed, 8 Jun 2011 09:34:17 +0000 (17:34 +0800)
1  2 
admin/settings/plugins.php
lang/en/admin.php
lib/adminlib.php
lib/db/install.xml
lib/db/services.php
lib/db/upgrade.php
lib/moodlelib.php
lib/upgradelib.php
version.php

@@@ -345,6 -324,9 +345,9 @@@ if ($hassiteconfig) 
      $ADMIN->add('webservicesettings', $temp);
      /// manage service
      $temp = new admin_settingpage('externalservices', get_string('externalservices', 'webservice'));
 -    $enablemobiledoclink = html_writer::tag('a', get_string('documentation'),array('href'=>$enablemobiledocurl));
+     $enablemobiledocurl = new moodle_url(get_docs_url('Enable_mobile_web_services'));
++    $enablemobiledoclink = html_writer::link($enablemobiledocurl, get_string('documentation'));
+     $temp->add(new admin_setting_enablemobileservice('enablemobilewebservice', get_string('enablemobilewebservice', 'admin'), get_string('configenablemobilewebservice', 'admin', $enablemobiledoclink), 0));
      $temp->add(new admin_setting_heading('manageserviceshelpexplaination', get_string('information', 'webservice'), get_string('servicehelpexplanation', 'webservice')));
      $temp->add(new admin_setting_manageexternalservices());
      $ADMIN->add('webservicesettings', $temp);
Simple merge
@@@ -6487,6 -6381,162 +6487,162 @@@ class admin_setting_managerepository ex
      }
  }
  
 -             $active_protocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
+ /**
+  * Special checkbox for enable mobile web service
+  * If enable then we store the service id of the mobile service into config table
+  * If disable then we unstore the service id from the config table
+  */
+ class admin_setting_enablemobileservice extends admin_setting_configcheckbox {
+     private $xmlrpcuse; //boolean: true => capability 'webservice/xmlrpc:use' is set for authenticated user role
+     /**
+      * Return true if Authenticated user role has the capability 'webservice/xmlrpc:use', otherwise false
+      * @return boolean
+      */
+     private function is_xmlrpc_cap_allowed() {
+         global $DB, $CFG;
+         //if the $this->xmlrpcuse variable is not set, it needs to be set
+         if (empty($this->xmlrpcuse) and $this->xmlrpcuse!==false) {
+             $params = array();
+             $params['permission'] = CAP_ALLOW;
+             $params['roleid'] = $CFG->defaultuserroleid;
+             $params['capability'] = 'webservice/xmlrpc:use';
+             $this->xmlrpcuse = $DB->record_exists('role_capabilities', $params);
+         }
+         return $this->xmlrpcuse;
+     }
+     /**
+      * Set the 'webservice/xmlrpc:use' to the Authenticated user role (allow or not)
+      * @param type $status true to allow, false to not set
+      */
+     private function set_xmlrpc_cap($status) {
+         global $CFG;
+         if ($status and !$this->is_xmlrpc_cap_allowed()) {
+             //need to allow the cap
+             $permission = CAP_ALLOW;
+             $assign = true;
+         } else if (!$status and $this->is_xmlrpc_cap_allowed()){
+             //need to disallow the cap
+             $permission = CAP_INHERIT;
+             $assign = true;
+         }
+         if (!empty($assign)) {
+             $systemcontext = get_system_context();
+             assign_capability('webservice/xmlrpc:use', $permission, $CFG->defaultuserroleid, $systemcontext->id, true);
+         }
+     }
+     /**
+      * Builds XHTML to display the control.
+      * The main purpose of this overloading is to display a warning when https
+      * is not supported by the server
+      * @param string $data Unused
+      * @param string $query
+      * @return string XHTML
+      */
+     public function output_html($data, $query='') {
+         global $CFG, $OUTPUT;
+         $html = parent::output_html($data, $query);
+         if ((string)$data === $this->yes) {
+             require_once($CFG->dirroot . "/lib/filelib.php");
+             $curl = new curl();
+             $httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); //force https url
+             $curl->head($httpswwwroot . "/login/index.php");
+             $info = $curl->get_info();
+             if (empty($info['http_code']) or ($info['http_code'] >= 400)) {
+                $html .= $OUTPUT->notification(get_string('nohttpsformobilewarning', 'admin'));
+             }
+         }
+         return $html;
+     }
+     /**
+      * Retrieves the current setting using the objects name
+      *
+      * @return string
+      */
+     public function get_setting() {
+         global $CFG;
+         $webservicesystem = $CFG->enablewebservices;
+         require_once($CFG->dirroot . '/webservice/lib.php');
+         $webservicemanager = new webservice();
+         $mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
+         if ($mobileservice->enabled and !empty($webservicesystem) and $this->is_xmlrpc_cap_allowed()) {
+             return $this->config_read($this->name); //same as returning 1
+         } else {
+             return 0;
+         }
+     }
+     /**
+      * Save the selected setting
+      *
+      * @param string $data The selected site
+      * @return string empty string or error message
+      */
+     public function write_setting($data) {
+         global $DB, $CFG;
+         $servicename = MOODLE_OFFICIAL_MOBILE_SERVICE;
+         require_once($CFG->dirroot . '/webservice/lib.php');
+         $webservicemanager = new webservice();
+         if ((string)$data === $this->yes) {
+              //code run when enable mobile web service
+              //enable web service systeme if necessary
+              set_config('enablewebservices', true);
+              //enable mobile service
+              $mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
+              $mobileservice->enabled = 1;
+              $webservicemanager->update_external_service($mobileservice);
+              //enable xml-rpc server
 -             if (!in_array('xmlrpc', $active_protocols)) {
 -                 $active_protocols[] = 'xmlrpc';
 -                 set_config('webserviceprotocols', implode(',', $active_protocols));
++             $activeprotocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
 -                 $active_protocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
 -                 $protocolkey = array_search('xmlrpc', $active_protocols);
++             if (!in_array('xmlrpc', $activeprotocols)) {
++                 $activeprotocols[] = 'xmlrpc';
++                 set_config('webserviceprotocols', implode(',', $activeprotocols));
+              }
+              //allow xml-rpc:use capability for authenticated user
+              $this->set_xmlrpc_cap(true);
+          } else {
+              //disable web service system if no other services are enabled
+              $otherenabledservices = $DB->get_records_select('external_services',
+                      'enabled = :enabled AND (shortname != :shortname OR shortname IS NULL)', array('enabled' => 1,
+                          'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
+              if (empty($otherenabledservices)) {
+                  set_config('enablewebservices', false);
+                  //also disable xml-rpc server
 -                    unset($active_protocols[$protocolkey]);
 -                    set_config('webserviceprotocols', implode(',', $active_protocols));
++                 $activeprotocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
++                 $protocolkey = array_search('xmlrpc', $activeprotocols);
+                  if ($protocolkey !== false) {
++                    unset($activeprotocols[$protocolkey]);
++                    set_config('webserviceprotocols', implode(',', $activeprotocols));
+                  }
+                  //disallow xml-rpc:use capability for authenticated user
+                  $this->set_xmlrpc_cap(false);
+              }
+              //disable the mobile service
+              $mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
+              $mobileservice->enabled = 0;
+              $webservicemanager->update_external_service($mobileservice);
+          }
+         return (parent::write_setting($data));
+     }
+ }
  
  /**
   * Special class for management of external services
Simple merge
@@@ -206,26 -206,14 +206,38 @@@ $functions = array
          'capabilities'=> 'moodle/course:create,moodle/course:visibility',
      ),
  
 +    // === message related functions ===
 +
 +    'moodle_message_send_messages' => array(
 +        'classname'   => 'moodle_message_external',
 +        'methodname'  => 'send_messages',
 +        'classpath'   => 'message/externallib.php',
 +        'description' => 'Send messages',
 +        'type'        => 'write',
 +        'capabilities'=> 'moodle/site:sendmessage',
 +    ),
 +
 +    // === notes related functions ===
 +
 +    'moodle_notes_create_notes' => array(
 +        'classname'   => 'moodle_notes_external',
 +        'methodname'  => 'create_notes',
 +        'classpath'   => 'notes/externallib.php',
 +        'description' => 'Create notes',
 +        'type'        => 'write',
 +        'capabilities'=> 'moodle/notes:manage',
 +    ),
 +
  );
 -       'Moodle mobile web service'  => array(
 -                'functions' => array ('moodle_enrol_get_users_courses', 'moodle_enrol_get_enrolled_users',
 -                    'moodle_user_get_users_by_id'),
 -                'enabled' => 0,
 -                'restrictedusers' => 0,
 -                'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE
 -        ),
 -);
+ $services = array(
++   'Moodle mobile web service'  => array(
++        'functions' => array (
++            'moodle_enrol_get_users_courses',
++            'moodle_enrol_get_enrolled_users',
++            'moodle_user_get_users_by_id'),
++        'enabled' => 0,
++        'restrictedusers' => 0,
++        'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE
++    ),
++);
@@@ -6112,425 -6112,20 +6112,439 @@@ WHERE gradeitemid IS NOT NULL AND grade
          upgrade_main_savepoint(true, 2011052300.02);
      }
  
 -    if ($oldversion < 2011060200.039) { //TODO: put the right latest version
 +    // 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, 2011060800);
 +    }
 +
++    if ($oldversion < 2011060800.01) { //TODO: put the right latest version
+         // Define field shortname to be added to external_services
+         $table = new xmldb_table('external_services');
+         $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'timemodified');
++        // Conditionally launch add field shortname
+         if (!$dbman->field_exists($table, $field)) {
+             $dbman->add_field($table, $field);
+         }
 -        // Conditionally launch add field shortname
+         // Main savepoint reached
 -        upgrade_main_savepoint(true, 2011060200.039);
++        upgrade_main_savepoint(true, 2011060800.01);
+     }
      return true;
  }
  
Simple merge
Simple merge
diff --cc version.php
@@@ -30,8 -30,7 +30,8 @@@
  defined('MOODLE_INTERNAL') || die();
  
  
 -$version  = 2011060200.039;              // YYYYMMDD      = weekly release date of this DEV branch
 +
- $version  = 2011060800.00;              // YYYYMMDD      = weekly release date of this DEV branch
++$version  = 2011060800.01;              // YYYYMMDD      = weekly release date of this DEV branch
                                          //         RR    = release increments - 00 in DEV branches
                                          //           .XX = incremental changes