enrol flatfile MDL-23892 DB schema updates to the buffer table.
authorAparup Banerjee <nebgor@gmail.com>
Tue, 14 Sep 2010 09:04:28 +0000 (09:04 +0000)
committerAparup Banerjee <nebgor@gmail.com>
Tue, 14 Sep 2010 09:04:28 +0000 (09:04 +0000)
enrol/flatfile/db/install.xml
enrol/flatfile/db/upgrade.php
enrol/flatfile/lib.php

index 8bd4e38..ea0c6cf 100644 (file)
@@ -6,17 +6,20 @@
   <TABLES>
     <TABLE NAME="enrol_flatfile" COMMENT="enrol_flatfile table retrofitted from MySQL">
       <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="action"/>
-        <FIELD NAME="action" TYPE="char" LENGTH="10" NOTNULL="false" DEFAULT="add" SEQUENCE="false" PREVIOUS="id" NEXT="role_id"/>
-        <FIELD NAME="role_id" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="action" NEXT="user_id"/>
-        <FIELD NAME="user_id" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="role_id" NEXT="course_id"/>
-        <FIELD NAME="course_id" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="user_id" NEXT="timestart"/>
-        <FIELD NAME="timestart" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="course_id" NEXT="timeend"/>
-        <FIELD NAME="timeend" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="timestart" NEXT="timemodified"/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" PREVIOUS="timeend"/>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="action"/>
+        <FIELD NAME="action" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="roleid"/>
+        <FIELD NAME="roleid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="action" NEXT="userid"/>
+        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="roleid" NEXT="courseid"/>
+        <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="userid" NEXT="timestart"/>
+        <FIELD NAME="timestart" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="courseid" NEXT="timeend"/>
+        <FIELD NAME="timeend" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timestart" NEXT="timemodified"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timeend"/>
       </FIELDS>
       <KEYS>
-        <KEY NAME="id" TYPE="primary" FIELDS="id" COMMENT="primary key"/>
+        <KEY NAME="id" TYPE="primary" FIELDS="id" COMMENT="primary key" NEXT="courseid-id"/>
+        <KEY NAME="courseid-id" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id" PREVIOUS="id" NEXT="userid-id"/>
+        <KEY NAME="userid-id" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="courseid-id" NEXT="roleid-id"/>
+        <KEY NAME="roleid-id" TYPE="foreign" FIELDS="roleid" REFTABLE="role" REFFIELDS="id" PREVIOUS="userid-id"/>
       </KEYS>
     </TABLE>
   </TABLES>
index d495d78..2cb5a4c 100644 (file)
@@ -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;
 }
index fabfa2c..7971923 100644 (file)
@@ -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();