From 42ff9ce68b932f844a326c4b8197cdcbd74ea002 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 22 Jul 2007 21:43:47 +0000 Subject: [PATCH] MDL-10111 migration of data into new gradebook; added new lib/db/upgradelib.php file (should be used by new groups upgrade code too) --- lib/db/install.xml | 32 +- lib/db/upgrade.php | 604 ++++++++++++++-------------------- lib/db/upgradelib.php | 176 ++++++++++ lib/grade/grade_category.php | 9 +- lib/gradelib.php | 100 +----- mod/assignment/db/upgrade.php | 2 +- mod/assignment/version.php | 4 +- mod/data/db/upgrade.php | 2 +- mod/data/version.php | 4 +- mod/forum/db/upgrade.php | 2 +- mod/forum/version.php | 4 +- mod/glossary/db/upgrade.php | 2 +- mod/glossary/version.php | 4 +- mod/lesson/db/upgrade.php | 2 +- mod/lesson/version.php | 4 +- mod/quiz/db/upgrade.php | 16 +- mod/quiz/version.php | 4 +- version.php | 2 +- 18 files changed, 471 insertions(+), 502 deletions(-) create mode 100644 lib/db/upgradelib.php diff --git a/lib/db/install.xml b/lib/db/install.xml index 2e906c388b..4d38d56e0d 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -1274,7 +1274,7 @@ - +
@@ -1292,7 +1292,19 @@
- +
+ + + + + + + + + + +
+ @@ -1566,7 +1578,7 @@
- +
@@ -1582,18 +1594,6 @@
- - - - - - - - - - - -
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 7c636cf2ea..7acad27d96 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -909,11 +909,77 @@ function xmldb_main_upgrade($oldversion=0) { $result = $result && add_key($table, $key); } -/// clenaup and recreate tables for course grade - if ($result && $oldversion < 2007063000) { + if ($result && $oldversion < 2007070603) { + // Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375) + set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'username', 'guest'); + } + + if ($result && $oldversion < 2007071400) { + /** + ** mnet application table + **/ + $table = new XMLDBTable('mnet_application'); + $table->comment = 'Information about applications on remote hosts'; + $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, + XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null); + $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '50', null, + XMLDB_NOTNULL, NULL, null, null, null); + $f = $table->addFieldInfo('display_name', XMLDB_TYPE_CHAR, '50', null, + XMLDB_NOTNULL, NULL, null, null, null); + $f = $table->addFieldInfo('xmlrpc_server_url', XMLDB_TYPE_CHAR, '255', null, + XMLDB_NOTNULL, NULL, null, null, null); + $f = $table->addFieldInfo('sso_land_url', XMLDB_TYPE_CHAR, '255', null, + XMLDB_NOTNULL, NULL, null, null, null); + + // PK and indexes + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + // Create the table + $result = $result && create_table($table); + + // Insert initial applications (moodle and mahara) + $application = new stdClass(); + $application->name = 'moodle'; + $application->display_name = 'Moodle'; + $application->xmlrpc_server_url = '/mnet/xmlrpc/server.php'; + $application->sso_land_url = '/auth/mnet/land.php'; + if ($result) { + $newid = insert_record('mnet_application', $application, false); + } + + $application = new stdClass(); + $application->name = 'mahara'; + $application->display_name = 'Mahara'; + $application->xmlrpc_server_url = '/api/xmlrpc/server.php'; + $application->sso_land_url = '/auth/xmlrpc/land.php'; + $result = $result && insert_record('mnet_application', $application, false); + + // New mnet_host->applicationid field + $table = new XMLDBTable('mnet_host'); + $field = new XMLDBField('applicationid'); + $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, $newid , 'last_log_id'); + + $result = $result && add_field($table, $field); + + /// Define key applicationid (foreign) to be added to mnet_host + $table = new XMLDBTable('mnet_host'); + $key = new XMLDBKey('applicationid'); + $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id')); + + /// Launch add key applicationid + $result = $result && add_key($table, $key); - /// Remove the all grade tables - we need empty db for course grade to work properly + } + + if ($result && $oldversion < 2007071607) { + require_once($CFG->dirroot . '/question/upgrade.php'); + $result = $result && question_remove_rqp_qtype_config_string(); + } + + + if ($result && $oldversion < 2007072200) { +/// Remove obsoleted unit tests tables - they will be recreated automatically $tables = array('grade_categories', + 'scale', 'grade_items', 'grade_calculations', 'grade_grades', @@ -921,7 +987,32 @@ function xmldb_main_upgrade($oldversion=0) { 'grade_grades_final', 'grade_grades_text', 'grade_outcomes', - 'grade_history'); + '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); + } + } + +/// Remove all grade tables used in development phases - we need new empty tables for final gradebook upgrade + $tables = array('grade_categories', + 'grade_items', + 'grade_calculations', + 'grade_grades', + 'grade_grades_raw', + 'grade_grades_final', + 'grade_grades_text', + 'grade_outcomes', + 'grade_outcomes_courses', + 'grade_history', + 'grade_import_newitem', + 'grade_import_values'); foreach ($tables as $table) { $table = new XMLDBTable($table); @@ -930,6 +1021,85 @@ function xmldb_main_upgrade($oldversion=0) { } } + $tables = array('grade_categories_history', + 'grade_items_history', + 'grade_grades_history', + 'grade_grades_text_history', + 'grade_scale_history', + 'grade_outcomes_history'); + + foreach ($tables as $table) { + $table = new XMLDBTable($table); + if (table_exists($table)) { + drop_table($table); + } + } + + + /// Define table grade_outcomes to be created + $table = new XMLDBTable('grade_outcomes'); + + /// Adding fields to table grade_outcomes + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + + /// Adding keys to table grade_outcomes + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); + $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id')); + $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id')); + + /// Launch create table for grade_outcomes + $result = $result && create_table($table); + + + /// Define table grade_outcomes_courses to be created + $table = new XMLDBTable('grade_outcomes_courses'); + + /// Adding fields to table grade_outcomes_courses + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + + /// Adding keys to table grade_outcomes_courses + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); + $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id')); + + /// Launch create table for grade_outcomes_courses + $result = $result && create_table($table); + + + /// Define table grade_categories to be created + $table = new XMLDBTable('grade_categories'); + + /// Adding fields to table grade_categories + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); + $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + + /// Adding keys to table grade_categories + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); + $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id')); + + /// Launch create table for grade_categories + $result = $result && create_table($table); + /// Define table grade_items to be created $table = new XMLDBTable('grade_items'); @@ -974,31 +1144,6 @@ function xmldb_main_upgrade($oldversion=0) { $result = $result && create_table($table); - /// Define table grade_categories to be created - $table = new XMLDBTable('grade_categories'); - - /// Adding fields to table grade_categories - $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); - $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); - $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); - - /// Adding keys to table grade_categories - $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); - $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id')); - - /// Launch create table for grade_categories - $result = $result && create_table($table); - - /// Define table grade_grades to be created $table = new XMLDBTable('grade_grades'); @@ -1055,56 +1200,66 @@ function xmldb_main_upgrade($oldversion=0) { $result = $result && create_table($table); - /// Define table grade_outcomes to be created - $table = new XMLDBTable('grade_outcomes'); + /// Define table grade_outcomes_history to be created + $table = new XMLDBTable('grade_outcomes_history'); - /// Adding fields to table grade_outcomes + /// Adding fields to table grade_outcomes_history $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); + $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - /// Adding keys to table grade_outcomes + /// Adding keys to table grade_outcomes_history $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_outcomes', array('id')); $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id')); - $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id')); + $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id')); - /// Launch create table for grade_outcomes - $result = $result && create_table($table); + /// Adding indexes to table grade_outcomes_history + $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action')); - } + /// Launch create table for grade_outcomes_history + $result = $result && create_table($table); - // add foreign key that was forgotten in last commit - if ($result && $oldversion < 2007063001) { - /// Define key gradeid (foreign) to be added to grade_grades_text - $table = new XMLDBTable('grade_grades_text'); - $key = new XMLDBKey('gradeid'); - $key->setAttributes(XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id')); + /// Define table grade_categories_history to be created + $table = new XMLDBTable('grade_categories_history'); - /// Launch add key gradeid - add_key($table, $key); - } + /// Adding fields to table grade_categories_history + $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); + $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); + $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); + $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - if ($result && $oldversion < 2007070602) { + /// Adding keys to table grade_categories_history + $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_categories', array('id')); + $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); + $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id')); + $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id')); - /// drop old grade history table - $table = new XMLDBTable('grade_history'); - if (table_exists($table)) { - drop_table($table); - } + /// Adding indexes to table grade_categories_history + $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action')); - /// drop old deleted field - $table = new XMLDBTable('grade_items'); - $field = new XMLDBField('deleted'); - if (field_exists($table, $field)) { - drop_field($table, $field); - } + /// Launch create table for grade_categories_history + $result = $result && create_table($table); /// Define table grade_items_history to be created @@ -1116,7 +1271,7 @@ function xmldb_main_upgrade($oldversion=0) { $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); @@ -1149,7 +1304,7 @@ function xmldb_main_upgrade($oldversion=0) { $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id')); $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id')); $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id')); - $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id')); + $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id')); /// Adding indexes to table grade_items_history $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action')); @@ -1158,39 +1313,6 @@ function xmldb_main_upgrade($oldversion=0) { $result = $result && create_table($table); - /// Define table grade_categories_history to be created - $table = new XMLDBTable('grade_categories_history'); - - /// Adding fields to table grade_categories_history - $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); - $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); - $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); - $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - - /// Adding keys to table grade_categories_history - $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_categories', array('id')); - $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); - $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id')); - $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id')); - - /// Adding indexes to table grade_categories_history - $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action')); - - /// Launch create table for grade_categories_history - $result = $result && create_table($table); - - /// Define table grade_grades_history to be created $table = new XMLDBTable('grade_grades_history'); @@ -1200,7 +1322,7 @@ function xmldb_main_upgrade($oldversion=0) { $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null); @@ -1223,7 +1345,7 @@ function xmldb_main_upgrade($oldversion=0) { $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN, array('rawscaleid'), 'scale', array('id')); $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id')); - $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id')); + $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id')); /// Adding indexes to table grade_grades_history $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action')); @@ -1241,7 +1363,7 @@ function xmldb_main_upgrade($oldversion=0) { $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null); $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); @@ -1254,7 +1376,7 @@ function xmldb_main_upgrade($oldversion=0) { $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_grades_text', array('id')); $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id')); $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id')); - $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id')); + $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id')); /// Adding indexes to table grade_grades_text_history $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action')); @@ -1263,181 +1385,6 @@ function xmldb_main_upgrade($oldversion=0) { $result = $result && create_table($table); - /// Define table grade_outcomes_history to be created - $table = new XMLDBTable('grade_outcomes_history'); - - /// Adding fields to table grade_outcomes_history - $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); - $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); - $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - - /// Adding keys to table grade_outcomes_history - $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_outcomes', array('id')); - $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); - $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id')); - $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id')); - $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id')); - - /// Adding indexes to table grade_outcomes_history - $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action')); - - /// Launch create table for grade_outcomes_history - $result = $result && create_table($table); - - - /// Define table scale_history to be created - $table = new XMLDBTable('scale_history'); - - /// Adding fields to table scale_history - $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); - $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); - $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); - $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); - $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('scale', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null); - - /// Adding keys to table scale_history - $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'scales', array('id')); - $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); - $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id')); - - /// Adding indexes to table scale_history - $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action')); - - /// Launch create table for scale_history - $result = $result && create_table($table); - - } - - if ($result && $oldversion < 2007070603) { - // Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375) - set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'username', 'guest'); - } - - if ($result && $oldversion < 2007070900) { - // fix loggeduser foreign key - $tables = array('grade_categories_history', - 'scale_history', - 'grade_items_history', - 'grade_grades_history', - 'grade_grades_text_history', - 'grade_outcomes_history'); - - foreach ($tables as $table) { - $table = new XMLDBTable($table); - $key = new XMLDBKey('userlogged'); - $key->setAttributes(XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id')); - add_key($table, $key); - } - } - - if ($result && $oldversion < 2007071000) { - - /// Define field overridden to be added to grade_grades - $table = new XMLDBTable('grade_grades'); - $field = new XMLDBField('overridden'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'exported'); - - /// Launch add field overridden - if (!field_exists($table, $field)) { - $result = $result && add_field($table, $field); - } - - /// Define field overridden to be added to grade_grades_history - $table = new XMLDBTable('grade_grades_history'); - $field = new XMLDBField('overridden'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'exported'); - - /// Launch add field overridden - if (!field_exists($table, $field)) { - $result = $result && add_field($table, $field); - } - - } - - if ($result && $oldversion < 2007071400) { - /** - ** mnet application table - **/ - $table = new XMLDBTable('mnet_application'); - $table->comment = 'Information about applications on remote hosts'; - $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, - XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null); - $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '50', null, - XMLDB_NOTNULL, NULL, null, null, null); - $f = $table->addFieldInfo('display_name', XMLDB_TYPE_CHAR, '50', null, - XMLDB_NOTNULL, NULL, null, null, null); - $f = $table->addFieldInfo('xmlrpc_server_url', XMLDB_TYPE_CHAR, '255', null, - XMLDB_NOTNULL, NULL, null, null, null); - $f = $table->addFieldInfo('sso_land_url', XMLDB_TYPE_CHAR, '255', null, - XMLDB_NOTNULL, NULL, null, null, null); - - // PK and indexes - $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); - // Create the table - $result = $result && create_table($table); - - // Insert initial applications (moodle and mahara) - $application = new stdClass(); - $application->name = 'moodle'; - $application->display_name = 'Moodle'; - $application->xmlrpc_server_url = '/mnet/xmlrpc/server.php'; - $application->sso_land_url = '/auth/mnet/land.php'; - if ($result) { - $newid = insert_record('mnet_application', $application, false); - } - - $application = new stdClass(); - $application->name = 'mahara'; - $application->display_name = 'Mahara'; - $application->xmlrpc_server_url = '/api/xmlrpc/server.php'; - $application->sso_land_url = '/auth/xmlrpc/land.php'; - $result = $result && insert_record('mnet_application', $application, false); - - // New mnet_host->applicationid field - $table = new XMLDBTable('mnet_host'); - $field = new XMLDBField('applicationid'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, $newid , 'last_log_id'); - - $result = $result && add_field($table, $field); - - /// Define key applicationid (foreign) to be added to mnet_host - $table = new XMLDBTable('mnet_host'); - $key = new XMLDBKey('applicationid'); - $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id')); - - /// Launch add key applicationid - $result = $result && add_key($table, $key); - - } - - if ($result && $oldversion < 2007071501) { - /// Drop old grade import tables - there are no data, it is for temporary storage only - $table = new XMLDBTable('grade_import_newitem'); - if (table_exists($table)) { - drop_table($table); - } - $table = new XMLDBTable('grade_import_values'); - if (table_exists($table)) { - drop_table($table); - } - - /// Define table grade_import_newitem to be created $table = new XMLDBTable('grade_import_newitem'); @@ -1452,6 +1399,7 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch create table for grade_import_newitem $result = $result && create_table($table); + /// Define table grade_import_values to be created $table = new XMLDBTable('grade_import_values'); @@ -1471,101 +1419,41 @@ function xmldb_main_upgrade($oldversion=0) { /// Launch create table for grade_import_values $result = $result && create_table($table); - } - - if ($result && $oldversion < 2007071607) { - require_once($CFG->dirroot . '/question/upgrade.php'); - $result = $result && question_remove_rqp_qtype_config_string(); - } - if ($result && $oldversion < 2007071700) { - - /// Define field aggregationcoef to be added to grade_items - $table = new XMLDBTable('grade_items'); - $field = new XMLDBField('aggregationcoef'); - $field->setAttributes(XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0', 'plusfactor'); - - /// Launch add field aggregationcoef - - /// Launch add field overridden - if (!field_exists($table, $field)) { - $result = $result && add_field($table, $field); - } - - /// Define field aggregationcoef to be added to grade_items - $table = new XMLDBTable('grade_items_history'); - $field = new XMLDBField('aggregationcoef'); - $field->setAttributes(XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0', 'plusfactor'); - - /// Launch add field aggregationcoef - - /// Launch add field overridden - if (!field_exists($table, $field)) { - $result = $result && add_field($table, $field); + /// upgrade the old 1.8 gradebook - migrade data into new grade tables + if ($result) { + require_once($CFG->libdir.'/db/upgradelib.php'); + if ($rs = get_recordset('course')) { + if ($rs->RecordCount() > 0) { + while ($course = rs_fetch_next_record($rs)) { + // this function uses SQL only, it must not be changed after 1.9 goes stable!! + if (!upgrade_18_gradebook($course->id)) { + $result = false; + break; + } + } + } + rs_close($rs); + } } - } - if ($result && $oldversion < 2007071900) { - - /// Define table grade_outcomes_courses to be created - $table = new XMLDBTable('grade_outcomes_courses'); - /// Adding fields to table grade_outcomes_courses - $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); - $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); - $table->addFieldInfo('outcomesid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); - - /// Adding keys to table grade_outcomes_courses - $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); - $table->addKeyInfo('outcomesid', XMLDB_KEY_FOREIGN, array('outcomesid'), 'grade_outcomes', array('id')); - - /// Launch create table for grade_outcomes_courses - $result = $result && create_table($table); - } - - if ($result && $oldversion < 2007072100) { - /// 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_history'); +/* + /// drop old gradebook tables + if ($result && $oldversion < 2007072209) { + $tables = array('grade_category', + 'grade_item', + 'grade_exceptions'); foreach ($tables as $table) { - $table = new XMLDBTable('unittest_'.$table); + $table = new XMLDBTable($table); if (table_exists($table)) { drop_table($table); } } - - /// Define field excluded to be added to grade_grades - $table = new XMLDBTable('grade_grades'); - $field = new XMLDBField('excluded'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'overridden'); - - /// Launch add field excluded - if (!field_exists($table, $field)) { - $result = $result && add_field($table, $field); - } - - /// Define field excluded to be added to grade_grades - $table = new XMLDBTable('grade_grades_history'); - $field = new XMLDBField('excluded'); - $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'overridden'); - - /// Launch add field excluded - if (!field_exists($table, $field)) { - $result = $result && add_field($table, $field); - } } - +*/ return $result; } ?> diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php new file mode 100644 index 0000000000..7930150f82 --- /dev/null +++ b/lib/db/upgradelib.php @@ -0,0 +1,176 @@ +libdir.'/gradelib.php'); // we need constants only + + // get all grade items with mod details and categories + $sql = "SELECT gi.*, cm.idnumber as cmidnumber, m.name as modname + FROM {$CFG->prefix}grade_item gi, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m + WHERE gi.courseid=$courseid AND m.id=gi.modid AND cm.instance=gi.cminstance + ORDER BY gi.sort_order ASC"; + + if (!$olditems = get_records_sql($sql)) { + //nothing to do - no items present in old gradebook + return true; + } + + if (!$oldcats = get_records('grade_category', 'courseid', $courseid, 'id')) { + //there should be at least uncategorised category - hmm, nothing to do + return true; + } + + $order = 1; + + // create course category + $course_category = new object(); + $course_category->courseid = $courseid; + $course_category->fullname = 'course grade category'; + $course_category->parent = null; + $course_category->aggregation = GRADE_AGGREGATE_MEAN_ALL; + $course_category->timemodified = $course_category->timecreated = time(); + if (!$course_category->id = insert_record('grade_categories', $course_category)) { + return false; + } + $course_category->depth = 1; + $course_category->path = '/'.$course_category->id; + if (!update_record('grade_categories', $course_category)) { + return false; + } + + // create course item + $course_item = new object(); + $course_item->courseid = $courseid; + $course_item->itemtype = 'course'; + $course_item->iteminstance = $course_category->id; + $course_item->gradetype = GRADE_TYPE_VALUE; + $course_item->sortorder = $order++; + $course_item->timemodified = $course_item->timecreated = $course_category->timemodified; + $course_item->needsupdate = 1; + if (!insert_record('grade_items', $course_item)) { + return false; + } + + // existing categories + $categories = array(); + $hiddenoldcats = array(); + if (count($oldcats) == 1) { + $oldcat = reset($oldcats); + if ($oldcat->drop_x_lowest) { + $course_category->droplow = $oldcat->drop_x_lowest; + update_record('grade_categories', $course_category); + } + $categories[$oldcat->id] = $course_category; + + } else { + foreach ($oldcats as $oldcat) { + $category = new object(); + $category->courseid = $courseid; + $category->fullname = addslashes($oldcat->name); + $category->parent = $course_category->id; + $category->droplow = $oldcat->drop_x_lowest; + $category->aggregation = GRADE_AGGREGATE_MEAN_ALL; + $category->timemodified = $category->timecreated = time(); + if (!$category->id = insert_record('grade_categories', $category)) { + return false; + } + $category->depth = 2; + $category->path = '/'.$course_category->id.'/'.$category->id; + if (!update_record('grade_categories', $category)) { + return false; + } + + $categories[$oldcat->id] = $category; + + $item = new object(); + $item->courseid = $courseid; + $item->itemtype = 'category'; + $item->iteminstance = $category->id; + $item->gradetype = GRADE_TYPE_VALUE; + $item->plusfactor = $oldcat->bonus_points; + $item->hidden = $oldcat->hidden; + $item->aggregationcoef = $oldcat->weight; + $item->sortorder = $order++; + $item->timemodified = $item->timecreated = $category->timemodified; + $item->needsupdate = 1; + if (!insert_record('grade_items', $item)) { + return false; + } + if ($item->hidden) { + $hiddenoldcats[] = $oldcat->id; + } + } + + $course_category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN_ALL; + update_record('grade_categories', $course_category); + } + unset($oldcats); + + // existing items + $newitems = array(); + foreach ($olditems as $olditem) { + if (empty($categories[$olditem->category])) { + continue; // faulty record + } + // proper data are set during activity upgrade or legacy grade fetching + $item = new object(); + $item->courseid = $courseid; + $item->itemtype = 'mod'; + $item->itemmodule = $olditem->modname; + $item->iteminstance = $olditem->cminstance; + $item->itemname = NULL; + $item->itemnumber = 0; + $item->gradetype = GRADE_TYPE_VALUE; + $item->multfactor = $olditem->scale_grade; + $item->hidden = (int)in_array($olditem->category, $hiddenoldcats); + $item->aggregationcoef = $olditem->extra_credit; + $item->sortorder = $order++; + $item->timemodified = $item->timecreated = time(); + $item->needsupdate = 1; + $item->categoryid = $categories[$olditem->category]->id; + if (!$item->id = insert_record('grade_items', $item)) { + return false; + } + + $newitems[$olditem->id] = $item; + + if ($olditem->extra_credit and $categories[$olditem->category]->aggregation != GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL) { + $categories[$olditem->category]->aggregation = GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL; + update_record('grade_categories', $categories[$olditem->category]); + } + } + unset($olditems); + + // setup up exception handling - exclude grade from aggregation + if ($exceptions = get_records('grade_exceptions', 'courseid', $courseid)) { + foreach ($exceptions as $exception) { + if (!array_key_exists($exception->grade_itemid, $newitems)) { + continue; // broken record + } + $grade = new object(); + $grade->excluded = time(); + $grade->itemid = $newitems[$exception->grade_itemid]->id; + $grade->userid = $exception->userid; + $grade->timemodified = $grade->timecreated = $grade->excluded; + insert_record('grade_grades', $grade); + } + } + + return true; +} + +?> diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 6e8f2ef62a..6f4a512851 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -254,10 +254,11 @@ class grade_category extends grade_object { } function insert_course_category($courseid) { - $this->courseid = $courseid; - $this->fullname = 'course grade category'; - $this->path = null; - $this->parent = null; + $this->courseid = $courseid; + $this->fullname = 'course grade category'; + $this->path = null; + $this->parent = null; + $this->aggregate = GRADE_AGGREGATE_MEAN_ALL; if (!parent::insert('system')) { debugging("Could not insert this category: " . print_r($this, true)); diff --git a/lib/gradelib.php b/lib/gradelib.php index 50b4b8e315..7f47530a0a 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -609,7 +609,7 @@ function grade_update_mod_grades($modinstance) { function grade_get_legacy_grade_item($modinstance, $grademax, $scaleid) { // does it already exist? - if ($grade_items = grade_grade::fetch_all(array('courseid'=>$modinstance->course, 'itemtype'=>'mod', 'itemmodule'=>$modinstance->modname, 'iteminstance'=>$modinstance->id, 'itemnumber'=>0))) { + if ($grade_items = grade_item::fetch_all(array('courseid'=>$modinstance->course, 'itemtype'=>'mod', 'itemmodule'=>$modinstance->modname, 'iteminstance'=>$modinstance->id, 'itemnumber'=>0))) { if (count($grade_items) > 1) { debugging('Multiple legacy grade_items found.'); return false; @@ -667,103 +667,6 @@ function grade_get_legacy_grade_item($modinstance, $grademax, $scaleid) { return $grade_item; } -/** - * This function is used to migrade old data and settings from old gradebook into new grading system. - * @param int $courseid - */ -function grade_upgrade_oldgradebook($courseid) { - global $CFG; - - // regrade everything - grade_force_full_regrading($courseid); - - // course grade data - $course_category = grade_category::fetch_course_category($courseid); - $course_item = $course_category->get_grade_item(); - - // first create all categories if needed - $categories = array(); - $oldcats = get_records('grade_category', 'courseid', $courseid, 'id'); - - if (empty($oldcats) or count($oldcats) == 1) { - $course_category->aggregation = GRADE_AGGREGATE_MEAN_ALL; - $course_category->update('upgrade'); - if ($oldcats) { - $oldcat = reset($oldcats); - $categories[$oldcat->id] =& $course_category; - } - - } else { - foreach ($oldcats as $oldcat) { - $newcat = new grade_category(array('courseid'=>$courseid, 'fullname'=>$oldcat->name)); - $newcat->droplow = $oldcat->drop_x_lowest; - $newcat->aggregation = GRADE_AGGREGATE_MEAN_ALL; - - if (empty($newcat->id)) { - $newcat->insert('upgrade'); - } else { - $newcat->update('upgrade'); - } - - $categories[$oldcat->id] =& $newcat; - - $catitem = $newcat->get_grade_item(); - $catitem->gradetype = GRADE_TYPE_VALUE; - $catitem->plusfactor = $oldcat->bonus_points; - $catitem->hidden = $oldcat->hidden; - $catitem->aggregationcoef = $oldcat->weight; - $catitem->update('upgrade'); - } - - $course_category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN_ALL; - $course_category->update('upgrade'); - } - - - $newitems = array(); - // get all grade items with mod details - $sql = "SELECT gi.*, cm.idnumber as cmidnumber, m.name as modname - FROM {$CFG->prefix}grade_item gi, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m - WHERE gi.courseid=$courseid AND m.id=gi.modid AND cm.instance=gi.cminstance - ORDER BY gi.sortorder ASC"; - - if ($olditems = get_records_sql($sql)) { - foreach ($olditems as $olditem) { - $newitem = new grade_item(array('courseid'=>$olditem->courseid, 'itemtype'=>'mod', 'itemmodule'=>$olditem->modname, 'iteminstance'=>$olditem->cminstance, 'itemnumber'=>0)); - $newitem->multfactor = $olditem->scale_grade; - $newitem->aggregationcoef = $olditem->extra_credit; - if ($olditem->extra_credit and $categories[$olditem->category]->aggregation != GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL) { - $categories[$olditem->category]->aggregation = GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL; - $categories[$olditem->category]->update('upgrade'); - } - - if (empty($newitem->id)) { - $newitem->gradetype = GRADE_TYPE_NONE; // type not known yet - $newitem->insert('upgrade'); - } else { - $newitem->update('upgrade'); - } - - if (!empty($olditem->category)) { - $newitem->set_parent($categories[$olditem->category]->id); - } - $newitems[$olditem->id] = $newitem; - } - } - - // setup up exception handling - override grade with NULL - if ($exceptions = get_records('grade_exceptions', 'courseid', $courseid)) { - foreach ($exceptions as $exception) { - if (!array_key_exists($exception->grade_itemid, $newitems)) { - continue; // broken record - } - $grade_item = grade_item::fetch(array('id'=>$newitems[$exception->grade_itemid])); - $grade = $grade_item->get_grade($exception->userid); - $grade->excluded = time(); - $grade->update(); - } - } -} /** * Builds an array of percentages indexed by integers for the purpose of building a select drop-down element. @@ -775,4 +678,5 @@ function grade_upgrade_oldgradebook($courseid) { function build_percentages_array($steps=1, $order='desc', $lowest=0, $highest=100) { // TODO reject or implement } + ?> diff --git a/mod/assignment/db/upgrade.php b/mod/assignment/db/upgrade.php index 8f946dfe72..63c1f7a8aa 100644 --- a/mod/assignment/db/upgrade.php +++ b/mod/assignment/db/upgrade.php @@ -23,7 +23,7 @@ function xmldb_assignment_upgrade($oldversion=0) { $result = true; - if ($result && $oldversion < 2007060600) { + if ($result && $oldversion < 2007072200) { require_once $CFG->dirroot.'/mod/assignment/lib.php'; // too much debug output $db->debug = false; diff --git a/mod/assignment/version.php b/mod/assignment/version.php index bf82d41dc2..60d7cfdfcb 100644 --- a/mod/assignment/version.php +++ b/mod/assignment/version.php @@ -5,8 +5,8 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2007060700; -$module->requires = 2007052800; // Requires this Moodle version +$module->version = 2007072200; +$module->requires = 2007072200; // Requires this Moodle version $module->cron = 60; ?> diff --git a/mod/data/db/upgrade.php b/mod/data/db/upgrade.php index c86fa7ee45..e027f183d2 100644 --- a/mod/data/db/upgrade.php +++ b/mod/data/db/upgrade.php @@ -55,7 +55,7 @@ function xmldb_data_upgrade($oldversion=0) { } - if ($result && $oldversion < 2007060600) { + if ($result && $oldversion < 2007072200) { require_once($CFG->dirroot.'/mod/data/lib.php'); // too much debug output $db->debug = false; diff --git a/mod/data/version.php b/mod/data/version.php index c2f82f0b44..e54cd9ef60 100644 --- a/mod/data/version.php +++ b/mod/data/version.php @@ -5,8 +5,8 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2007060600; -$module->requires = 2007060100; // Requires this Moodle version +$module->version = 2007072200; +$module->requires = 2007072200; // Requires this Moodle version $module->cron = 60; ?> diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index 080dab16c0..f7c24c7f91 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -32,7 +32,7 @@ function xmldb_forum_upgrade($oldversion=0) { /// $result = result of "/lib/ddllib.php" function calls /// } - if ($result && $oldversion < 2007060600) { + if ($result && $oldversion < 2007072200) { require_once($CFG->dirroot.'/mod/forum/lib.php'); // too much debug output $db->debug = false; diff --git a/mod/forum/version.php b/mod/forum/version.php index c2f82f0b44..e54cd9ef60 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -5,8 +5,8 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2007060600; -$module->requires = 2007060100; // Requires this Moodle version +$module->version = 2007072200; +$module->requires = 2007072200; // Requires this Moodle version $module->cron = 60; ?> diff --git a/mod/glossary/db/upgrade.php b/mod/glossary/db/upgrade.php index defcd49edf..5237f7bb96 100644 --- a/mod/glossary/db/upgrade.php +++ b/mod/glossary/db/upgrade.php @@ -60,7 +60,7 @@ function xmldb_glossary_upgrade($oldversion=0) { $result = $result && drop_field($table, $field); } - if ($result && $oldversion < 2007060600) { + if ($result && $oldversion < 2007072200) { require_once($CFG->dirroot.'/mod/glossary/lib.php'); // too much debug output $db->debug = false; diff --git a/mod/glossary/version.php b/mod/glossary/version.php index 965c1cb574..9b745b42ff 100644 --- a/mod/glossary/version.php +++ b/mod/glossary/version.php @@ -5,8 +5,8 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2007060600; -$module->requires = 2007060100; // Requires this Moodle version +$module->version = 2007072200; +$module->requires = 2007072200; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) ?> diff --git a/mod/lesson/db/upgrade.php b/mod/lesson/db/upgrade.php index 202c134089..f53fc1dac9 100644 --- a/mod/lesson/db/upgrade.php +++ b/mod/lesson/db/upgrade.php @@ -56,7 +56,7 @@ function xmldb_lesson_upgrade($oldversion=0) { $result = $result && change_field_notnull($table, $field); } - if ($result && $oldversion < 2007061100) { + if ($result && $oldversion < 2007072200) { require_once($CFG->dirroot.'/mod/lesson/lib.php'); // too much debug output $db->debug = false; diff --git a/mod/lesson/version.php b/mod/lesson/version.php index 244c4ec150..0392b6a830 100644 --- a/mod/lesson/version.php +++ b/mod/lesson/version.php @@ -8,8 +8,8 @@ * @package lesson **/ -$module->version = 2007061100; // The current module version (Date: YYYYMMDDXX) -$module->requires = 2007060502; // Requires this Moodle version +$module->version = 2007072200; // The current module version (Date: YYYYMMDDXX) +$module->requires = 2007072200; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) ?> diff --git a/mod/quiz/db/upgrade.php b/mod/quiz/db/upgrade.php index 5a4eabf730..0e41640e45 100644 --- a/mod/quiz/db/upgrade.php +++ b/mod/quiz/db/upgrade.php @@ -47,14 +47,6 @@ function xmldb_quiz_upgrade($oldversion=0) { $result = $result && add_index($table, $index); } - if ($result && $oldversion < 2007061100) { - require_once $CFG->dirroot.'/mod/quiz/lib.php'; - // too much debug output - $db->debug = false; - quiz_update_grades(); - $db->debug = true; - } - if ($result && $oldversion < 2007070200) { /// Changing precision of field timelimit on table quiz to (10) @@ -66,6 +58,14 @@ function xmldb_quiz_upgrade($oldversion=0) { $result = $result && change_field_precision($table, $field); } + if ($result && $oldversion < 2007072200) { + require_once $CFG->dirroot.'/mod/quiz/lib.php'; + // too much debug output + $db->debug = false; + quiz_update_grades(); + $db->debug = true; + } + return $result; } diff --git a/mod/quiz/version.php b/mod/quiz/version.php index d0f0a9c131..1f0f75ad83 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -5,8 +5,8 @@ // This fragment is called by moodle_needs_upgrading() and /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2007070200; // The (date) version of this module -$module->requires = 2007062401; // Requires this Moodle version +$module->version = 2007072200; // The (date) version of this module +$module->requires = 2007072200; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)? ?> diff --git a/version.php b/version.php index e0255015de..22dc0b9059 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 = 2007072100; // YYYYMMDD = date + $version = 2007072201; // YYYYMMDD = date // XY = increments within a single day $release = '1.9 dev'; // Human-friendly version name -- 2.39.5