Fixed conflicts & merge branch 'MDL-17201_index' of git://github.com/andyjdavis/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 31 Jan 2011 14:34:40 +0000 (15:34 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 31 Jan 2011 14:34:40 +0000 (15:34 +0100)
1  2 
lib/db/install.xml
lib/db/upgrade.php
version.php

diff --combined lib/db/install.xml
@@@ -1,5 -1,5 +1,5 @@@
  <?xml version="1.0" encoding="UTF-8" ?>
- <XMLDB PATH="lib/db" VERSION="20110114" COMMENT="XMLDB file for core Moodle tables"
+ <XMLDB PATH="lib/db" VERSION="20110125" COMMENT="XMLDB file for core Moodle tables"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
  >
        <KEYS>
          <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        </KEYS>
+       <INDEXES>
+         <INDEX NAME="userfieldidx" UNIQUE="false" FIELDS="userid, fieldid"/>
+       </INDEXES>
      </TABLE>
      <TABLE NAME="question_categories" COMMENT="Categories are for grouping questions" PREVIOUS="user_info_data" NEXT="question">
        <FIELDS>
          <FIELD NAME="tagid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="itemtype"/>
          <FIELD NAME="itemtype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="tagid" NEXT="itemid"/>
          <FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="itemtype" NEXT="tiuserid"/>
 -        <FIELD NAME="tiuserid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="itemid" NEXT="ordering"/>
 +        <FIELD NAME="tiuserid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="itemid" NEXT="ordering"/>
          <FIELD NAME="ordering" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Maintains the order of the tag instances of an item" PREVIOUS="tiuserid" NEXT="timemodified"/>
          <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="timemodified" PREVIOUS="ordering"/>
        </FIELDS>
        </KEYS>
      </TABLE>
    </TABLES>
 -</XMLDB>
 +</XMLDB>
diff --combined lib/db/upgrade.php
@@@ -239,7 -239,7 +239,7 @@@ function xmldb_main_upgrade($oldversion
          // add field
          $field = new xmldb_field('tiuserid');
          if (!$dbman->field_exists($table, $field)) {
 -            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'itemid');
 +            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
              $dbman->add_field($table, $field);
          }
          // modify index
@@@ -2825,10 -2825,10 +2825,10 @@@ WHERE gradeitemid IS NOT NULL AND grade
  
      if ($oldversion < 2010033102.00) {
          // rename course view capability to participate
 -        $params = array('view'=>'moodle/course:view', 'participate'=>'moodle/course:participate');
 -        $sql = "UPDATE {role_capabilities} SET capability = :participate WHERE capability = :view";
 +        $params = array('viewcap'=>'moodle/course:view', 'participatecap'=>'moodle/course:participate');
 +        $sql = "UPDATE {role_capabilities} SET capability = :participatecap WHERE capability = :viewcap";
          $DB->execute($sql, $params);
 -        $sql = "UPDATE {capabilities} SET name = :participate WHERE name = :view";
 +        $sql = "UPDATE {capabilities} SET name = :participatecap WHERE name = :viewcap";
          $DB->execute($sql, $params);
          // note: the view capability is readded again at the end of upgrade, but with different meaning
          upgrade_main_savepoint(true, 2010033102.00);
  
          // Check if we need to fix default grade
          if (array_key_exists('defaultgrade', $columns) && (
 -                empty($columns['defaultgrade']->unsigned) || 
 -                empty($columns['defaultgrade']->not_null) || 
 +                empty($columns['defaultgrade']->unsigned) ||
 +                empty($columns['defaultgrade']->not_null) ||
                  $columns['defaultgrade']->default_value !== '1.0000000')) {
              // defaultgrade should be unsigned NOT NULL DEFAULT '1.0000000'
              // Fixed in earlier upgrade code
          if (array_key_exists('tiuserid', $columns) && !empty($columns['tiuserid']->has_default)) {
              // tiuserid should have no default
              // Fixed in earlier upgrade code
 -            $field = new xmldb_field('tiuserid', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'itemid');
 +            $field = new xmldb_field('tiuserid', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
              $index = new xmldb_index('itemtype-itemid-tagid-tiuserid', XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
              if ($dbman->index_exists($table, $index)) {
                  $dbman->drop_index($table, $index);
  
          upgrade_main_savepoint(true, 2011011414);
      }
 -    
 +
      if ($oldversion < 2011011415) {
          //create the rating table indexes if required
          $table = new xmldb_table('rating');
 -        
 +
          $index = new xmldb_index('itemid', XMLDB_INDEX_NOTUNIQUE, array('itemid'));
          if (!$dbman->index_exists($table, $index)) {
              $dbman->add_index($table, $index);
 -            
 +
              $key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
              $dbman->add_key($table, $key);
 -            
 +
              $key = new xmldb_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
              $dbman->add_key($table, $key);
          }
 -        
 +
          upgrade_main_savepoint(true, 2011011415);
      }
  
 +    if ($oldversion < 2011012400) {
 +        // Clean up the old progress tracked roles setting, no longer used (replaced by enrolment)
 +        unset_config('progresstrackedroles');
 +        upgrade_main_savepoint(true, 2011012400);
 +    }
 +
      if ($oldversion < 2011012500) {
 -        
 +        $columns = $DB->get_columns('tag_instance');
 +        $table = new xmldb_table('tag_instance');
 +
 +        // Drop and recreate index if tiuserid doesn't have default value
 +        if (array_key_exists('tiuserid', $columns) && empty($columns['tiuserid']->has_default)) {
 +            // Define index itemtype-itemid-tagid-tiuserid (unique) to be dropped form tag_instance
 +            $index = new xmldb_index('itemtype-itemid-tagid-tiuserid', XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
 +            // Conditionally launch drop index itemtype-itemid-tagid-tiuserid
 +            if ($dbman->index_exists($table, $index)) {
 +                $dbman->drop_index($table, $index);
 +            }
 +
 +            // Changing the default of field tiuserid on table tag_instance to 0
 +            $field = new xmldb_field('tiuserid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'itemid');
 +
 +            // Launch change of default for field tiuserid
 +            $dbman->change_field_default($table, $field);
 +
 +            $index = new xmldb_index('itemtype-itemid-tagid-tiuserid', XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
 +
 +            // Conditionally launch add index itemtype-itemid-tagid-tiuserid
 +            if (!$dbman->index_exists($table, $index)) {
 +                $dbman->add_index($table, $index);
 +            }
 +        }
 +
 +        // Main savepoint reached
 +        upgrade_main_savepoint(true, 2011012500);
 +    }
 +
++    if ($oldversion < 2011012501) {
+         //add the index userfieldidx (not unique) to user_info_data
+         $table = new xmldb_table('user_info_data');
+         $index = new xmldb_index('userfieldidx', XMLDB_INDEX_NOTUNIQUE, array('userid', 'fieldid'));
 -        upgrade_main_savepoint(true, 2011012500);
++
+         if (!$dbman->index_exists($table, $index)) {
+             $dbman->add_index($table, $index);
+         }
++        upgrade_main_savepoint(true, 2011012501);
+     }
      return true;
  }
  
diff --combined version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
--$version = 2011012500;  // YYYYMMDD   = date of the last version bump
++$version = 2011012501;  // YYYYMMDD   = date of the last version bump
                          //         XX = daily increments
  
 -$release = '2.0.1+ (Build: 20110119)';  // Human-friendly version name
 +$release = '2.0.1+ (Build: 20110125)';  // Human-friendly version name