diff --git a/app/Livewire/Project/Application/Configuration.php b/app/Livewire/Project/Application/Configuration.php
index bf2811075..792e55e45 100644
--- a/app/Livewire/Project/Application/Configuration.php
+++ b/app/Livewire/Project/Application/Configuration.php
@@ -3,7 +3,6 @@
namespace App\Livewire\Project\Application;
use App\Models\Application;
-use App\Models\Server;
use Livewire\Component;
class Configuration extends Component
@@ -40,15 +39,7 @@ class Configuration extends Component
$this->project = $project;
$this->environment = $environment;
$this->application = $application;
- if ($application->destination && $application->destination->server) {
- $mainServer = $application->destination->server;
- $this->servers = Server::ownedByCurrentTeam()
- ->select('id', 'name')
- ->where('id', '!=', $mainServer->id)
- ->get();
- } else {
- $this->servers = collect();
- }
+
}
public function render()
diff --git a/app/Livewire/Project/Database/Configuration.php b/app/Livewire/Project/Database/Configuration.php
index e14b27cf6..4e08f0fee 100644
--- a/app/Livewire/Project/Database/Configuration.php
+++ b/app/Livewire/Project/Database/Configuration.php
@@ -6,23 +6,34 @@ use Livewire\Component;
class Configuration extends Component
{
+ public $currentRoute;
+
public $database;
+ public $project;
+
+ public $environment;
+
public function mount()
{
- $project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
- if (! $project) {
- return redirect()->route('dashboard');
- }
- $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
- if (! $environment) {
- return redirect()->route('dashboard');
- }
- $database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
- if (! $database) {
- return redirect()->route('dashboard');
- }
+ $this->currentRoute = request()->route()->getName();
+
+ $project = currentTeam()
+ ->projects()
+ ->select('id', 'uuid', 'team_id')
+ ->where('uuid', request()->route('project_uuid'))
+ ->firstOrFail();
+ $environment = $project->environments()
+ ->select('id', 'name', 'project_id')
+ ->where('name', request()->route('environment_name'))
+ ->firstOrFail();
+ $database = $environment->databases()
+ ->where('uuid', request()->route('database_uuid'))
+ ->firstOrFail();
+
$this->database = $database;
+ $this->project = $project;
+ $this->environment = $environment;
if (str($this->database->status)->startsWith('running') && is_null($this->database->config_hash)) {
$this->database->isConfigurationChanged(true);
$this->dispatch('configurationChanged');
diff --git a/app/Livewire/Project/Shared/Destination.php b/app/Livewire/Project/Shared/Destination.php
index c305e817c..61dcab196 100644
--- a/app/Livewire/Project/Shared/Destination.php
+++ b/app/Livewire/Project/Shared/Destination.php
@@ -8,6 +8,7 @@ use App\Events\ApplicationStatusChanged;
use App\Models\InstanceSettings;
use App\Models\Server;
use App\Models\StandaloneDocker;
+use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
@@ -17,7 +18,7 @@ class Destination extends Component
{
public $resource;
- public $networks = [];
+ public Collection $networks;
public function getListeners()
{
@@ -30,6 +31,7 @@ class Destination extends Component
public function mount()
{
+ $this->networks = collect([]);
$this->loadData();
}
@@ -55,38 +57,46 @@ class Destination extends Component
}
}
- public function stop(int $server_id)
+ public function stop($serverId)
{
- $server = Server::find($server_id);
- StopApplicationOneServer::run($this->resource, $server);
- $this->refreshServers();
+ try {
+ $server = Server::ownedByCurrentTeam()->findOrFail($serverId);
+ StopApplicationOneServer::run($this->resource, $server);
+ $this->refreshServers();
+ } catch (\Exception $e) {
+ return handleError($e, $this);
+ }
}
public function redeploy(int $network_id, int $server_id)
{
- if ($this->resource->additional_servers->count() > 0 && str($this->resource->docker_registry_image_name)->isEmpty()) {
- $this->dispatch('error', 'Failed to deploy.', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.
More information here: documentation');
+ try {
+ if ($this->resource->additional_servers->count() > 0 && str($this->resource->docker_registry_image_name)->isEmpty()) {
+ $this->dispatch('error', 'Failed to deploy.', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.
More information here: documentation');
- return;
+ return;
+ }
+ $deployment_uuid = new Cuid2;
+ $server = Server::ownedByCurrentTeam()->findOrFail($server_id);
+ $destination = $server->standaloneDockers->where('id', $network_id)->firstOrFail();
+ queue_application_deployment(
+ deployment_uuid: $deployment_uuid,
+ application: $this->resource,
+ server: $server,
+ destination: $destination,
+ only_this_server: true,
+ no_questions_asked: true,
+ );
+
+ return redirect()->route('project.application.deployment.show', [
+ 'project_uuid' => data_get($this->resource, 'environment.project.uuid'),
+ 'application_uuid' => data_get($this->resource, 'uuid'),
+ 'deployment_uuid' => $deployment_uuid,
+ 'environment_name' => data_get($this->resource, 'environment.name'),
+ ]);
+ } catch (\Exception $e) {
+ return handleError($e, $this);
}
- $deployment_uuid = new Cuid2;
- $server = Server::find($server_id);
- $destination = StandaloneDocker::find($network_id);
- queue_application_deployment(
- deployment_uuid: $deployment_uuid,
- application: $this->resource,
- server: $server,
- destination: $destination,
- only_this_server: true,
- no_questions_asked: true,
- );
-
- return redirect()->route('project.application.deployment.show', [
- 'project_uuid' => data_get($this->resource, 'environment.project.uuid'),
- 'application_uuid' => data_get($this->resource, 'uuid'),
- 'deployment_uuid' => $deployment_uuid,
- 'environment_name' => data_get($this->resource, 'environment.name'),
- ]);
}
public function promote(int $network_id, int $server_id)
@@ -119,23 +129,27 @@ class Destination extends Component
public function removeServer(int $network_id, int $server_id, $password)
{
- if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
- if (! Hash::check($password, Auth::user()->password)) {
- $this->addError('password', 'The provided password is incorrect.');
+ try {
+ if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
+ if (! Hash::check($password, Auth::user()->password)) {
+ $this->addError('password', 'The provided password is incorrect.');
+
+ return;
+ }
+ }
+
+ if ($this->resource->destination->server->id == $server_id && $this->resource->destination->id == $network_id) {
+ $this->dispatch('error', 'You cannot remove this destination server.', 'You are trying to remove the main server.');
return;
}
+ $server = Server::ownedByCurrentTeam()->findOrFail($server_id);
+ StopApplicationOneServer::run($this->resource, $server);
+ $this->resource->additional_networks()->detach($network_id, ['server_id' => $server_id]);
+ $this->loadData();
+ ApplicationStatusChanged::dispatch(data_get($this->resource, 'environment.project.team.id'));
+ } catch (\Exception $e) {
+ return handleError($e, $this);
}
-
- if ($this->resource->destination->server->id == $server_id && $this->resource->destination->id == $network_id) {
- $this->dispatch('error', 'You cannot remove this destination server.', 'You are trying to remove the main server.');
-
- return;
- }
- $server = Server::find($server_id);
- StopApplicationOneServer::run($this->resource, $server);
- $this->resource->additional_networks()->detach($network_id, ['server_id' => $server_id]);
- $this->loadData();
- ApplicationStatusChanged::dispatch(data_get($this->resource, 'environment.project.team.id'));
}
}
diff --git a/resources/views/livewire/project/application/configuration.blade.php b/resources/views/livewire/project/application/configuration.blade.php
index fc2b8c7c0..7827476d8 100644
--- a/resources/views/livewire/project/application/configuration.blade.php
+++ b/resources/views/livewire/project/application/configuration.blade.php
@@ -98,7 +98,7 @@
@elseif (request()->route()->getName() === 'project.application.source' && $application->git_based())