Exemple #1
0
 /**
  * Process the given stage calling whatever functions are necessary
  *
  * @param int $stage (see PORTFOLIO_STAGE_* constants)
  * @param bool $alreadystolen used to avoid letting plugins steal control twice.
  * @return bool whether or not to process the next stage. this is important as the function is called recursively.
  */
 public function process_stage($stage, $alreadystolen = false)
 {
     $this->set('stage', $stage);
     if ($alreadystolen) {
         $this->alreadystolen[$stage] = true;
     } else {
         if (!array_key_exists($stage, $this->alreadystolen)) {
             $this->alreadystolen[$stage] = false;
         }
     }
     if (!$this->alreadystolen[$stage] && ($url = $this->instance->steal_control($stage))) {
         $this->save();
         redirect($url);
         // does not return
     } else {
         $this->save();
     }
     $waiting = $this->instance->get_export_config('wait');
     if ($stage > PORTFOLIO_STAGE_QUEUEORWAIT && empty($waiting)) {
         $stage = PORTFOLIO_STAGE_FINISHED;
     }
     $functionmap = array(PORTFOLIO_STAGE_CONFIG => 'config', PORTFOLIO_STAGE_CONFIRM => 'confirm', PORTFOLIO_STAGE_QUEUEORWAIT => 'queueorwait', PORTFOLIO_STAGE_PACKAGE => 'package', PORTFOLIO_STAGE_CLEANUP => 'cleanup', PORTFOLIO_STAGE_SEND => 'send', PORTFOLIO_STAGE_FINISHED => 'finished');
     $function = 'process_stage_' . $functionmap[$stage];
     try {
         if ($this->{$function}()) {
             // 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);
     } catch (portfolio_plugin_exception $e) {
         portfolio_export_rethrow_exception($this, $e);
     } catch (portfolio_export_exception $e) {
         throw $e;
     } catch (Exception $e) {
         debugging(get_string('thirdpartyexception', 'portfolio', get_class($e)));
         debugging($e);
         portfolio_export_rethrow_exception($this, $e);
     }
 }
Exemple #2
0
            $exporter->print_header(get_string('selectplugin', 'portfolio'));
            echo $OUTPUT->box_start();
            $mform->display();
            echo $OUTPUT->box_end();
            echo $OUTPUT->footer();
            exit;
        }
    }
}
// if we haven't been passed &stage= grab it from the exporter.
if (!$stage) {
    $stage = $exporter->get('stage');
}
// for places returning control to pass (rather than PORTFOLIO_STAGE_PACKAGE
// which is unstable if they can't get to the constant (eg external system)
$alreadystolen = false;
if ($postcontrol) {
    // the magic request variable plugins must pass on returning here
    try {
        // allow it to read whatever gets sent back in the request
        // this is useful for plugins that redirect away and back again
        // adding a token to the end of the url, for example box.net
        $exporter->instance()->post_control($stage, array_merge($_GET, $_POST));
    } catch (portfolio_plugin_exception $e) {
        portfolio_export_rethrow_exception($exporter, $e);
    }
    $alreadystolen = true;
    // remember this so we don't get caught in a steal control loop!
}
// actually do the work now..
$exporter->process_stage($stage, $alreadystolen);