2023-12-08 17:32:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Actions\Service;
|
|
|
|
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
use App\Models\Service;
|
|
|
|
|
|
|
|
class DeleteService
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
public function handle(Service $service)
|
|
|
|
{
|
|
|
|
$server = data_get($service, 'server');
|
2024-01-17 14:48:01 +00:00
|
|
|
if ($server->isFunctional()) {
|
|
|
|
StopService::run($service);
|
|
|
|
}
|
2023-12-08 17:32:08 +00:00
|
|
|
$storagesToDelete = collect([]);
|
|
|
|
|
|
|
|
$service->environment_variables()->delete();
|
|
|
|
$commands = [];
|
|
|
|
foreach ($service->applications()->get() as $application) {
|
|
|
|
$storages = $application->persistentStorages()->get();
|
|
|
|
foreach ($storages as $storage) {
|
|
|
|
$storagesToDelete->push($storage);
|
|
|
|
}
|
2024-01-02 20:03:51 +00:00
|
|
|
$application->forceDelete();
|
2023-12-08 17:32:08 +00:00
|
|
|
}
|
|
|
|
foreach ($service->databases()->get() as $database) {
|
|
|
|
$storages = $database->persistentStorages()->get();
|
|
|
|
foreach ($storages as $storage) {
|
|
|
|
$storagesToDelete->push($storage);
|
|
|
|
}
|
2024-01-02 20:03:51 +00:00
|
|
|
$database->forceDelete();
|
2023-12-08 17:32:08 +00:00
|
|
|
}
|
|
|
|
foreach ($storagesToDelete as $storage) {
|
|
|
|
$commands[] = "docker volume rm -f $storage->name";
|
|
|
|
}
|
|
|
|
$commands[] = "docker rm -f $service->uuid";
|
|
|
|
|
|
|
|
instant_remote_process($commands, $server, false);
|
|
|
|
|
|
|
|
$service->forceDelete();
|
|
|
|
}
|
|
|
|
}
|