]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14591 - misc improvements to portfolio api
authormjollnir_ <mjollnir_>
Fri, 29 Aug 2008 12:36:56 +0000 (12:36 +0000)
committermjollnir_ <mjollnir_>
Fri, 29 Aug 2008 12:36:56 +0000 (12:36 +0000)
lib/portfoliolib.php
portfolio/file.php
portfolio/type/download/lib.php

index 717ed618333ea1691b5ba4690b0455566d8fa51c..b50eab096cf512c0b7549a08a8f3b297379a73d0 100644 (file)
@@ -1564,6 +1564,13 @@ abstract class portfolio_plugin_base {
         return true;
     }
 
+    /**
+    * perform any required cleanup functions
+    */
+    public function cleanup() {
+        return true;
+    }
+
     public static function mnet_publishes() {
         return array();
     }
@@ -1584,7 +1591,7 @@ abstract class portfolio_plugin_push_base extends portfolio_plugin_base {
 */
 abstract class portfolio_plugin_pull_base extends portfolio_plugin_base {
 
-    private $file;
+    protected $file;
 
     public function is_push() {
         return false;
@@ -1599,6 +1606,23 @@ abstract class portfolio_plugin_pull_base extends portfolio_plugin_base {
     */
     public abstract function verify_file_request_params($params);
 
+    /**
+    * called from portfolio/file.php
+    * this function sends the stored file out to the browser
+    * the default is to just use send_stored_file,
+    * but other implementations might do something different
+    * for example, send back the file base64 encoded and encrypted
+    * mahara does this but in the response to an xmlrpc request
+    * rather than through file.php
+    */
+    public function send_file() {
+        $file = $this->get('file');
+        if (!($file instanceof stored_file)) {
+            throw new portfolio_export_exception($this->get('exporter'), 'filenotfound', 'portfolio');
+        }
+        send_stored_file($file, 0, 0, true, null, true);
+    }
+
 }
 
 /**
@@ -1899,8 +1923,12 @@ final class portfolio_exporter {
                 // if we get through here it means control was returned
                 // as opposed to wanting to stop processing
                 // eg to wait for user input.
+                $this->save();
                 $stage++;
                 return $this->process_stage($stage);
+            } else {
+                $this->save();
+                return false;
             }
         } catch (portfolio_caller_exception $e) {
             portfolio_export_rethrow_exception($this, $e);
@@ -1912,8 +1940,6 @@ final class portfolio_exporter {
             debugging(get_string('thirdpartyexception', 'portfolio', get_class($e)));
             portfolio_export_rethrow_exception($this, $e);
         }
-        $this->save();
-        return false;
     }
 
     /**
@@ -2126,7 +2152,7 @@ final class portfolio_exporter {
             unset($SESSION->portfolioexport);
             return true;
         }
-        // @todo maybe add a hook in the plugin(s)
+        $this->get('instance')->cleanup();
         $DB->delete_records('portfolio_tempdata', array('id' => $this->id));
         $fs = get_file_storage();
         $fs->delete_area_files(SYSCONTEXTID, 'portfolio_exporter', $this->id);
@@ -2389,15 +2415,13 @@ function portfolio_handle_event($eventdata) {
 function portfolio_cron() {
     global $DB;
 
-    if ($expired = $DB->get_records_select('portfolio_tempdata', 'expirytime < ?', array(time()))) {
+    if ($expired = $DB->get_records_select('portfolio_tempdata', 'expirytime < ?', array(time()), '', 'id')) {
         foreach ($expired as $d) {
-            $DB->delete_records('portfolio_tempdata', array('id' => $d->id));
-            $fs = get_file_storage();
-            $fs->delete_area_files(SYSCONTEXTID, 'portfolio_exporter', $d->id);
+            $e = portfolio_exporter::rewaken_object($d);
+            $e->process_stage_cleanup(true);
         }
     }
-
-    // @todo add hooks in the plugins
+    // @todo add hooks in the plugins - either per instance or per plugin
 }
 
 /**
index 3135bc6656341bb8b6dcbc0a249e65f0b89a59b8..e92efc3bda32e660201f7e3f656e7c16228b2b4a 100644 (file)
@@ -16,12 +16,7 @@ if (!$exporter->get('instance')->verify_file_request_params(array_merge($_GET, $
     throw new portfolio_export_exception($exporter, 'filedenied', 'portfolio');
 }
 
-$file = $exporter->get('instance')->get('file');
-if (!($file instanceof stored_file)) {
-    throw new portfolio_export_exception($exporter, 'filenotfound', 'portfolio');
-}
-
-send_stored_file($file, 0, 0, true, null, true);
+$exporter->get('instance')->send_file();
 $exporter->process_stage_cleanup(true);
-
+exit;
 ?>
index 524671f952e07d5e4fffcd8ecde98967fcec999c..f09ff5961cc531ed553bb9448ec50bab70010c4b 100644 (file)
@@ -5,7 +5,6 @@ require_once($CFG->libdir . '/packer/zip_packer.php');
 
 class portfolio_plugin_download extends portfolio_plugin_pull_base {
 
-    protected $file;
     protected $exportconfig;
 
     public static function allows_multiple() {