From 55fe807451961c3ed3003bb1c8d4176bf8ac8577 Mon Sep 17 00:00:00 2001 From: Aparup Banerjee Date: Tue, 14 Sep 2010 09:04:28 +0000 Subject: [PATCH] enrol flatfile MDL-23892 DB schema updates to the buffer table. --- enrol/flatfile/db/install.xml | 21 ++++++++++++--------- enrol/flatfile/db/upgrade.php | 20 ++++++++++++-------- enrol/flatfile/lib.php | 12 ++++++------ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/enrol/flatfile/db/install.xml b/enrol/flatfile/db/install.xml index 8bd4e388f25..ea0c6cfe90e 100644 --- a/enrol/flatfile/db/install.xml +++ b/enrol/flatfile/db/install.xml @@ -6,17 +6,20 @@ - - - - - - - - + + + + + + + + - + + + +
diff --git a/enrol/flatfile/db/upgrade.php b/enrol/flatfile/db/upgrade.php index d495d78f4dd..2cb5a4c724b 100644 --- a/enrol/flatfile/db/upgrade.php +++ b/enrol/flatfile/db/upgrade.php @@ -38,17 +38,20 @@ function xmldb_enrol_flatfile_upgrade($oldversion) { $table = new xmldb_table('enrol_flatfile'); // Adding fields to table enrol_flatfile - $table->add_field('id', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('action', XMLDB_TYPE_CHAR, '10', null, null, null, 'add'); - $table->add_field('role_id', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('user_id', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('course_id', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('timestart', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('timeend', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, '0'); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null); + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('action', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null); + $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); + $table->add_field('timestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + $table->add_field('timeend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); // Adding keys to table enrol_flatfile $table->add_key('id', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('courseid-id', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); + $table->add_key('userid-id', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); + $table->add_key('roleid-id', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); // Conditionally launch create table for enrol_flatfile if (!$dbman->table_exists($table)) { @@ -59,5 +62,6 @@ function xmldb_enrol_flatfile_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2010091400, 'enrol', 'flatfile'); } + return $result; } diff --git a/enrol/flatfile/lib.php b/enrol/flatfile/lib.php index fabfa2cddb0..79719235845 100644 --- a/enrol/flatfile/lib.php +++ b/enrol/flatfile/lib.php @@ -191,10 +191,10 @@ class enrol_flatfile_plugin extends enrol_plugin { if ($future_enrols = $DB->get_records('enrol_flatfile', null, '')) { foreach($future_enrols as $id => $future_en) { $this->log .= "Processing buffered enrolments.\n"; - $user = $DB->get_record("user", array("id"=>$future_en->user_id)); - $course = $DB->get_record("course", array("id"=>$future_en->course_id)); + $user = $DB->get_record("user", array("id"=>$future_en->userid)); + $course = $DB->get_record("course", array("id"=>$future_en->courseid)); // enrol the person. - if($this->process_records($future_en->action, $future_en->role_id, + if($this->process_records($future_en->action, $future_en->roleid, $user, $course, $future_en->timestart, $future_en->timeend, false)) { //ok record went thru, get rid of the record. $DB->delete_records('enrol_flatfile', array('id'=>$future_en->id)); @@ -215,9 +215,9 @@ class enrol_flatfile_plugin extends enrol_plugin { // populate into enrol_flatfile table as a future role to be assigned by cron. $future_en = new object(); $future_en->action = $action; - $future_en->role_id = $roleid; - $future_en->user_id = $user->id; - $future_en->course_id = $course->id; + $future_en->roleid = $roleid; + $future_en->userid = $user->id; + $future_en->courseid = $course->id; $future_en->timestart = $timestart; $future_en->timeend = $timeend; $future_en->timemodified = time();