Files
coolify/app/Livewire/Project/Database/FlushCache.php
T
Aditya Tripathi 4429945da6 refactor(database): move flush cache from action menu to danger page
Relocate the cache flush action out of the Heading dropdown into a
dedicated FlushCache section on the database /danger page, shown only
for Redis, KeyDB and Dragonfly. Keeps the shared Danger component free
of cache-specific branches. Tests updated to target the new component.
2026-10-04 22:57:48 +02:00

62 lines
1.6 KiB
PHP

<?php
namespace App\Livewire\Project\Database;
use App\Actions\Database\FlushCacheDatabase;
use App\Models\StandaloneDragonfly;
use App\Models\StandaloneKeydb;
use App\Models\StandaloneRedis;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
class FlushCache extends Component
{
use AuthorizesRequests;
public $database;
public function mount(): void
{
$this->authorize('view', $this->database);
}
public function flush(): void
{
try {
$this->authorize('manage', $this->database);
if (! $this->isCacheDatabase()) {
throw new \RuntimeException('This database type does not support cache flushing.');
}
FlushCacheDatabase::run($this->database);
$this->auditFlush();
$this->dispatch('success', 'Cache flushed successfully.');
} catch (\Throwable $e) {
handleError($e, $this);
}
}
public function isCacheDatabase(): bool
{
return $this->database instanceof StandaloneRedis
|| $this->database instanceof StandaloneKeydb
|| $this->database instanceof StandaloneDragonfly;
}
private function auditFlush(): void
{
auditLog('ui.database.flushed', [
'team_id' => $this->database->team()?->id,
'database_uuid' => $this->database->uuid,
'database_name' => $this->database->name,
]);
}
public function render(): View
{
return view('livewire.project.database.flush-cache');
}
}