Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,34 @@ class Backups extends BaseBackups
{
return 'Core';
}

}
```

If you want to hide and show the file download and delete action in Table Actions.

```php
<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use App\Filament\Pages\Backups;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FilamentSpatieLaravelBackupPlugin::make()
->downloadable(true)
->deletable(true)
);
}
}
```
Then register the extended page class on `AdminPanelProvider` class.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"calebporzio/sushi": "^2.4",
"filament/filament": "^3.0",
"spatie/laravel-backup": "^8.0",
"wnx/laravel-backup-restore": "^1.3",
"spatie/laravel-package-tools": "^1.15"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div wire:poll.{{ $this->interval() }}>
<div>
{{ $this->table }}
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div wire:poll.{{ $this->interval() }}>
<div>
{{ $this->table }}
</div>
24 changes: 15 additions & 9 deletions resources/views/pages/backups.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@

<x-slot name="footer" >
<div class="flex gap-x-2">
<x-filament::button wire:click="create('only-db')" color="primary" class="w-full">
{{ __('filament-spatie-backup::backup.pages.backups.modal.buttons.only_db') }}
</x-filament::button>
@if($this->shouldDisplayOnlyDBButton())
<x-filament::button wire:click="create('only-db')" color="primary" class="w-full">
{{ __('filament-spatie-backup::backup.pages.backups.modal.buttons.only_db') }}
</x-filament::button>
@endif

<x-filament::button wire:click="create('only-files')" color="info" class="w-full">
{{ __('filament-spatie-backup::backup.pages.backups.modal.buttons.only_files') }}
</x-filament::button>
@if($this->shouldDisplayOnlyFilesButton())
<x-filament::button wire:click="create('only-files')" color="info" class="w-full">
{{ __('filament-spatie-backup::backup.pages.backups.modal.buttons.only_files') }}
</x-filament::button>
@endif

<x-filament::button wire:click="create()" color="success" class="w-full">
{{ __('filament-spatie-backup::backup.pages.backups.modal.buttons.db_and_files') }}
</x-filament::button>
@if($this->shouldDisplayDbAndFilesButton())
<x-filament::button wire:click="create()" color="success" class="w-full">
{{ __('filament-spatie-backup::backup.pages.backups.modal.buttons.db_and_files') }}
</x-filament::button>
@endif
</div>
</x-slot>
</x-filament::modal>
Expand Down
36 changes: 21 additions & 15 deletions src/Components/BackupDestinationListRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
use Livewire\Attributes\Computed;
use Livewire\Component;
use PhpParser\Node\Stmt\Label;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackup;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;
use ShuvroRoy\FilamentSpatieLaravelBackup\Models\BackupDestination;
use Spatie\Backup\BackupDestination\Backup;
use Spatie\Backup\BackupDestination\BackupDestination as SpatieBackupDestination;

class BackupDestinationListRecords extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;
use InteractsWithTable;

/**
* @var array<int|string, array<string, string>|string>
Expand All @@ -40,6 +40,8 @@ public function render(): View

public function table(Table $table): Table
{
$plugin = filament()->getPlugin('filament-spatie-backup');

return $table
->query(BackupDestination::query())
->columns([
Expand All @@ -66,16 +68,28 @@ public function table(Table $table): Table
->options(FilamentSpatieLaravelBackup::getFilterDisks()),
])
->actions([
Tables\Actions\Action::make('restore')
->label('Restore')
->icon('heroicon-o-arrow-up-tray')
// ->visible(fn (): bool => $plugin->getdownloadable())
->action(
fn (BackupDestination $record) =>
Artisan::call('backup:restore', [
'--backup' => $record->path,
])
Copy link

@jhoanborges jhoanborges Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add '--reset' => true, or maybe pass it as params, otherwise you'll get an error that you have duplicate lines in your database. I created a fork to make this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminded me ,I forget to update it I already changed in my prod project.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! any update for this pull-req?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! any update for this pull-req?

ohh ! I am sorry and i can't merge it cause i'm not a official contributor.may be my code was not good or don't follow there rules.by the way i will update my code tonight to ready for merge and keep up to date.

),


Tables\Actions\Action::make('download')
->label(__('filament-spatie-backup::backup.components.backup_destination_list.table.actions.download'))
->icon('heroicon-o-arrow-down-tray')
->visible(auth()->user()->can('download-backup'))
->visible(fn (): bool => $plugin->getdownloadable())
->action(fn (BackupDestination $record) => Storage::disk($record->disk)->download($record->path)),

Tables\Actions\Action::make('delete')
->label(__('filament-spatie-backup::backup.components.backup_destination_list.table.actions.delete'))
->icon('heroicon-o-trash')
->visible(auth()->user()->can('delete-backup'))
->visible(fn (): bool => $plugin->getdeletable())
->requiresConfirmation()
->action(function (BackupDestination $record) {
SpatieBackupDestination::create($record->disk, config('backup.backup.name'))
Expand All @@ -93,15 +107,7 @@ public function table(Table $table): Table
])
->bulkActions([
// ...
]);
}

#[Computed]
public function interval(): string
{
/** @var FilamentSpatieLaravelBackupPlugin $plugin */
$plugin = filament()->getPlugin('filament-spatie-backup');

return $plugin->getPolingInterval();
])
->poll($plugin->getPolingInterval());
}
}
18 changes: 5 additions & 13 deletions src/Components/BackupDestinationStatusListRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Computed;
use Livewire\Component;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;
use ShuvroRoy\FilamentSpatieLaravelBackup\Models\BackupDestinationStatus;

class BackupDestinationStatusListRecords extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;
use InteractsWithTable;

public function render(): View
{
Expand All @@ -26,6 +24,8 @@ public function render(): View

public function table(Table $table): Table
{
$plugin = filament()->getPlugin('filament-spatie-backup');

return $table
->query(BackupDestinationStatus::query())
->columns([
Expand All @@ -52,15 +52,7 @@ public function table(Table $table): Table
])
->bulkActions([
// ...
]);
}

#[Computed]
public function interval(): string
{
/** @var FilamentSpatieLaravelBackupPlugin $plugin */
$plugin = filament()->getPlugin('filament-spatie-backup');

return $plugin->getPolingInterval();
])
->poll($plugin->getPolingInterval());
}
}
70 changes: 70 additions & 0 deletions src/FilamentSpatieLaravelBackupPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ class FilamentSpatieLaravelBackupPlugin implements Plugin

protected bool $hasStatusListRecordsTable = true;

protected bool $hasDisplayOnlyDBButton = true;

protected bool $hasDisplayOnlyFilesButton = true;

protected bool $hasDisplayDbAndFilesButton = true;

protected ?int $timeout = null;

protected bool $downloadable = true;

protected bool $deletable = true;

public function register(Panel $panel): void
{
$panel->pages([$this->getPage()]);
Expand Down Expand Up @@ -101,6 +111,30 @@ public function getTimeout(): ?int
return $this->timeout;
}

public function downloadable(bool $condition = true): static
{
$this->downloadable = $condition;

return $this;
}

public function getdownloadable(): bool
{
return $this->downloadable;
}

public function deletable(bool $condition = true): static
{
$this->deletable = $condition;

return $this;
}

public function getdeletable(): bool
{
return $this->deletable;
}

public function statusListRecordsTable(bool $condition = true): static
{
$this->hasStatusListRecordsTable = $condition;
Expand All @@ -112,4 +146,40 @@ public function hasStatusListRecordsTable(): bool
{
return $this->hasStatusListRecordsTable;
}

public function shouldDisplayOnlyDBButton(bool $condition = true): static
{
$this->hasDisplayOnlyDBButton = $condition;

return $this;
}

public function hasDisplayOnlyDBButton(): bool
{
return $this->hasDisplayOnlyDBButton;
}

public function shouldDisplayOnlyFilesButton(bool $condition = true): static
{
$this->hasDisplayOnlyFilesButton = $condition;

return $this;
}

public function hasDisplayOnlyFilesButton(): bool
{
return $this->hasDisplayOnlyFilesButton;
}

public function shouldDisplayDbAndFilesButton(bool $condition = true): static
{
$this->hasDisplayDbAndFilesButton = $condition;

return $this;
}

public function hasDisplayDbAndFilesButton(): bool
{
return $this->hasDisplayDbAndFilesButton;
}
}
3 changes: 1 addition & 2 deletions src/Jobs/CreateBackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class CreateBackupJob implements ShouldQueue
public function __construct(
protected readonly Option $option = Option::ALL,
protected readonly ?int $timeout = null,
) {
}
) {}

public function handle(): void
{
Expand Down
Loading