]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11504 fixed defaults in grade_items/display; added decimals and display to grade_...
authorskodak <skodak>
Fri, 28 Sep 2007 21:00:31 +0000 (21:00 +0000)
committerskodak <skodak>
Fri, 28 Sep 2007 21:00:31 +0000 (21:00 +0000)
lib/db/install.xml
lib/db/upgrade.php
lib/simpletest/fixtures/gradetest.php
version.php

index 222316ea84d437ac7ee96e664d0ed9e6bf4454d3..4338e39d4fbab887bfb1f4883987bc29d48353c3 100644 (file)
         <FIELD NAME="plusfactor" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="Add this to all grades" PREVIOUS="multfactor" NEXT="aggregationcoef"/>
         <FIELD NAME="aggregationcoef" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="Aggregation coefficient used for category weights or other aggregation types" PREVIOUS="plusfactor" NEXT="sortorder"/>
         <FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Sorting order of the columns" PREVIOUS="aggregationcoef" NEXT="display"/>
-        <FIELD NAME="display" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="-1" SEQUENCE="false" ENUM="false" COMMENT="Display as real grades, percentages (in reference to the minimum and maximum grades) or letters (A, B, C etc..), or course default (-1)" PREVIOUS="sortorder" NEXT="decimals"/>
+        <FIELD NAME="display" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Display as real grades, percentages (in reference to the minimum and maximum grades) or letters (A, B, C etc..), or course default (0)" PREVIOUS="sortorder" NEXT="decimals"/>
         <FIELD NAME="decimals" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Also known as precision, the number of digits after the decimal point symbol." PREVIOUS="display" NEXT="hidden"/>
         <FIELD NAME="hidden" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="1 is hidden, &amp;gt; 1 is a date to hide until (prevents viewing)" PREVIOUS="decimals" NEXT="locked"/>
         <FIELD NAME="locked" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="1 is locked, &amp;gt; 1 is a date to lock until (prevents update)" PREVIOUS="hidden" NEXT="locktime"/>
