]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16046 - beginning of, adding userid field to portfolio tempdata
authormjollnir_ <mjollnir_>
Tue, 19 Aug 2008 15:02:46 +0000 (15:02 +0000)
committermjollnir_ <mjollnir_>
Tue, 19 Aug 2008 15:02:46 +0000 (15:02 +0000)
lib/db/install.xml
lib/db/upgrade.php
version.php

index 55417de27c8a6063cbba2e3d08c1da502fa08141..22f23a1ef0048daa58724bfe71a47cef649908d7 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20080806" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20080820" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="data"/>
         <FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="dumping ground for portfolio callers to store their data in." PREVIOUS="id" NEXT="expirytime"/>
-        <FIELD NAME="expirytime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="time this record will expire (used for cron cleanups) - the start of export + 24 hours" PREVIOUS="data"/>
+        <FIELD NAME="expirytime" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="time this record will expire (used for cron cleanups) - the start of export + 24 hours" PREVIOUS="data" NEXT="userid"/>
+        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="psuedo fk to user.  this is stored in the serialised data structure in the data field, but added here for ease of lookups." PREVIOUS="expirytime"/>
       </FIELDS>
       <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="userfk"/>
+        <KEY NAME="userfk" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" COMMENT="fk to usertable" PREVIOUS="primary"/>
       </KEYS>
     </TABLE>
     <TABLE NAME="message_providers" COMMENT="This table stores the message providers (modules and core systems)" PREVIOUS="portfolio_tempdata" NEXT="message_processors">
index 872e255e19a281d10437e91e036a8084f00d3a6a..1ec8bec714d8ffe3751e7853ac344d67f15d5bfc 100644 (file)
@@ -672,6 +672,34 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint($result, 2008081600);
     }
 
+    if ($result && $oldversion < 2008081900) {
+    /// Define field userid to be added to portfolio_tempdata
+        $table = new xmldb_table('portfolio_tempdata');
+        $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'expirytime');
+
+    /// Conditionally launch add field userid
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+        $DB->set_field('portfolio_tempdata', 'userid', 0);
+    /// now change it to be notnull
+
+    /// Changing nullability of field userid on table portfolio_tempdata to not null
+        $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'expirytime');
+
+    /// Launch change of nullability for field userid
+        $dbman->change_field_notnull($table, $field);
+
+    /// Define key userfk (foreign) to be added to portfolio_tempdata
+        $table = new xmldb_table('portfolio_tempdata');
+        $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
+
+    /// Launch add key userfk
+        $dbman->add_key($table, $key);
+
+        upgrade_main_savepoint($result, 2008081900);
+    }
+
     return $result;
 }
 
index a922895f19b45e26f5f63d2627d57f4ea049ceb1..cdd99a0498a3802a5114b59b7054badbf97acb50 100644 (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 = 2008081600;  // YYYYMMDD   = date of the last version bump
+    $version = 2008081900;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20080819)';  // Human-friendly version name