return true;
}
+ /**
+ * perform any required cleanup functions
+ */
+ public function cleanup() {
+ return true;
+ }
+
public static function mnet_publishes() {
return array();
}
*/
abstract class portfolio_plugin_pull_base extends portfolio_plugin_base {
- private $file;
+ protected $file;
public function is_push() {
return false;
*/
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);
+ }
+
}
/**
// 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);
debugging(get_string('thirdpartyexception', 'portfolio', get_class($e)));
portfolio_export_rethrow_exception($this, $e);
}
- $this->save();
- return false;
}
/**
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);
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
}
/**
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;
?>