Skip to content

Commit

Permalink
MDL-11504 fixed defaults in grade_items/display; added decimals and d…
Browse files Browse the repository at this point in the history
…isplay to grade_items_history
  • Loading branch information
skodak committed Sep 28, 2007
1 parent 284abb0 commit d926630
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 61 deletions.
2 changes: 1 addition & 1 deletion lib/db/install.xml
Expand Up @@ -1337,7 +1337,7 @@
<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"/>
Expand Down
135 changes: 76 additions & 59 deletions lib/db/upgrade.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}

/*
Expand Down
4 changes: 4 additions & 0 deletions lib/simpletest/fixtures/gradetest.php
Expand Up @@ -188,6 +188,8 @@ function prepare_test_tables() {
$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');
Expand Down Expand Up @@ -417,6 +419,8 @@ function prepare_test_history_tables() {
$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');
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -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
Expand Down

0 comments on commit d926630

Please sign in to comment.