From d926630485ee7826d15a8f1228e01aecfacf4357 Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 28 Sep 2007 21:00:31 +0000 Subject: [PATCH] MDL-11504 fixed defaults in grade_items/display; added decimals and display to grade_items_history --- lib/db/install.xml | 2 +- lib/db/upgrade.php | 135 +++++++++++++++++++--------------- lib/simpletest/fixtures/gradetest.php | 4 + version.php | 2 +- 4 files changed, 82 insertions(+), 61 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index 222316ea8..4338e39d4 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1337,7 +1337,7 @@ - + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 6929e4493..74d4b0a6c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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); } /* diff --git a/lib/simpletest/fixtures/gradetest.php b/lib/simpletest/fixtures/gradetest.php index 6da193275..833fccb8e 100644 --- a/lib/simpletest/fixtures/gradetest.php +++ b/lib/simpletest/fixtures/gradetest.php @@ -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'); diff --git a/version.php b/version.php index f61ae2438..edc2239b4 100644 --- a/version.php +++ b/version.php @@ -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 -- 2.11.4.GIT