*/
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;
*/
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);
}
/**
// 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.
*