From: Penelope Leach Date: Mon, 16 Nov 2009 15:02:52 +0000 (+0000) Subject: portfolio - MDL-19356 - add instance column to portfolio_tempdata X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e1b9ac3ef86dd4041c354810d9053f59bf38320c;p=moodle.git portfolio - MDL-19356 - add instance column to portfolio_tempdata 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. --- diff --git a/lib/db/install.xml b/lib/db/install.xml index fee5cbc524..a936b93831 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -1967,8 +1967,8 @@ - - + + @@ -2009,11 +2009,13 @@ - + + - + + @@ -2355,4 +2357,4 @@
-
\ No newline at end of file + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index fb0e7c0ba4..95e8ea428f 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; } diff --git a/lib/portfolio/exporter.php b/lib/portfolio/exporter.php index c79c247227..801dc0cf6c 100644 --- a/lib/portfolio/exporter.php +++ b/lib/portfolio/exporter.php @@ -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); } } diff --git a/lib/portfolio/plugin.php b/lib/portfolio/plugin.php index 10679ea96a..e9cc4d0a79 100644 --- a/lib/portfolio/plugin.php +++ b/lib/portfolio/plugin.php @@ -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; diff --git a/version.php b/version.php index 9a31ace491..c82030da07 100644 --- a/version.php +++ b/version.php @@ -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