Exemplo n.º 1
0
 /**
 * xmlrpc (mnet) function to get the file.
 * reads in the file and returns it base_64 encoded
 * so that it can be enrypted by mnet.
 *
 * @param string $token the token recieved previously during send_content_intent
 */
 public static function fetch_file($token) {
     global $DB;
     $remoteclient = get_mnet_remote_client();
     try {
         if (!$transferid = $DB->get_field('portfolio_mahara_queue', 'transferid', array('token' => $token))) {
             throw new mnet_server_exception(8009, 'mnet_notoken', 'portfolio_mahara');
         }
         $exporter = portfolio_exporter::rewaken_object($transferid);
     } catch (portfolio_exception $e) {
         throw new mnet_server_exception(8010, 'mnet_noid', 'portfolio_mahara');
     }
     if ($exporter->get('instance')->get_config('mnethostid') != $remoteclient->id) {
         throw new mnet_server_exception(8011, 'mnet_wronghost', 'portfolio_mahara');
     }
     global $CFG;
     try {
         $i = $exporter->get('instance');
         $f = $i->get('file');
         if (empty($f) || !($f instanceof stored_file)) {
             throw new mnet_server_exception(8012, 'mnet_nofile', 'portfolio_mahara');
         }
         try {
             $c = $f->get_content();
         } catch (file_exception $e) {
             throw new mnet_server_exception(8013, 'mnet_nofilecontents', 'portfolio_mahara', $e->getMessage());
         }
         $contents = base64_encode($c);
     } catch (Exception $e) {
         throw new mnet_server_exception(8013, 'mnet_nofile', 'portfolio_mahara');
     }
     $exporter->log_transfer();
     $exporter->process_stage_cleanup(true);
     return $contents;
 }
/**
* main portfolio cronjob
* currently just cleans up expired transfer records.
*
* @todo add hooks in the plugins - either per instance or per plugin
*/
function portfolio_cron()
{
    global $DB, $CFG;
    require_once $CFG->libdir . '/portfolio/exporter.php';
    if ($expired = $DB->get_records_select('portfolio_tempdata', 'expirytime < ?', array(time()), '', 'id')) {
        foreach ($expired as $d) {
            try {
                $e = portfolio_exporter::rewaken_object($d->id);
                $e->process_stage_cleanup(true);
            } catch (Exception $e) {
                mtrace('Exception thrown in portfolio cron while cleaning up ' . $d->id . ': ' . $e->getMessage());
            }
        }
    }
}
Exemplo n.º 3
0
 * @copyright 2009 Penny Leach
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../config.php';
if (empty($CFG->enableportfolios)) {
    print_error('disabled', 'portfolio');
}
require_once $CFG->libdir . '/portfoliolib.php';
require_once $CFG->libdir . '/portfolio/plugin.php';
require_once $CFG->libdir . '/portfolio/exporter.php';
require_once $CFG->dirroot . '/mnet/lib.php';
require_login();
$id = required_param('id', PARAM_INT);
// id of current export
$landed = optional_param('landed', false, PARAM_BOOL);
// this is the parameter we get back after we've jumped to mahara
if (!$landed) {
    $exporter = portfolio_exporter::rewaken_object($id);
    $exporter->verify_rewaken();
    $mnetauth = get_auth_plugin('mnet');
    if (!($url = $mnetauth->start_jump_session($exporter->get('instance')->get_config('mnethostid'), '/portfolio/mahara/preconfig.php?landed=1&id=' . $id, true))) {
        throw new porfolio_exception('failedtojump', 'portfolio_mahara');
    }
    redirect($url);
} else {
    // now we have the sso session set up, start sending intent stuff and then redirect back to portfolio/add.php when we're done
    $exporter = portfolio_exporter::rewaken_object($id);
    $exporter->verify_rewaken();
    $exporter->get('instance')->send_intent();
    redirect($CFG->wwwroot . '/portfolio/add.php?postcontrol=1&sesskey=' . sesskey() . '&id=' . $id);
}
Exemplo n.º 4
0
$PAGE->set_title(get_string('logs', 'portfolio'));
$PAGE->set_heading($fullname);
$PAGE->set_context(context_user::instance($user->id));
$PAGE->set_pagelayout('report');
echo $OUTPUT->header();
$showroles = 1;
$somethingprinted = false;
echo $OUTPUT->box_start();
$queued = $DB->get_records('portfolio_tempdata', array('userid' => $USER->id), 'expirytime DESC', 'id, expirytime');
if (count($queued) > 0) {
    $table = new html_table();
    $table->head = array(get_string('displayarea', 'portfolio'), get_string('plugin', 'portfolio'), get_string('displayinfo', 'portfolio'), get_string('displayexpiry', 'portfolio'), '');
    $table->data = array();
    $now = time();
    foreach ($queued as $q) {
        $e = portfolio_exporter::rewaken_object($q->id);
        $e->verify_rewaken(true);
        $queued = $e->get('queued');
        $baseurl = new moodle_url('/portfolio/add.php', array('id' => $q->id, 'logreturn' => 1, 'sesskey' => sesskey()));
        $iconstr = $OUTPUT->action_icon(new moodle_url($baseurl, array('cancel' => 1)), new pix_icon('t/stop', get_string('cancel')));
        if (!$e->get('queued') && $e->get('expirytime') > $now) {
            $iconstr .= $OUTPUT->action_icon($baseurl, new pix_icon('t/go', get_string('continue')));
        }
        $table->data[] = array($e->get('caller')->display_name(), $e->get('instance') ? $e->get('instance')->get('name') : get_string('noinstanceyet', 'portfolio'), $e->get('caller')->heading_summary(), userdate($q->expirytime), $iconstr);
        unset($e);
        // This could potentially be quite big, so free it.
    }
    echo $OUTPUT->heading(get_string('queuesummary', 'portfolio'));
    echo html_writer::table($table);
    $somethingprinted = true;
}
Exemplo n.º 5
0
<?php

