Skip to content
Merged
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
11 changes: 11 additions & 0 deletions app/Filament/Resources/ResultResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Filament\Resources\ResultResource\Pages;
use App\Helpers\Number;
use App\Helpers\TimeZoneHelper;
use App\Jobs\TruncateResults;
use App\Models\Result;
use App\Settings\DataMigrationSettings;
use App\Settings\GeneralSettings;
Expand Down Expand Up @@ -316,6 +317,16 @@ public static function table(Table $table): Table
->modalHeading('Migrate History')
->modalDescription(new HtmlString('<p>v0.16.0 archived the old <code>"results"</code> table, to migrate your history click the button below.</p><p>For more information read the <a href="#" target="_blank" rel="nofollow" class="underline">docs</a>.</p>'))
->modalSubmitActionLabel('Yes, migrate it'),
Tables\Actions\ActionGroup::make([
Tables\Actions\Action::make('truncate')
->action(fn () => TruncateResults::dispatch(Auth::user()))
->requiresConfirmation()
->modalHeading('Truncate Results')
->modalDescription('Are you sure you want to truncate all results data? This can\'t be undone.')
->color('danger')
->icon('heroicon-o-trash')
->hidden(fn (): bool => ! Auth::user()->is_admin),
])->dropdownPlacement('bottom-end'),
])
->defaultSort('created_at', 'desc')
->paginated([5, 15, 25, 50, 100])
Expand Down
48 changes: 48 additions & 0 deletions app/Jobs/TruncateResults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Jobs;

use App\Models\User;
use Filament\Notifications\Notification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;

class TruncateResults implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 1;

public function __construct(
public User $user,
) {
}

/**
* Execute the job.
*/
public function handle(): void
{
try {
DB::table('results')->truncate();
} catch (\Throwable $th) {
$this->fail($th);

return;
}

Notification::make()
->title('Results table truncated!')
->success()
->sendToDatabase($this->user);
}
}