From 04f35360ac8ef551ce72b7f0b314fc0a3d6698d9 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Tue, 5 Aug 2008 13:24:47 +0000 Subject: [PATCH] MDL-15934 - new table and infastructure for portfolio callers to store export data that is too big to put in the session. --- lib/db/install.xml | 51 ++++++++++++++++++++++++++------------------ lib/db/upgrade.php | 23 ++++++++++++++++++++ lib/portfoliolib.php | 28 +++++++++++++++++++++++- version.php | 2 +- 4 files changed, 81 insertions(+), 23 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index cc7d1ffc1c..5e999c9df6 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -1734,7 +1734,7 @@ - +
@@ -1748,7 +1748,32 @@
- +
+ + + + + + + + + + + + + + +
+ + + + + + + + +
+ @@ -1771,7 +1796,7 @@
- +
@@ -1781,23 +1806,7 @@
- - - - - - - - - - - - - - - -
- +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index ce0461e02c..5de1c13c62 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -573,6 +573,29 @@ function xmldb_main_upgrade($oldversion=0) { /// Main savepoint reached upgrade_main_savepoint($result, 2008080401); } + + if ($result && $oldversion < 2008080500) { + + /// Define table portfolio_tempdata to be created + $table = new xmldb_table('portfolio_tempdata'); + + /// Adding fields to table portfolio_tempdata + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); + + /// Adding keys to table portfolio_tempdata + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Conditionally launch create table for portfolio_tempdata + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2008080500); + } + + return $result; } diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 771af1d565..ec78324759 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -572,6 +572,11 @@ abstract class portfolio_caller_base { */ protected $user; + /** + * id if any of tempdata + */ + private $tempdataid; + /** * if this caller wants any additional config items * they should be defined here. @@ -704,6 +709,25 @@ abstract class portfolio_caller_base { return $this->exportconfig[$key]; } + + protected function set_export_data($data) { + global $DB; + if ($this->tempdataid) { + $DB->set_field('portfolio_tempdata', 'data', serialize($data), array('id' => $this->tempdataid)); + } + $this->tempdataid = $DB->insert_record('portfolio_tempdata', (object)array('data' => serialize($data))); + } + + protected function get_export_data() { + global $DB; + if ($this->tempdataid) { + if ($data = $DB->get_field('portfolio_tempdata', 'data', array('id' => $this->tempdataid))) { + return unserialize($data); + } + } + return false; + } + /** * Similar to the other allowed_config functions * if you need export config, you must provide @@ -1936,11 +1960,13 @@ final class portfolio_exporter { * @return boolean whether or not to process the next stage. this is important as the control function is called recursively. */ public function process_stage_cleanup() { - global $CFG; + global $CFG, $DB; // @todo this is unpleasant. fix it. require_once($CFG->dirroot . '/backup/lib.php'); delete_dir_contents($this->tempdir); // @todo maybe add a hook in the plugin(s) + $DB->delete_records('portfolio_tempdata', array('id' => $this->tempdataid)); + return true; } diff --git a/version.php b/version.php index 0e9cbf4cc0..feb7ed802c 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 = 2008080401; // YYYYMMDD = date of the last version bump + $version = 2008080500; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20080805)'; // Human-friendly version name -- 2.39.5