require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php';
if (empty($CFG->enableportfolios)) {
    print_error('disabled', 'portfolio');
}
require_once $CFG->libdir . '/portfoliolib.php';
require_once $CFG->dirroot . '/mnet/lib.php';
require_login();
if (!($landed = optional_param('landed', false, PARAM_BOOL))) {
    $id = required_param('id', PARAM_INT);
    $exporter = portfolio_exporter::rewaken_object($id);
    $exporter->verify_rewaken();
    $mnetauth = get_auth_plugin('mnet');
    if (!($url = $mnetauth->start_jump_session($exporter->get('instance')->get_config('mnethostid'), '/portfolio/type/mahara/preconfig.php?landed=1', true))) {
        throw new porfolio_exception('failedtojump', 'portfolio_mahara');
    }
    redirect($url);
} else {
    // now we have the sso session set up, start sending intent stuff and then redirect back to portfolio/add.php when we're done
    $exporter = portfolio_exporter::rewaken_object($SESSION->portfolioexport);
    $exporter->verify_rewaken();
    $exporter->get('instance')->send_intent();
    redirect($CFG->wwwroot . '/portfolio/add.php?postcontrol=1&id=' . $exporter->get('id'));
}
Exemplo n.º 6
0
/**
 * Main portfolio cronjob.
 * Currently just cleans up expired transfer records.
 */
function portfolio_cron()
{
    global $DB, $CFG;
    require_once $CFG->libdir . '/portfolio/exporter.php';
    if ($expired = $DB->get_records_select('portfolio_tempdata', 'expirytime < ?', array(time()), '', 'id')) {
        foreach ($expired as $d) {
            try {
                $e = portfolio_exporter::rewaken_object($d->id);
                $e->process_stage_cleanup(true);
            } catch (Exception $e) {
                mtrace('Exception thrown in portfolio cron while cleaning up ' . $d->id . ': ' . $e->getMessage());
            }
        }
    }
    $process = $DB->get_records('portfolio_tempdata', array('queued' => 1), 'id ASC', 'id');
    foreach ($process as $d) {
        try {
            $exporter = portfolio_exporter::rewaken_object($d->id);
            $exporter->process_stage_package();
            $exporter->process_stage_send();
            $exporter->save();
            $exporter->process_stage_cleanup();
        } catch (Exception $e) {
            // This will get probably retried in the next cron until it is discarded by the code above.
            mtrace('Exception thrown in portfolio cron while processing ' . $d->id . ': ' . $e->getMessage());
        }
    }
}