MDL-10111 migration of data into new gradebook; added new lib/db/upgradelib.php file (should be used by new groups upgrade code too)

This commit is contained in:
skodak 2007-07-22 21:43:47 +00:00
parent 63b1cf1fe2
commit 42ff9ce68b
18 changed files with 471 additions and 502 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20070721" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20070722" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@ -1274,7 +1274,7 @@
<KEY NAME="handlerid" TYPE="foreign" FIELDS="handlerid" REFTABLE="events_handlers" REFFIELDS="id" PREVIOUS="queuedeventid"/>
</KEYS>
</TABLE>
<TABLE NAME="grade_outcomes" COMMENT="This table describes the outcomes used in the system. An outcome is a statement tied to a rubric scale from low to high, such as “Not met, Borderline, Met” (stored as 0,1 or 2)" PREVIOUS="events_queue_handlers" NEXT="grade_categories">
<TABLE NAME="grade_outcomes" COMMENT="This table describes the outcomes used in the system. An outcome is a statement tied to a rubric scale from low to high, such as “Not met, Borderline, Met” (stored as 0,1 or 2)" PREVIOUS="events_queue_handlers" NEXT="grade_outcomes_courses">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Mostly these are defined site wide ie NULL" PREVIOUS="id" NEXT="shortname"/>
@ -1292,7 +1292,19 @@
<KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id" PREVIOUS="scaleid"/>
</KEYS>
</TABLE>
<TABLE NAME="grade_categories" COMMENT="This table keeps information about categories, used for grouping items." PREVIOUS="grade_outcomes" NEXT="grade_items">
<TABLE NAME="grade_outcomes_courses" COMMENT="stores what outcomes are used in what courses." PREVIOUS="grade_outcomes" NEXT="grade_categories">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the course" PREVIOUS="id" NEXT="outcomeid"/>
<FIELD NAME="outcomeid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the outcome" PREVIOUS="courseid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="courseid"/>
<KEY NAME="courseid" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id" PREVIOUS="primary" NEXT="outcomeid"/>
<KEY NAME="outcomeid" TYPE="foreign" FIELDS="outcomeid" REFTABLE="grade_outcomes" REFFIELDS="id" PREVIOUS="courseid"/>
</KEYS>
</TABLE>
<TABLE NAME="grade_categories" COMMENT="This table keeps information about categories, used for grouping items." PREVIOUS="grade_outcomes_courses" NEXT="grade_items">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="The course this grade category is part of" PREVIOUS="id" NEXT="parent"/>
@ -1566,7 +1578,7 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me"/>
</KEYS>
</TABLE>
<TABLE NAME="grade_import_values" COMMENT="Temporary table for importing grades" PREVIOUS="grade_import_newitem" NEXT="grade_outcomes_courses">
<TABLE NAME="grade_import_values" COMMENT="Temporary table for importing grades" PREVIOUS="grade_import_newitem">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="itemid"/>
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="if set, this points to existing grade_items id" PREVIOUS="id" NEXT="newgradeitem"/>
@ -1582,18 +1594,6 @@
<KEY NAME="newgradeitem" TYPE="foreign" FIELDS="newgradeitem" REFTABLE="grade_import_newitem" REFFIELDS="id" PREVIOUS="itemid"/>
</KEYS>
</TABLE>
<TABLE NAME="grade_outcomes_courses" COMMENT="stores what outcomes are used in what courses." PREVIOUS="grade_import_values">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the course" PREVIOUS="id" NEXT="outcomesid"/>
<FIELD NAME="outcomesid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the outcome" PREVIOUS="courseid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="courseid"/>
<KEY NAME="courseid" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id" PREVIOUS="primary" NEXT="outcomesid"/>
<KEY NAME="outcomesid" TYPE="foreign" FIELDS="outcomesid" REFTABLE="grade_outcomes" REFFIELDS="id" PREVIOUS="courseid"/>
</KEYS>
</TABLE>
</TABLES>
<STATEMENTS>
<STATEMENT NAME="insert mnet_application" TYPE="insert" TABLE="mnet_application" COMMENT="Initial insert of records on table mnet_application" NEXT="insert log_display">

View File

@ -909,10 +909,98 @@ 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');
}
/// Remove the all grade tables - we need empty db for course grade to work properly
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 < 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',
'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);
}
}
/// 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',
@ -921,7 +1009,10 @@ function xmldb_main_upgrade($oldversion=0) {
'grade_grades_final',
'grade_grades_text',
'grade_outcomes',
'grade_history');
'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
/// 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 table grade_categories_history to be created
$table = new XMLDBTable('grade_categories_history');
/// 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'));
/// 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');
/// Launch add key gradeid
add_key($table, $key);
}
/// 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'));
if ($result && $oldversion < 2007070602) {
/// Adding indexes to table grade_categories_history
$table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
/// drop old grade history table
$table = new XMLDBTable('grade_history');
if (table_exists($table)) {
drop_table($table);
}
/// 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);
/// 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);
}
}
/// 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);
}
}
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;
}
?>

176
lib/db/upgradelib.php Normal file
View File

@ -0,0 +1,176 @@
<?php //$Id$
/*
* This file is used for special upgrade functions - for example groups and gradebook.
* These functions must use SQL and dabase related functions only- no other Moodle API,
* because it might depend on db structures that are not yet present during upgrade.
* (Do not use functions from accesslib.php, grades classes or group functions at all!)
*/
/**
* This function is used to migrade old data and settings from old gradebook into new grading system.
* It is executed only once for each course during upgrade to 1.9, all grade tables must be empty initially.
* @param int $courseid
*/
function upgrade_18_gradebook($courseid) {
global $CFG;
require_once($CFG->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;
}
?>

View File

@ -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));

View File

@ -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
}
?>

View File

@ -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;

View File

@ -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;
?>

View File

@ -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;

View File

@ -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;
?>

View File

@ -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;

View File

@ -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;
?>

View File

@ -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;

View File

@ -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)
?>

View File

@ -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;

View File

@ -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)
?>

View File

@ -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;
}

View File

@ -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)?
?>

View 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 = 2007072100; // YYYYMMDD = date
$version = 2007072201; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.9 dev'; // Human-friendly version name