Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit af29dade97d98e2547ae66cf44927bc3d193d419 1 parent 3daedb5
@mudrd8mz mudrd8mz authored
Showing with 41 additions and 7 deletions.
  1. +41 −7 mdeploy.php
View
48 mdeploy.php
@@ -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);
}
/**
@@ -611,6 +628,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.
*
* In CLI mode, the access is automatically authorized. In HTTP mode, the
Please sign in to comment.
Something went wrong with that request. Please try again.