From b53e289bcd465807d354110f76718c49ec58f839 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 13 Feb 2025 10:07:58 +0100 Subject: [PATCH] fix(core): improve connection testing with dynamic disk configuration for s3 backups --- app/Models/S3Storage.php | 14 ++++++++++++-- bootstrap/helpers/s3.php | 17 ----------------- 2 files changed, 12 insertions(+), 19 deletions(-) delete mode 100644 bootstrap/helpers/s3.php diff --git a/app/Models/S3Storage.php b/app/Models/S3Storage.php index 5a9eb87a3..e9d674650 100644 --- a/app/Models/S3Storage.php +++ b/app/Models/S3Storage.php @@ -43,8 +43,18 @@ class S3Storage extends BaseModel public function testConnection(bool $shouldSave = false) { try { - set_s3_target($this); - Storage::disk('custom-s3')->files(); + $disk = Storage::build([ + 'driver' => 's3', + 'region' => $this['region'], + 'key' => $this['key'], + 'secret' => $this['secret'], + 'bucket' => $this['bucket'], + 'endpoint' => $this['endpoint'], + 'use_path_style_endpoint' => true, + ]); + // Test the connection by listing files with ListObjectsV2 (S3) + $disk->files(); + $this->unusable_email_sent = false; $this->is_usable = true; } catch (\Throwable $e) { diff --git a/bootstrap/helpers/s3.php b/bootstrap/helpers/s3.php deleted file mode 100644 index 7029377a4..000000000 --- a/bootstrap/helpers/s3.php +++ /dev/null @@ -1,17 +0,0 @@ -set('filesystems.disks.custom-s3', [ - 'driver' => 's3', - 'region' => $s3['region'], - 'key' => $s3['key'], - 'secret' => $s3['secret'], - 'bucket' => $s3['bucket'], - 'endpoint' => $s3['endpoint'], - 'use_path_style_endpoint' => true, - 'aws_url' => $s3->awsUrl(), - ]); -}