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.
<?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>
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;
}
'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);
}
}
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;
// 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