Example #1
0
 /**
  * Constructor.
  *
  * @param portfolio_exporter $exporter instance of portfolio_exporter (will handle null case)
  * @param string $errorcode language string key
  * @param string $module language string module (optional, defaults to moodle)
  * @param string $continue url to continue to (optional, defaults to wwwroot)
  * @param object $a language string data (optional, defaults to  null)
  */
 public function __construct($exporter, $errorcode, $module = null, $continue = null, $a = null)
 {
     global $CFG;
     // This static variable is necessary because sometimes the code below
     // which tries to obtain a continue link can cause one of these
     // exceptions to be thrown. This would create an infinite loop (until
     // PHP hits its stack limit). Using this static lets us make the
     // nested constructor finish immediately without attempting to call
     // methods that might fail.
     static $inconstructor = false;
     if (!$inconstructor && !empty($exporter) && $exporter instanceof portfolio_exporter) {
         $inconstructor = true;
         try {
             if (empty($continue)) {
                 $caller = $exporter->get('caller');
                 if (!empty($caller) && $caller instanceof portfolio_caller_base) {
                     $continue = $exporter->get('caller')->get_return_url();
                 }
             }
             // this was previously only called if we were in cron,
             // but I think if there's always an exception, we should clean up
             // rather than force the user to resolve the export later.
             $exporter->process_stage_cleanup();
         } catch (Exception $e) {
             // Ooops, we had an exception trying to get caller
             // information. Ignore it.
         }
         $inconstructor = false;
     }
     parent::__construct($errorcode, $module, $continue, $a);
 }
Example #2
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());
            }
        }
    }
}
Example #4
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);
}
Example #5
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;
}
Example #6
0
    // Ensure that we found a file we can use, if not throw an exception.
    portfolio_include_callback_file($callbackcomponent, $callbackclass);
    $caller = new $callbackclass($callbackargs);
    $caller->set('user', $USER);
    if ($formats = explode(',', $callerformats)) {
        $caller->set_formats_from_button($formats);
    }
    $caller->load_data();
    // this must check capabilities and either throw an exception or return false.
    if (!$caller->check_permissions()) {
        throw new portfolio_caller_exception('nopermissions', 'portfolio', $caller->get_return_url());
    }
    portfolio_export_pagesetup($PAGE, $caller);
    // this calls require_login($course) if it can..
    // finally! set up the exporter object with the portfolio instance, and caller information elements
    $exporter = new portfolio_exporter($instance, $caller, $callbackcomponent);
    // set the export-specific variables, and save.
    $exporter->set('user', $USER);
    $exporter->save();
}
if (!$exporter->get('instance')) {
    // we've just arrived but have no instance
    // in this case the exporter object and the caller object have been set up above
    // so just make a little form to select the portfolio plugin instance,
    // which is the last thing to do before starting the export.
    //
    // first check to make sure there is actually a point
    $options = portfolio_instance_select(portfolio_instances(), $exporter->get('caller')->supported_formats(), get_class($exporter->get('caller')), $exporter->get('caller')->get_mimetype(), 'instance', true, true);
    if (empty($options)) {
        throw new portfolio_export_exception($exporter, 'noavailableplugins', 'portfolio');
    } else {
Example #7
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'));
}
Example #8
0
    if (!$caller->check_permissions()) {
        throw new portfolio_caller_exception('nopermissions', 'portfolio', $caller->get_return_url());
    }
    // for build navigation
    if (!($course = $caller->get('course'))) {
        $course = $courseid;
    }
    // set up the course so that build_navigation works nice
    $PAGE->set_course($course);
    // and now we know the course for sure, call require_login with it
    require_login($course);
    list($extranav, $cm) = $caller->get_navigation();
    $extranav[] = array('type' => 'title', 'name' => get_string('exporting', 'portfolio'));
    $navigation = build_navigation($extranav, $cm);
    // finally! set up the exporter object with the portfolio instance, caller information, and navigation elements
    $exporter = new portfolio_exporter($instance, $caller, $callbackfile, $navigation);
    // set the export-specific variables, and save.
    $exporter->set('user', $USER);
    $exporter->set('sesskey', sesskey());
    $exporter->save();
    // and finally, put it in the session for waking up again later.
    $SESSION->portfolioexport = $exporter->get('id');
}
if (!$exporter->get('instance')) {
    // we've just arrived but have no instance
    // in this case the exporter object and the caller object have been set up above
    // so just make a little form to select the portfolio plugin instance,
    // which is the last thing to do before starting the export.
    $mform = new portfolio_instance_select('', array('caller' => $exporter->get('caller')));
    if ($mform->is_cancelled()) {
        $exporter->cancel_request();
Example #9
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());
        }
    }
}