Permalink
Browse files

MDL-35238 Reorganise the worker::execute() flow

  • Loading branch information...
mudrd8mz committed Oct 9, 2012
1 parent 3daedb5 commit af29dade97d98e2547ae66cf44927bc3d193d419
Showing with 41 additions and 7 deletions.
  1. +41 −7 mdeploy.php
View
@@ -572,6 +572,10 @@ public function help() {
*/
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 */
protected $input = null;
@@ -583,21 +587,34 @@ class worker extends singleton_pattern {
*/
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')) {
$this->output->help();
- exit(1);
+ $this->done(self::EXIT_HELP);
}
- // Authorize access. None in CLI. Passphrase in HTTP.
- $this->authorize();
+ if ($this->input->get_option('upgrade')) {
+ // 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);
}
/**
@@ -610,6 +627,23 @@ protected function initialize() {
// 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.
*

0 comments on commit af29dad

Please sign in to comment.