| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?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);
- }
- }
|