Merge branch 'fix-#2546-deletion-issues' into #2546
This commit is contained in:
		@@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Actions\Database;
 | 
					namespace App\Actions\Database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Actions\Server\CleanupDocker;
 | 
				
			||||||
use App\Models\StandaloneClickhouse;
 | 
					use App\Models\StandaloneClickhouse;
 | 
				
			||||||
use App\Models\StandaloneDragonfly;
 | 
					use App\Models\StandaloneDragonfly;
 | 
				
			||||||
use App\Models\StandaloneKeydb;
 | 
					use App\Models\StandaloneKeydb;
 | 
				
			||||||
@@ -12,7 +13,6 @@ use App\Models\StandalonePostgresql;
 | 
				
			|||||||
use App\Models\StandaloneRedis;
 | 
					use App\Models\StandaloneRedis;
 | 
				
			||||||
use Illuminate\Support\Facades\Process;
 | 
					use Illuminate\Support\Facades\Process;
 | 
				
			||||||
use Lorisleiva\Actions\Concerns\AsAction;
 | 
					use Lorisleiva\Actions\Concerns\AsAction;
 | 
				
			||||||
use App\Actions\Server\CleanupDocker;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class StopDatabase
 | 
					class StopDatabase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -21,13 +21,12 @@ class StopDatabase
 | 
				
			|||||||
    public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, bool $isDeleteOperation = false, bool $dockerCleanup = true)
 | 
					    public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, bool $isDeleteOperation = false, bool $dockerCleanup = true)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $server = $database->destination->server;
 | 
					        $server = $database->destination->server;
 | 
				
			||||||
        if (!$server->isFunctional()) {
 | 
					        if (! $server->isFunctional()) {
 | 
				
			||||||
            return 'Server is not functional';
 | 
					            return 'Server is not functional';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->stopContainer($database, $database->uuid, 300);
 | 
					        $this->stopContainer($database, $database->uuid, 300);
 | 
				
			||||||
        if (!$isDeleteOperation) {
 | 
					        if (! $isDeleteOperation) {
 | 
				
			||||||
            $this->deleteConnectedNetworks($database->uuid, $server); //Probably not needed as DBs do not have a network normally
 | 
					 | 
				
			||||||
            if ($dockerCleanup) {
 | 
					            if ($dockerCleanup) {
 | 
				
			||||||
                CleanupDocker::run($server, true);
 | 
					                CleanupDocker::run($server, true);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,9 +4,9 @@ namespace App\Jobs;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use App\Actions\Application\StopApplication;
 | 
					use App\Actions\Application\StopApplication;
 | 
				
			||||||
use App\Actions\Database\StopDatabase;
 | 
					use App\Actions\Database\StopDatabase;
 | 
				
			||||||
 | 
					use App\Actions\Server\CleanupDocker;
 | 
				
			||||||
use App\Actions\Service\DeleteService;
 | 
					use App\Actions\Service\DeleteService;
 | 
				
			||||||
use App\Actions\Service\StopService;
 | 
					use App\Actions\Service\StopService;
 | 
				
			||||||
use App\Actions\Server\CleanupDocker;
 | 
					 | 
				
			||||||
use App\Models\Application;
 | 
					use App\Models\Application;
 | 
				
			||||||
use App\Models\Service;
 | 
					use App\Models\Service;
 | 
				
			||||||
use App\Models\StandaloneClickhouse;
 | 
					use App\Models\StandaloneClickhouse;
 | 
				
			||||||
@@ -35,8 +35,7 @@ class DeleteResourceJob implements ShouldBeEncrypted, ShouldQueue
 | 
				
			|||||||
        public bool $deleteVolumes,
 | 
					        public bool $deleteVolumes,
 | 
				
			||||||
        public bool $dockerCleanup,
 | 
					        public bool $dockerCleanup,
 | 
				
			||||||
        public bool $deleteConnectedNetworks
 | 
					        public bool $deleteConnectedNetworks
 | 
				
			||||||
    ) {
 | 
					    ) {}
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function handle()
 | 
					    public function handle()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -84,11 +83,11 @@ class DeleteResourceJob implements ShouldBeEncrypted, ShouldQueue
 | 
				
			|||||||
                CleanupDocker::run($server, true);
 | 
					                CleanupDocker::run($server, true);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($this->deleteConnectedNetworks) {
 | 
					            if ($this->deleteConnectedNetworks && ! $isDatabase) {
 | 
				
			||||||
                $this->resource?->delete_connected_networks($this->resource->uuid);
 | 
					                $this->resource?->delete_connected_networks($this->resource->uuid);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } catch (\Throwable $e) {
 | 
					        } catch (\Throwable $e) {
 | 
				
			||||||
            send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage());
 | 
					            send_internal_notification('ContainerStoppingJob failed with: '.$e->getMessage());
 | 
				
			||||||
            throw $e;
 | 
					            throw $e;
 | 
				
			||||||
        } finally {
 | 
					        } finally {
 | 
				
			||||||
            $this->resource->forceDelete();
 | 
					            $this->resource->forceDelete();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,8 +78,8 @@ class Heading extends Component
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        return view('livewire.project.database.heading', [
 | 
					        return view('livewire.project.database.heading', [
 | 
				
			||||||
            'checkboxes' => [
 | 
					            'checkboxes' => [
 | 
				
			||||||
                ['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images (the next deployment will take longer as the images have to be pulled again)'],
 | 
					                ['id' => 'docker_cleanup', 'label' => 'Cleanup docker build cache and unused images (next deployment could take longer).'],
 | 
				
			||||||
            ]
 | 
					            ],
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -201,7 +201,7 @@
 | 
				
			|||||||
                            <p>This operation is permanent and cannot be undone. Please think again before proceeding!
 | 
					                            <p>This operation is permanent and cannot be undone. Please think again before proceeding!
 | 
				
			||||||
                            </p>
 | 
					                            </p>
 | 
				
			||||||
                        </div>
 | 
					                        </div>
 | 
				
			||||||
                        <div class="px-2 mb-4">The following actions will be performed:</div>
 | 
					                        <div class="mb-4">The following actions will be performed:</div>
 | 
				
			||||||
                        <ul class="mb-4 space-y-2">
 | 
					                        <ul class="mb-4 space-y-2">
 | 
				
			||||||
                            @foreach ($actions as $action)
 | 
					                            @foreach ($actions as $action)
 | 
				
			||||||
                                <li class="flex items-center text-red-500">
 | 
					                                <li class="flex items-center text-red-500">
 | 
				
			||||||
@@ -230,7 +230,6 @@
 | 
				
			|||||||
                            <div class="mb-4">
 | 
					                            <div class="mb-4">
 | 
				
			||||||
                                <h4 class="text-lg font-semibold mb-2">Confirm Actions</h4>
 | 
					                                <h4 class="text-lg font-semibold mb-2">Confirm Actions</h4>
 | 
				
			||||||
                                <p class="text-sm mb-2">{{ $confirmationLabel }}</p>
 | 
					                                <p class="text-sm mb-2">{{ $confirmationLabel }}</p>
 | 
				
			||||||
 | 
					 | 
				
			||||||
                                <div class="relative mb-2">
 | 
					                                <div class="relative mb-2">
 | 
				
			||||||
                                    <input type="text" x-model="confirmationText"
 | 
					                                    <input type="text" x-model="confirmationText"
 | 
				
			||||||
                                        class="w-full p-2 pr-10 rounded text-black input cursor-text" readonly>
 | 
					                                        class="w-full p-2 pr-10 rounded text-black input cursor-text" readonly>
 | 
				
			||||||
@@ -287,7 +286,7 @@
 | 
				
			|||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <!-- Navigation buttons -->
 | 
					                <!-- Navigation buttons -->
 | 
				
			||||||
                <div class="flex flex-wrap justify-between mt-4 gap-2">
 | 
					                <div class="flex flex-wrap gap-2 justify-between mt-4">
 | 
				
			||||||
                    <template x-if="step > initialStep">
 | 
					                    <template x-if="step > initialStep">
 | 
				
			||||||
                        <x-forms.button @click="step--" class="w-24 dark:bg-coolgray-200 dark:hover:bg-coolgray-300">
 | 
					                        <x-forms.button @click="step--" class="w-24 dark:bg-coolgray-200 dark:hover:bg-coolgray-300">
 | 
				
			||||||
                            Back
 | 
					                            Back
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,19 +72,13 @@
 | 
				
			|||||||
                                </x-forms.button>
 | 
					                                </x-forms.button>
 | 
				
			||||||
                            @endif
 | 
					                            @endif
 | 
				
			||||||
                        @endif
 | 
					                        @endif
 | 
				
			||||||
                        <x-modal-confirmation 
 | 
					                        <x-modal-confirmation title="Confirm Application Stopping?" buttonTitle="Stop"
 | 
				
			||||||
                            title="Confirm Application Stopping?"
 | 
					                            submitAction="stop" :checkboxes="$checkboxes" :actions="[
 | 
				
			||||||
                            buttonTitle="Stop"
 | 
					                                'This application will be stopped.',
 | 
				
			||||||
                            submitAction="stop"
 | 
					                                'All non-persistent data of this application will be deleted.',
 | 
				
			||||||
                            :checkboxes="$checkboxes"
 | 
					                            ]" :confirmWithText="false" :confirmWithPassword="false"
 | 
				
			||||||
                            :actions="['This application will be stopped.', 'If the application is currently in use data could be lost.', 'All non-persistent data of this application (containers, networks, unused images) will be deleted (don\'t worry, no data is lost and you can start the application again).']"
 | 
					                            step1ButtonText="Continue" step2ButtonText="Confirm" :dispatchEvent="true"
 | 
				
			||||||
                            :confirmWithText="false"
 | 
					                            dispatchEventType="stopEvent">
 | 
				
			||||||
                            :confirmWithPassword="false"
 | 
					 | 
				
			||||||
                            step1ButtonText="Continue Stopping Application"
 | 
					 | 
				
			||||||
                            step2ButtonText="Stop Application"
 | 
					 | 
				
			||||||
                            :dispatchEvent="true"
 | 
					 | 
				
			||||||
                            dispatchEventType="stopEvent"
 | 
					 | 
				
			||||||
                            >
 | 
					 | 
				
			||||||
                            <x-slot:button-title>
 | 
					                            <x-slot:button-title>
 | 
				
			||||||
                                <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24"
 | 
					                                <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24"
 | 
				
			||||||
                                    stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
 | 
					                                    stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user