From d1efcd6a61a6c213299722bf9fa0633fde16d7f8 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 8 Aug 2023 12:32:24 +0300 Subject: [PATCH] s3 constructor --- composer.lock | 8 ++++---- src/Appwrite/Platform/Tasks/Backup.php | 2 +- src/Appwrite/Platform/Tasks/Restore.php | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index bcf66029c2..30ddaa1e91 100644 --- a/composer.lock +++ b/composer.lock @@ -2626,12 +2626,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "25f6b80b3063b85d7c9483be85f7b6ffea4c1edd" + "reference": "cef63e2d76156c2069c98ccd1430ebac5df3a35c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/25f6b80b3063b85d7c9483be85f7b6ffea4c1edd", - "reference": "25f6b80b3063b85d7c9483be85f7b6ffea4c1edd", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/cef63e2d76156c2069c98ccd1430ebac5df3a35c", + "reference": "cef63e2d76156c2069c98ccd1430ebac5df3a35c", "shasum": "" }, "require": { @@ -2673,7 +2673,7 @@ "issues": "https://github.com/utopia-php/storage/issues", "source": "https://github.com/utopia-php/storage/tree/feat-transfer" }, - "time": "2023-08-08T02:58:34+00:00" + "time": "2023-08-08T08:09:59+00:00" }, { "name": "utopia-php/swoole", diff --git a/src/Appwrite/Platform/Tasks/Backup.php b/src/Appwrite/Platform/Tasks/Backup.php index e02fed7b93..5f5265c88d 100644 --- a/src/Appwrite/Platform/Tasks/Backup.php +++ b/src/Appwrite/Platform/Tasks/Backup.php @@ -50,7 +50,7 @@ class Backup extends Action { $this->database = $database; $this->dsn = $this->getDsn($database); - $this->s3 = new DOSpaces('/' . $this->database . '/full', App::getEnv('_DO_SPACES_ACCESS_KEY'), App::getEnv('_DO_SPACES_SECRET_KEY'), App::getEnv('_DO_SPACES_BUCKET_NAME'), App::getEnv('_DO_SPACES_REGION')); + $this->s3 = new DOSpaces('/' . $database . '/full', App::getEnv('_DO_SPACES_ACCESS_KEY'), App::getEnv('_DO_SPACES_SECRET_KEY'), App::getEnv('_DO_SPACES_BUCKET_NAME'), App::getEnv('_DO_SPACES_REGION')); if (is_null($this->dsn)) { Console::error('No DSN match'); diff --git a/src/Appwrite/Platform/Tasks/Restore.php b/src/Appwrite/Platform/Tasks/Restore.php index a0b843966e..35cb03a8aa 100644 --- a/src/Appwrite/Platform/Tasks/Restore.php +++ b/src/Appwrite/Platform/Tasks/Restore.php @@ -19,6 +19,7 @@ class Restore extends Action public const PROCESSORS = 4; protected ?DSN $dsn = null; protected string $database; + protected ?DOSpaces $s3 = null; public function __construct() { @@ -42,9 +43,10 @@ class Restore extends Action { $this->database = $database; $this->dsn = $this->getDsn($database); + $this->s3 = new DOSpaces('/' . $database . '/full', App::getEnv('_DO_SPACES_ACCESS_KEY'), App::getEnv('_DO_SPACES_SECRET_KEY'), App::getEnv('_DO_SPACES_BUCKET_NAME'), App::getEnv('_DO_SPACES_REGION')); - if (!$this->dsn instanceof DSN) { - Console::error('No dsn match'); + if (is_null($this->dsn)) { + Console::error('No DSN match'); Console::exit(); } @@ -100,19 +102,17 @@ class Restore extends Action public function download(string $file, Device $local) { $filename = basename($file); - $s3 = new DOSpaces($this->database . '/full', App::getEnv('_DO_SPACES_ACCESS_KEY'), App::getEnv('_DO_SPACES_SECRET_KEY'), App::getEnv('_DO_SPACES_BUCKET_NAME'), App::getEnv('_DO_SPACES_REGION')); - try { - $path = $s3->getPath($filename); + $path = $this->s3->getPath($filename); - if (!$s3->exists($path)) { + if (!$this->s3->exists($path)) { Console::error('File: ' . $path . ' does not exist on cloud'); Console::exit(); } $this->log('Downloading: ' . $file); - if (!$s3->transfer($path, $file, $local)) { + if (!$this->s3->transfer($path, $file, $local)) { Console::error('Error Downloading ' . $file); Console::exit(); }