Skip to content

Commit

Permalink
MDL-35238 Reorganise the worker::execute() flow
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Nov 8, 2012
1 parent 3daedb5 commit af29dad
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions mdeploy.php
Expand Up @@ -572,6 +572,10 @@ public function help() {
*/ */
class worker extends singleton_pattern { class worker extends singleton_pattern {


const EXIT_OK = 0; // Success exit code.
const EXIT_HELP = 1; // Explicit help required.
const EXIT_UNKNOWN_ACTION = 127; // Neither -i nor -u provided.

/** @var input_manager */ /** @var input_manager */
protected $input = null; protected $input = null;


Expand All @@ -583,21 +587,34 @@ class worker extends singleton_pattern {
*/ */
public function execute() { public function execute() {


// Authorize access. None in CLI. Passphrase in HTTP.
$this->authorize();

// Asking for help in the CLI mode.
if ($this->input->get_option('help')) { if ($this->input->get_option('help')) {
$this->output->help(); $this->output->help();
exit(1); $this->done(self::EXIT_HELP);
} }


// Authorize access. None in CLI. Passphrase in HTTP. if ($this->input->get_option('upgrade')) {
$this->authorize(); // Fetch the ZIP file into a temporary location.

// Compare MD5 checksum of the ZIP file.


// Fetch the ZIP file into a temporary location. // If the target location exists, backup it.


// If the target location exists, backup it. // Unzip the ZIP file into the target location.


// Unzip the ZIP file into the target location. // Redirect to the given URL (in HTTP) or exit (in CLI).
$this->done();


// Redirect to the given URL (in HTTP) or exit (in CLI). } else if ($this->input->get_option('install')) {
// Installing a new plugin not implemented yet.
}

// Print help in CLI by default.
$this->output->help();
$this->done(self::EXIT_UNKNOWN_ACTION);
} }


/** /**
Expand All @@ -610,6 +627,23 @@ protected function initialize() {


// End of external API // End of external API


/**
* Finish this script execution.
*
* @param int $exitcode
*/
protected function done($exitcode = self::EXIT_OK) {

if (PHP_SAPI === 'cli') {
exit($exitcode);

} else {
$returnurl = $this->input->get_option('returnurl');
redirect($returnurl);
exit($exitcode);
}
}

/** /**
* Authorize access to the script. * Authorize access to the script.
* *
Expand Down

0 comments on commit af29dad

Please sign in to comment.