|
|
@@ -0,0 +1,137 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace DebenOldert\AutoDeploy;
|
|
|
+
|
|
|
+include_once 'IAction.interface.php';
|
|
|
+
|
|
|
+use ZipArchive;
|
|
|
+
|
|
|
+class Action implements IAction
|
|
|
+{
|
|
|
+ protected $settings;
|
|
|
+ protected $key;
|
|
|
+
|
|
|
+ protected $json;
|
|
|
+
|
|
|
+ protected $downloadUrl;
|
|
|
+
|
|
|
+ protected $zipName;
|
|
|
+ protected $unzipName;
|
|
|
+
|
|
|
+ protected $pluginName;
|
|
|
+
|
|
|
+ protected $success = false;
|
|
|
+
|
|
|
+ public function __construct(\stdClass $json, array $settings, string $key)
|
|
|
+ {
|
|
|
+ $this->json = $json;
|
|
|
+ $this->settings = $settings;
|
|
|
+ $this->key = $key;
|
|
|
+
|
|
|
+ var_dump($this->json);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function start(): bool
|
|
|
+ {
|
|
|
+ global $PHPWORK;
|
|
|
+ if($this->shouldDownload())
|
|
|
+ {
|
|
|
+ $this->downloadUrl = $this->formatUrl();
|
|
|
+ $this->zipName = $this->formatDownloadName();
|
|
|
+ $this->unzipName = $this->formatUnZipName();
|
|
|
+
|
|
|
+ if($this->download() && $this->unzip() > 0)
|
|
|
+ {
|
|
|
+ $this->pluginName = $this->formatRealName();
|
|
|
+ $this->success = $this->move();
|
|
|
+ return $this->isSuccess();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $PHPWORK->sendHttpCode(500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $PHPWORK->sendHttpCode(412);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function isSuccess(): bool
|
|
|
+ {
|
|
|
+ return $this->success;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function move(): bool
|
|
|
+ {
|
|
|
+ $plugindir = \DebenOldert\PHPWork\Base::PLUGIN_DIR;
|
|
|
+ $dest = "{$plugindir}/{$this->pluginName}";
|
|
|
+
|
|
|
+ if(is_dir($dest))
|
|
|
+ {
|
|
|
+ return rename($this->unzipName, $dest);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function unzip(): int
|
|
|
+ {
|
|
|
+ $zip = new ZipArchive();
|
|
|
+ if($zip->open($this->zipName) !== 'true'){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $zip->extractTo($this->unzipName);
|
|
|
+ $zip->close();
|
|
|
+
|
|
|
+ return $zip->numFiles;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function formatDownloadName(): string
|
|
|
+ {
|
|
|
+ return Null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function formatUnZipName(): string
|
|
|
+ {
|
|
|
+ return Null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function formatUrl() : string
|
|
|
+ {
|
|
|
+ return Null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function shouldDownload(): bool
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function download(): bool
|
|
|
+ {
|
|
|
+ $file = fopen($this->zipName, 'wb');
|
|
|
+
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $this->downloadUrl);
|
|
|
+ curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
|
|
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_FILE, $file);
|
|
|
+
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return file_exists($this->zipName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function formatRealName(): string
|
|
|
+ {
|
|
|
+ return Null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function createFolder($path) : bool
|
|
|
+ {
|
|
|
+ return mkdir($path, 0777, true);
|
|
|
+ }
|
|
|
+}
|