2025-12-16 11:52:58 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Components\Actions;
|
|
|
|
|
|
2026-01-27 11:36:07 +01:00
|
|
|
use App\Enums\TablerIcon;
|
2025-12-16 11:52:58 -05:00
|
|
|
use App\Models\Server;
|
|
|
|
|
use Filament\Actions\Action;
|
|
|
|
|
use Filament\Notifications\Notification;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
|
|
class DeleteServerIcon extends Action
|
|
|
|
|
{
|
|
|
|
|
public static function getDefaultName(): ?string
|
|
|
|
|
{
|
|
|
|
|
return 'delete_icon';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->visible(fn ($record) => $record->icon);
|
|
|
|
|
|
|
|
|
|
$this->hiddenLabel();
|
|
|
|
|
|
2026-01-27 20:07:18 -05:00
|
|
|
$this->tooltip(trans('admin/server.import_image'));
|
2025-12-16 11:52:58 -05:00
|
|
|
|
2026-01-27 20:07:18 -05:00
|
|
|
$this->icon(TablerIcon::Trash);
|
2025-12-16 11:52:58 -05:00
|
|
|
|
|
|
|
|
$this->color('danger');
|
|
|
|
|
|
|
|
|
|
$this->action(function ($record) {
|
|
|
|
|
foreach (array_keys(Server::IMAGE_FORMATS) as $ext) {
|
|
|
|
|
$path = Server::ICON_STORAGE_PATH . "/$record->uuid.$ext";
|
|
|
|
|
if (Storage::disk('public')->exists($path)) {
|
|
|
|
|
Storage::disk('public')->delete($path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Notification::make()
|
|
|
|
|
->title(trans('server/setting.server_info.icon.deleted'))
|
|
|
|
|
->success()
|
|
|
|
|
->send();
|
|
|
|
|
|
|
|
|
|
$record->refresh();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|