index 6929e44937eeba16c6210e49d04dc8a929413b4f..74d4b0a6c0401456fa1f363cb7f463c06618e426 100644 (file)
@@ -1081,6 +1081,8 @@ function xmldb_main_upgrade($oldversion=0) {
         $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
         $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
         $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+        $table->addFieldInfo('display', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+        $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
         $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
         $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
         $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
@@ -1240,6 +1242,8 @@ function xmldb_main_upgrade($oldversion=0) {
         $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
         $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
         $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+        $table->addFieldInfo('display', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+        $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
         $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
         $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
         $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
@@ -2015,17 +2019,6 @@ function xmldb_main_upgrade($oldversion=0) {
 
     if ($result && $oldversion < 2007091800) {
 
-    /// Define field display to be added to grade_items
-        $table = new XMLDBTable('grade_items');
-        $field = new XMLDBField('display');
-        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '-1', 'sortorder');
-
-    /// Launch add field display
-        $result = $result && add_field($table, $field);
-    }
-
-    if ($result && $oldversion < 2007091800) {
-
     /// Define table grade_letters to be created
         $table = new XMLDBTable('grade_letters');
 
@@ -2071,29 +2064,6 @@ function xmldb_main_upgrade($oldversion=0) {
      */
     if ($result && $oldversion < 2007092002) {
 
-/// Remove obsoleted unit tests tables - they will be recreated automatically
-        $tables = array('grade_categories',
-                        'scale',
-                        'grade_items',
-                        'grade_calculations',
-                        'grade_grades',
-                        'grade_grades_raw',
-                        'grade_grades_final',
-                        'grade_grades_text',
-                        'grade_outcomes',
-                        'grade_outcomes_courses');
-
-        foreach ($tables as $tablename) {
-            $table = new XMLDBTable('unittest_'.$tablename);
-            if (table_exists($table)) {
-                drop_table($table);
-            }
-            $table = new XMLDBTable('unittest_'.$tablename.'_history');
-            if (table_exists($table)) {
-                drop_table($table);
-            }
-        }
-
     /// Define field feedback to be added to grade_grades
         $table = new XMLDBTable('grade_grades');
         $field = new XMLDBField('feedback');
@@ -2210,47 +2180,94 @@ function xmldb_main_upgrade($oldversion=0) {
         }
     }
 
-    if ($result && $oldversion < 2007092500) {
+    if ($result && $oldversion < 2007092801) {
 
-    /// Define field decimals to be added to grade_items
-        $table = new XMLDBTable('grade_items');
-        $field = new XMLDBField('decimals');
-        $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '2', 'display');
+    /// Define index contextidlowerboundary (not unique) to be added to grade_letters
+        $table = new XMLDBTable('grade_letters');
+        $index = new XMLDBIndex('contextid-lowerboundary');
+        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
 
-    /// Launch add field decimals
-        $result = $result && add_field($table, $field);
+    /// Launch add index contextidlowerboundary
+        if (!index_exists($table, $field)) {
+            $result = $result && add_index($table, $index);
+        }
     }
 
-    if ($result && $oldversion < 2007092501) {
+    if ($result && $oldversion < 2007092803) {
 
-    /// Changing the default of field decimals on table grade_items to drop it
+/// Remove obsoleted unit tests tables - they will be recreated automatically
+        $tables = array('grade_categories',
+                        'scale',
+                        'grade_items',
+                        'grade_calculations',
+                        'grade_grades',
+                        'grade_grades_raw',
+                        'grade_grades_final',
+                        'grade_grades_text',
+                        'grade_outcomes',
+                        'grade_outcomes_courses');
+
+        foreach ($tables as $tablename) {
+            $table = new XMLDBTable('unittest_'.$tablename);
+            if (table_exists($table)) {
+                drop_table($table);
+            }
+            $table = new XMLDBTable('unittest_'.$tablename.'_history');
+            if (table_exists($table)) {
+                drop_table($table);
+            }
+        }
+
+    /// Define field display to be added to grade_items
+        $table = new XMLDBTable('grade_items');
+        $field = new XMLDBField('display');
+        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'sortorder');
+
+    /// Launch add field display
+        if (!field_exists($table, $field)) {
+            $result = $result && add_field($table, $field);
+        } else {
+            $result = $result && change_field_default($table, $field);
+        }
+
+    /// Define field display to be added to grade_items_history
+        $table = new XMLDBTable('grade_items_history');
+        $field = new XMLDBField('display');
+        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'sortorder');
+
+    /// Launch add field display
+        if (!field_exists($table, $field)) {
+            $result = $result && add_field($table, $field);
+        }
+
+
+    /// Define field decimals to be added to grade_items
         $table = new XMLDBTable('grade_items');
         $field = new XMLDBField('decimals');
         $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null, 'display');
 
-    /// Launch change of default for field decimals
-        $result = $result && change_field_default($table, $field);
-    }
-    if ($result && $oldversion < 2007092501) {
+    /// Launch add field decimals
+        if (!field_exists($table, $field)) {
+            $result = $result && add_field($table, $field);
+        } else {
+            $result = $result && change_field_default($table, $field);
+            $result = $result && change_field_notnull($table, $field);
+        }
 
-    /// Changing nullability of field decimals on table grade_items to null
-        $table = new XMLDBTable('grade_items');
+    /// Define field decimals to be added to grade_items_history
+        $table = new XMLDBTable('grade_items_history');
         $field = new XMLDBField('decimals');
         $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null, 'display');
 
-    /// Launch change of nullability for field decimals
-        $result = $result && change_field_notnull($table, $field);
-    }
+    /// Launch add field decimals
+        if (!field_exists($table, $field)) {
+            $result = $result && add_field($table, $field);
+        }
 
-    if ($result && $oldversion < 2007092801) {
 
-    /// Define index contextidlowerboundary (not unique) to be added to grade_letters
-        $table = new XMLDBTable('grade_letters');
-        $index = new XMLDBIndex('contextid-lowerboundary');
-        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
+    /// fix incorrect -1 default for grade_item->display
+        execute_sql("UPDATE {$CFG->prefix}grade_items SET display=0 WHERE display=-1");
 
-    /// Launch add index contextidlowerboundary
-        $result = $result && add_index($table, $index);
     }
 
 /*
index 6da19327580abb02bcebb613b4a3729f9ab34dfc..833fccb8ee4644723ffeba1bff3212a9259889cc 100644 (file)
@@ -188,6 +188,8 @@ class grade_test extends UnitTestCase {
             $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
             $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+            $table->addFieldInfo('display', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+            $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
             $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
@@ -417,6 +419,8 @@ class grade_test extends UnitTestCase {
             $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
             $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+            $table->addFieldInfo('display', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+            $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
             $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
index f61ae2438b6c014c76097e7b77092716fdbc3293..edc2239b453ac5feb6379e073eb13f7ac54676fb 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2007092801;  // YYYYMMDD = date
+    $version = 2007092803;  // YYYYMMDD = date
                             //       XY = increments within a single day
 
     $release = '1.9 Beta +';   // Human-friendly version name