Skip to content

Commit

Permalink
Merge pull request #66 from cooljet84/main
Browse files Browse the repository at this point in the history
Fix missing storage option in resend and delete
  • Loading branch information
RickDBCN authored Jun 19, 2024
2 parents 8b4dc58 + 9b00e14 commit 6005afd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/Mail/ResendMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ public function content(): Content
public function attachments(): array
{
$attachments = [];
$storageDisk = config('filament-email.attachments_disk', 'local');

if ($this->addAttachments) {
$modelAttachments = $this->email->attachments;
if (! empty($modelAttachments)) {
if (!empty($modelAttachments)) {
foreach ($modelAttachments as $attachment) {
$attachments[] = Attachment::fromPath(storage_path('app'.DIRECTORY_SEPARATOR.$attachment['path']))
$attachments[] = Attachment::fromStorageDisk($storageDisk, $attachment['path'])
->as($attachment['name']);
}
}
Expand Down
33 changes: 18 additions & 15 deletions src/Models/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;

/**
* Email
Expand Down Expand Up @@ -65,32 +66,34 @@ public static function boot()
parent::boot();

self::deleting(function ($record) {
$storageDisk = config('filament-email.attachments_disk', 'local');
$folderPath = null;
if (! empty($record->attachments)) {
if (!empty($record->attachments)) {
foreach ($record->attachments as $attachment) {
$filePath = storage_path('app'.DIRECTORY_SEPARATOR.$attachment['path']);
$filePath = Storage::disk($storageDisk)->path($attachment['path']);
if (empty($folderPath)) {
$parts = explode(DIRECTORY_SEPARATOR, $filePath);
$parts = explode(DIRECTORY_SEPARATOR, $attachment['path']);
array_pop($parts);
$folderPath = implode(DIRECTORY_SEPARATOR, $parts);
}
if (! is_dir($filePath) && file_exists($filePath)) {
unlink($filePath);
if (!Storage::directoryExists($folderPath) && Storage::disk($storageDisk)->exists($attachment['path'])) {
Storage::disk($storageDisk)->delete($attachment['path']);
}
}
}

$savePathRaw = storage_path('app'.DIRECTORY_SEPARATOR.$record->raw_body);
if (! is_dir($savePathRaw) && file_exists($savePathRaw)) {
if (empty($folderPath)) {
$parts = explode(DIRECTORY_SEPARATOR, $savePathRaw);
array_pop($parts);
$folderPath = implode(DIRECTORY_SEPARATOR, $parts);
if (!empty($record->raw_body)) {
if (!Storage::disk($storageDisk)->directoryExists($record->raw_body) && Storage::disk($storageDisk)->exists($record->raw_body)) {
if (empty($folderPath)) {
$parts = explode(DIRECTORY_SEPARATOR, $record->raw_body);
array_pop($parts);
$folderPath = implode(DIRECTORY_SEPARATOR, $parts);
}
Storage::disk($storageDisk)->delete($record->raw_body);
}
if (Storage::disk($storageDisk)->directoryExists($folderPath)) {
Storage::disk($storageDisk)->deleteDirectory($folderPath);
}
unlink($savePathRaw);
}
if (is_dir($folderPath) && file_exists($folderPath)) {
rmdir($folderPath);
}
});
}
Expand Down

0 comments on commit 6005afd

Please sign in to comment.