]> git.mjollnir.org Git - moodle.git/commitdiff
portfolio - MDL-19356 - add instance column to portfolio_tempdata
authorPenelope Leach <penny@catalyst.net.nz>
Mon, 16 Nov 2009 15:02:52 +0000 (15:02 +0000)
committerPenelope Leach <penny@catalyst.net.nz>
Mon, 16 Nov 2009 15:02:52 +0000 (15:02 +0000)
this is the first step in moving towards supporting multiple exports per session.

however, some plugins aren't going to be able to support this (eg box.net) so
we add the instance to the tempdata table, so that we can quickly check whether
we have an export of the same *type* of plugin in the session.

lib/db/install.xml
lib/db/upgrade.php
lib/portfolio/exporter.php
lib/portfolio/plugin.php
version.php

index fee5cbc5246a7863bd112a3b41f66523b44b2f12..a936b9383178cc287a390f0a02fd96c6aab054cb 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20091106" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20091116" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <FIELD NAME="value" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="config value" PREVIOUS="name"/>
       </FIELDS>
       <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="instance"/>
-        <KEY NAME="instance" TYPE="foreign" FIELDS="instance" REFTABLE="portfolio_instance" REFFIELDS="id" COMMENT="fk to plugin instance" PREVIOUS="primary"/>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="instancefk"/>
+        <KEY NAME="instancefk" TYPE="foreign" FIELDS="instance" REFTABLE="portfolio_instance" REFFIELDS="id" COMMENT="fk to plugin instance" PREVIOUS="primary"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="name" UNIQUE="false" FIELDS="name" COMMENT="name index"/>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="data"/>
         <FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="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" 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" 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"/>
+        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="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" NEXT="instance"/>
+        <FIELD NAME="instance" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="which portfolio plugin instance is being used" PREVIOUS="userid"/>
       </FIELDS>
       <KEYS>
         <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"/>
+        <KEY NAME="userfk" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" COMMENT="fk to usertable" PREVIOUS="primary" NEXT="instance"/>
+        <KEY NAME="instance" TYPE="foreign" FIELDS="instance" REFTABLE="portfolio_instance" REFFIELDS="id" COMMENT="fk to portfolio_instance" PREVIOUS="userfk"/>
       </KEYS>
     </TABLE>
     <TABLE NAME="message_providers" COMMENT="This table stores the message providers (modules and core systems)" PREVIOUS="portfolio_tempdata" NEXT="message_processors">
       </KEYS>
     </TABLE>
   </TABLES>
-</XMLDB>
\ No newline at end of file
+</XMLDB>
index fb0e7c0ba447b7230336ec86cfc1f808722809b6..95e8ea428fe1115eca673d06ed537b00ba17b2d0 100644 (file)
@@ -2761,6 +2761,27 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
         upgrade_main_savepoint($result, 2009110605);
     }
 
+    if ($result && $oldversion < 2009111600) {
+
+    /// Define field instance to be added to portfolio_tempdata
+        $table = new xmldb_table('portfolio_tempdata');
+        $field = new xmldb_field('instance', XMLDB_TYPE_INTEGER, '10', null, null, null, '0', 'userid');
+
+    /// Conditionally launch add field instance
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+       $key = new xmldb_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
+
+    /// Launch add key instancefk
+        $dbman->add_key($table, $key);
+
+    /// Main savepoint reached
+        upgrade_main_savepoint($result, 2009111600);
+    }
+
+
     return $result;
 }
 
index c79c247227887f09f9423b2076fe6b4f0b79969b..801dc0cf6c5f9bde396d4f6e30c4b7c4f7b280a4 100644 (file)
@@ -619,11 +619,15 @@ class portfolio_exporter {
                 'data' => base64_encode(serialize($this)),
                 'expirytime' => time() + (60*60*24),
                 'userid' => $this->user->id,
+                'instance' => (empty($this->instance)) ? null : $this->instance->get('id'),
             );
             $this->id = $DB->insert_record('portfolio_tempdata', $r);
             $this->save(); // call again so that id gets added to the save data.
         } else {
-            $DB->set_field('portfolio_tempdata', 'data', base64_encode(serialize($this)), array('id' => $this->id));
+            $r = $DB->get_record('portfolio_tempdata', array('id' => $this->id));
+            $r->data = base64_encode(serialize($this));
+            $r->instance = (empty($this->instance)) ? null : $this->instance->get('id');
+            $DB->update_record('portfolio_tempdata', $r);
         }
     }
 
index 10679ea96a37f724448141f548f33ecde111c69f..e9cc4d0a79c8d600a28323520b1b775c0c0758f3 100644 (file)
@@ -696,6 +696,7 @@ abstract class portfolio_plugin_base {
         global $DB;
         $DB->delete_records('portfolio_instance_config', array('instance' => $this->get('id')));
         $DB->delete_records('portfolio_instance_user', array('instance' => $this->get('id')));
+        $DB->delete_records('portfolio_tempdata', array('instance' => $this->get('id')));
         $DB->delete_records('portfolio_instance', array('id' => $this->get('id')));
         $this->dirty = false;
         return true;
index 9a31ace491128f73cd77e22b3923326d6b85736e..c82030da07aa36421a36ae16a5963f4ce3209767 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 = 2009110605;  // YYYYMMDD   = date of the last version bump
+    $version = 2009111600;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20091116)';  // Human-friendly version name