Skip to content

Commit

Permalink
MDL-14591 - misc improvements to portfolio api
Browse files Browse the repository at this point in the history
  • Loading branch information
mjollnir_ committed Aug 29, 2008
1 parent 444ac4b commit 2eb07e7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
44 changes: 34 additions & 10 deletions lib/portfoliolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,13 @@ public function delete() {
return true;
}

/**
* perform any required cleanup functions
*/
public function cleanup() {
return true;
}

public static function mnet_publishes() {
return array();
}
Expand All @@ -1584,7 +1591,7 @@ public function is_push() {
*/
abstract class portfolio_plugin_pull_base extends portfolio_plugin_base {

private $file;
protected $file;

public function is_push() {
return false;
Expand All @@ -1599,6 +1606,23 @@ public function is_push() {
*/
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);
}

}

/**
Expand Down Expand Up @@ -1899,8 +1923,12 @@ public function process_stage($stage, $alreadystolen=false) {
// 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);
Expand All @@ -1912,8 +1940,6 @@ public function process_stage($stage, $alreadystolen=false) {
debugging(get_string('thirdpartyexception', 'portfolio', get_class($e)));
portfolio_export_rethrow_exception($this, $e);
}
$this->save();
return false;
}

/**
Expand Down Expand Up @@ -2126,7 +2152,7 @@ public function process_stage_cleanup($pullok=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);
Expand Down Expand Up @@ -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
}

/**
Expand Down
9 changes: 2 additions & 7 deletions portfolio/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
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;
?>
1 change: 0 additions & 1 deletion portfolio/type/download/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class portfolio_plugin_download extends portfolio_plugin_pull_base {

protected $file;
protected $exportconfig;

public static function allows_multiple() {
Expand Down

0 comments on commit 2eb07e7

Please sign in to comment.