Skip to content

Commit

Permalink
Fixed #79. Ignore Email global scope if app is running in console.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogermani87 committed Sep 15, 2024
1 parent 912a931 commit 73b33f1
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/Models/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public function team(): BelongsTo
protected static function booted(): void
{
static::addGlobalScope('teams', function (Builder $query) {
if (auth()->check() && Filament::getTenant()) {
$query->whereBelongsTo(auth()->user()?->teams);
} else {
$query->whereTeamId(null);
if (!app()->runningInConsole()) {
if (auth()->check() && Filament::getTenant()) {
$query->whereBelongsTo(auth()->user()?->teams);
} else {
$query->whereTeamId(null);
}
}
});
}
Expand All @@ -66,34 +68,33 @@ public static function boot()
parent::boot();

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

if (! empty($record->raw_body) && count(explode(DIRECTORY_SEPARATOR, $record->raw_body)) === 3) {
if (! Storage::disk($storageDisk)->directoryExists($record->raw_body) && Storage::disk($storageDisk)->exists($record->raw_body)) {
if (!empty($record->raw_body) && count(explode(DIRECTORY_SEPARATOR, $record->raw_body)) === 3) {
if (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);
}
}
if (!empty($folderPath) && Storage::disk($storageDisk)->directoryExists($folderPath)) {
Storage::disk($storageDisk)->deleteDirectory($folderPath);
}
});
}
Expand Down

0 comments on commit 73b33f1

Please sign in to comment.