rector: arrrrr

This commit is contained in:
Andras Bacsai
2025-01-07 14:52:08 +01:00
parent c702ebff6d
commit 16c0cd10d8
349 changed files with 4204 additions and 3712 deletions

View File

@@ -10,6 +10,7 @@ use App\Models\ServiceDatabase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
use Throwable;
use Visus\Cuid2\Cuid2;
class Danger extends Component
@@ -43,10 +44,10 @@ class Danger extends Component
if ($this->resource === null) {
if (isset($parameters['service_uuid'])) {
$this->resource = Service::where('uuid', $parameters['service_uuid'])->first();
$this->resource = Service::query()->where('uuid', $parameters['service_uuid'])->first();
} elseif (isset($parameters['stack_service_uuid'])) {
$this->resource = ServiceApplication::where('uuid', $parameters['stack_service_uuid'])->first()
?? ServiceDatabase::where('uuid', $parameters['stack_service_uuid'])->first();
$this->resource = ServiceApplication::query()->where('uuid', $parameters['stack_service_uuid'])->first()
?? ServiceDatabase::query()->where('uuid', $parameters['stack_service_uuid'])->first();
}
}
@@ -81,18 +82,16 @@ class Danger extends Component
public function delete($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.');
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
return;
}
return null;
}
if (! $this->resource) {
$this->addError('resource', 'Resource not found.');
return;
return null;
}
try {
@@ -109,7 +108,7 @@ class Danger extends Component
'project_uuid' => $this->projectUuid,
'environment_uuid' => $this->environmentUuid,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
}

View File

@@ -8,6 +8,7 @@ use App\Events\ApplicationStatusChanged;
use App\Models\InstanceSettings;
use App\Models\Server;
use App\Models\StandaloneDocker;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
@@ -63,9 +64,11 @@ class Destination extends Component
$server = Server::ownedByCurrentTeam()->findOrFail($serverId);
StopApplicationOneServer::run($this->resource, $server);
$this->refreshServers();
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function redeploy(int $network_id, int $server_id)
@@ -74,13 +77,13 @@ class Destination extends Component
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.<br>More information here: <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/multiple-servers">documentation</a>');
return;
return null;
}
$deployment_uuid = new Cuid2;
$cuid2 = new Cuid2;
$server = Server::ownedByCurrentTeam()->findOrFail($server_id);
$destination = $server->standaloneDockers->where('id', $network_id)->firstOrFail();
queue_application_deployment(
deployment_uuid: $deployment_uuid,
deployment_uuid: $cuid2,
application: $this->resource,
server: $server,
destination: $destination,
@@ -91,10 +94,10 @@ class Destination extends Component
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,
'deployment_uuid' => $cuid2,
'environment_uuid' => data_get($this->resource, 'environment.uuid'),
]);
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
}
@@ -130,26 +133,26 @@ class Destination extends Component
public function removeServer(int $network_id, int $server_id, $password)
{
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.');
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
return;
}
return null;
}
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;
return null;
}
$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) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
}

View File

@@ -2,8 +2,10 @@
namespace App\Livewire\Project\Shared\EnvironmentVariable;
use App\Models\Application;
use App\Models\EnvironmentVariable;
use Livewire\Component;
use Throwable;
class All extends Component
{
@@ -31,7 +33,7 @@ class All extends Component
{
$this->is_env_sorting_enabled = data_get($this->resource, 'settings.is_env_sorting_enabled', false);
$this->resourceClass = get_class($this->resource);
$resourceWithPreviews = [\App\Models\Application::class];
$resourceWithPreviews = [Application::class];
$simpleDockerfile = filled(data_get($this->resource, 'dockerfile'));
if (str($this->resourceClass)->contains($resourceWithPreviews) && ! $simpleDockerfile) {
$this->showPreview = true;
@@ -101,11 +103,13 @@ class All extends Component
$this->updateOrder();
$this->sortEnvironmentVariables();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
} finally {
$this->refreshEnvs();
}
return null;
}
private function updateOrder()
@@ -167,17 +171,17 @@ class All extends Component
private function createEnvironmentVariable($data)
{
$environment = new EnvironmentVariable;
$environment->key = $data['key'];
$environment->value = $data['value'];
$environment->is_build_time = $data['is_build_time'] ?? false;
$environment->is_multiline = $data['is_multiline'] ?? false;
$environment->is_literal = $data['is_literal'] ?? false;
$environment->is_preview = $data['is_preview'] ?? false;
$environment->resourceable_id = $this->resource->id;
$environment->resourceable_type = $this->resource->getMorphClass();
$environmentVariable = new EnvironmentVariable;
$environmentVariable->key = $data['key'];
$environmentVariable->value = $data['value'];
$environmentVariable->is_build_time = $data['is_build_time'] ?? false;
$environmentVariable->is_multiline = $data['is_multiline'] ?? false;
$environmentVariable->is_literal = $data['is_literal'] ?? false;
$environmentVariable->is_preview = $data['is_preview'] ?? false;
$environmentVariable->resourceable_id = $this->resource->id;
$environmentVariable->resourceable_type = $this->resource->getMorphClass();
return $environment;
return $environmentVariable;
}
private function deleteRemovedVariables($isPreview, $variables)

View File

@@ -4,6 +4,7 @@ namespace App\Livewire\Project\Shared\EnvironmentVariable;
use App\Models\EnvironmentVariable as ModelsEnvironmentVariable;
use App\Models\SharedEnvironmentVariable;
use Exception;
use Livewire\Component;
class Show extends Component
@@ -60,7 +61,7 @@ class Show extends Component
public function mount()
{
$this->syncData();
if ($this->env->getMorphClass() === \App\Models\SharedEnvironmentVariable::class) {
if ($this->env->getMorphClass() === SharedEnvironmentVariable::class) {
$this->isSharedVariable = true;
}
$this->parameters = get_route_parameters();
@@ -116,7 +117,7 @@ class Show extends Component
public function serialize()
{
data_forget($this->env, 'real_value');
if ($this->env->getMorphClass() === \App\Models\SharedEnvironmentVariable::class) {
if ($this->env->getMorphClass() === SharedEnvironmentVariable::class) {
data_forget($this->env, 'is_build_time');
}
}
@@ -156,7 +157,7 @@ class Show extends Component
$this->value = $oldValue;
$this->dispatch('error', 'Required environment variable cannot be empty.');
return;
return null;
}
$this->serialize();
@@ -168,9 +169,11 @@ class Show extends Component
$this->syncData(true);
$this->dispatch('success', 'Environment variable updated.');
$this->dispatch('envsUpdated');
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e);
}
return null;
}
public function delete()
@@ -179,8 +182,10 @@ class Show extends Component
$this->env->delete();
$this->dispatch('environmentVariableDeleted');
$this->dispatch('success', 'Environment variable deleted successfully.');
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e);
}
return null;
}
}

View File

@@ -6,8 +6,11 @@ use App\Models\Application;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Support\Collection;
use InvalidArgumentException;
use Livewire\Attributes\On;
use Livewire\Component;
use RuntimeException;
use Throwable;
class ExecuteContainerCommand extends Component
{
@@ -43,7 +46,7 @@ class ExecuteContainerCommand extends Component
$this->servers = collect();
if (data_get($this->parameters, 'application_uuid')) {
$this->type = 'application';
$this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail();
$this->resource = Application::query()->where('uuid', $this->parameters['application_uuid'])->firstOrFail();
if ($this->resource->destination->server->isFunctional()) {
$this->servers = $this->servers->push($this->resource->destination->server);
}
@@ -66,14 +69,14 @@ class ExecuteContainerCommand extends Component
$this->loadContainers();
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource = Service::query()->where('uuid', $this->parameters['service_uuid'])->firstOrFail();
if ($this->resource->server->isFunctional()) {
$this->servers = $this->servers->push($this->resource->server);
}
$this->loadContainers();
} elseif (data_get($this->parameters, 'server_uuid')) {
$this->type = 'server';
$this->resource = Server::where('uuid', $this->parameters['server_uuid'])->firstOrFail();
$this->resource = Server::query()->where('uuid', $this->parameters['server_uuid'])->firstOrFail();
$this->server = $this->resource;
}
}
@@ -146,7 +149,7 @@ class ExecuteContainerCommand extends Component
{
try {
if ($this->server->isForceDisabled()) {
throw new \RuntimeException('Server is disabled.');
throw new RuntimeException('Server is disabled.');
}
$this->dispatch(
'send-terminal-command',
@@ -154,9 +157,11 @@ class ExecuteContainerCommand extends Component
data_get($this->server, 'name'),
data_get($this->server, 'uuid')
);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
#[On('connectToContainer')]
@@ -165,28 +170,28 @@ class ExecuteContainerCommand extends Component
if ($this->selected_container === 'default') {
$this->dispatch('error', 'Please select a container.');
return;
return null;
}
try {
// Validate container name format
if (! preg_match('/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/', $this->selected_container)) {
throw new \InvalidArgumentException('Invalid container name format');
throw new InvalidArgumentException('Invalid container name format');
}
// Verify container exists in our allowed list
$container = collect($this->containers)->firstWhere('container.Names', $this->selected_container);
if (is_null($container)) {
throw new \RuntimeException('Container not found.');
throw new RuntimeException('Container not found.');
}
// Verify server ownership and status
$server = data_get($container, 'server');
if (! $server || ! $server instanceof Server) {
throw new \RuntimeException('Invalid server configuration.');
throw new RuntimeException('Invalid server configuration.');
}
if ($server->isForceDisabled()) {
throw new \RuntimeException('Server is disabled.');
throw new RuntimeException('Server is disabled.');
}
// Additional ownership verification based on resource type
@@ -194,11 +199,11 @@ class ExecuteContainerCommand extends Component
'application' => $this->resource->destination->server,
'database' => $this->resource->destination->server,
'service' => $this->resource->server,
default => throw new \RuntimeException('Invalid resource type.')
default => throw new RuntimeException('Invalid resource type.')
};
if ($server->id !== $resourceServer->id && ! $this->resource->additional_servers->contains('id', $server->id)) {
throw new \RuntimeException('Server ownership verification failed.');
throw new RuntimeException('Server ownership verification failed.');
}
$this->dispatch(
@@ -207,9 +212,11 @@ class ExecuteContainerCommand extends Component
data_get($container, 'container.Names'),
data_get($container, 'server.uuid')
);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -44,19 +44,15 @@ class GetLogs extends Component
public function mount()
{
if (! is_null($this->resource)) {
if ($this->resource->getMorphClass() === \App\Models\Application::class) {
if ($this->resource->getMorphClass() === Application::class) {
$this->showTimeStamps = $this->resource->settings->is_include_timestamps;
} elseif ($this->servicesubtype) {
$this->showTimeStamps = $this->servicesubtype->is_include_timestamps;
} else {
if ($this->servicesubtype) {
$this->showTimeStamps = $this->servicesubtype->is_include_timestamps;
} else {
$this->showTimeStamps = $this->resource->is_include_timestamps;
}
$this->showTimeStamps = $this->resource->is_include_timestamps;
}
if ($this->resource?->getMorphClass() === \App\Models\Application::class) {
if (str($this->container)->contains('-pr-')) {
$this->pull_request = 'Pull Request: '.str($this->container)->afterLast('-pr-')->beforeLast('_')->value();
}
if ($this->resource?->getMorphClass() === Application::class && str($this->container)->contains('-pr-')) {
$this->pull_request = 'Pull Request: '.str($this->container)->afterLast('-pr-')->beforeLast('_')->value();
}
}
}
@@ -69,11 +65,11 @@ class GetLogs extends Component
public function instantSave()
{
if (! is_null($this->resource)) {
if ($this->resource->getMorphClass() === \App\Models\Application::class) {
if ($this->resource->getMorphClass() === Application::class) {
$this->resource->settings->is_include_timestamps = $this->showTimeStamps;
$this->resource->settings->save();
}
if ($this->resource->getMorphClass() === \App\Models\Service::class) {
if ($this->resource->getMorphClass() === Service::class) {
$serviceName = str($this->container)->beforeLast('-')->value();
$subType = $this->resource->applications()->where('name', $serviceName)->first();
if ($subType) {
@@ -95,7 +91,7 @@ class GetLogs extends Component
if (! $this->server->isFunctional()) {
return;
}
if (! $refresh && ($this->resource?->getMorphClass() === \App\Models\Service::class || str($this->container)->contains('-pr-'))) {
if (! $refresh && ($this->resource?->getMorphClass() === Service::class || str($this->container)->contains('-pr-'))) {
return;
}
if ($this->numberOfLines <= 0 || is_null($this->numberOfLines)) {
@@ -118,22 +114,20 @@ class GetLogs extends Component
}
$sshCommand = SshMultiplexingHelper::generateSshCommand($this->server, $command);
}
} else {
if ($this->server->isSwarm()) {
$command = "docker service logs -n {$this->numberOfLines} {$this->container}";
if ($this->server->isNonRoot()) {
$command = parseCommandsByLineForSudo(collect($command), $this->server);
$command = $command[0];
}
$sshCommand = SshMultiplexingHelper::generateSshCommand($this->server, $command);
} else {
$command = "docker logs -n {$this->numberOfLines} {$this->container}";
if ($this->server->isNonRoot()) {
$command = parseCommandsByLineForSudo(collect($command), $this->server);
$command = $command[0];
}
$sshCommand = SshMultiplexingHelper::generateSshCommand($this->server, $command);
} elseif ($this->server->isSwarm()) {
$command = "docker service logs -n {$this->numberOfLines} {$this->container}";
if ($this->server->isNonRoot()) {
$command = parseCommandsByLineForSudo(collect($command), $this->server);
$command = $command[0];
}
$sshCommand = SshMultiplexingHelper::generateSshCommand($this->server, $command);
} else {
$command = "docker logs -n {$this->numberOfLines} {$this->container}";
if ($this->server->isNonRoot()) {
$command = parseCommandsByLineForSudo(collect($command), $this->server);
$command = $command[0];
}
$sshCommand = SshMultiplexingHelper::generateSshCommand($this->server, $command);
}
if ($refresh) {
$this->outputs = '';

View File

@@ -3,6 +3,7 @@
namespace App\Livewire\Project\Shared;
use Livewire\Component;
use Throwable;
class HealthChecks extends Component
{
@@ -37,9 +38,11 @@ class HealthChecks extends Component
$this->validate();
$this->resource->save();
$this->dispatch('success', 'Health check updated.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -12,6 +12,7 @@ use App\Models\StandaloneMongodb;
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
use Exception;
use Illuminate\Support\Collection;
use Livewire\Component;
@@ -42,7 +43,7 @@ class Logs extends Component
try {
$server = $this->servers->firstWhere('id', $server_id);
if (! $server->isFunctional()) {
return;
return null;
}
if ($server->isSwarm()) {
$containers = collect([
@@ -54,9 +55,11 @@ class Logs extends Component
$containers = getCurrentApplicationContainerStatus($server, $this->resource->id, includePullrequests: true);
}
$server->containers = $containers->sort();
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function mount()
@@ -68,7 +71,7 @@ class Logs extends Component
$this->query = request()->query();
if (data_get($this->parameters, 'application_uuid')) {
$this->type = 'application';
$this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail();
$this->resource = Application::query()->where('uuid', $this->parameters['application_uuid'])->firstOrFail();
$this->status = $this->resource->status;
if ($this->resource->destination->server->isFunctional()) {
$this->servers = $this->servers->push($this->resource->destination->server);
@@ -93,7 +96,7 @@ class Logs extends Component
$this->containers->push($this->container);
} elseif (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource = Service::query()->where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource->applications()->get()->each(function ($application) {
$this->containers->push(data_get($application, 'name').'-'.data_get($this->resource, 'uuid'));
});
@@ -110,9 +113,11 @@ class Logs extends Component
return str_contains($container, $this->query['pull_request_id']);
});
}
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -3,6 +3,7 @@
namespace App\Livewire\Project\Shared;
use Livewire\Component;
use Throwable;
class Metrics extends Component
{
@@ -39,9 +40,11 @@ class Metrics extends Component
$this->dispatch("refreshChartData-{$this->chartId}-memory", [
'seriesData' => $memoryMetrics,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function setInterval()

View File

@@ -3,6 +3,7 @@
namespace App\Livewire\Project\Shared;
use Livewire\Component;
use Throwable;
class ResourceLimits extends Component
{
@@ -55,8 +56,10 @@ class ResourceLimits extends Component
$this->validate();
$this->resource->save();
$this->dispatch('success', 'Resource limits updated.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
}

View File

@@ -2,11 +2,21 @@
namespace App\Livewire\Project\Shared;
use App\Models\Application;
use App\Models\Environment;
use App\Models\Project;
use App\Models\StandaloneClickhouse;
use App\Models\StandaloneDocker;
use App\Models\StandaloneDragonfly;
use App\Models\StandaloneKeydb;
use App\Models\StandaloneMariadb;
use App\Models\StandaloneMongodb;
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
use App\Models\SwarmDocker;
use Livewire\Component;
use Throwable;
use Visus\Cuid2\Cuid2;
class ResourceOperations extends Component
@@ -32,18 +42,17 @@ class ResourceOperations extends Component
public function cloneTo($destination_id)
{
$new_destination = StandaloneDocker::find($destination_id);
$new_destination = StandaloneDocker::query()->find($destination_id);
if (! $new_destination) {
$new_destination = SwarmDocker::find($destination_id);
$new_destination = SwarmDocker::query()->find($destination_id);
}
if (! $new_destination) {
return $this->addError('destination_id', 'Destination not found.');
}
$uuid = (string) new Cuid2;
$server = $new_destination->server;
if ($this->resource->getMorphClass() === \App\Models\Application::class) {
if ($this->resource->getMorphClass() === Application::class) {
$name = 'clone-of-'.str($this->resource->name)->limit(20).'-'.$uuid;
$new_resource = $this->resource->replicate()->fill([
'uuid' => $uuid,
'name' => $name,
@@ -66,12 +75,12 @@ class ResourceOperations extends Component
$newEnvironmentVariable->save();
}
$persistentVolumes = $this->resource->persistentStorages()->get();
foreach ($persistentVolumes as $volume) {
$volumeName = str($volume->name)->replace($this->resource->uuid, $new_resource->uuid)->value();
if ($volumeName === $volume->name) {
$volumeName = $new_resource->uuid.'-'.str($volume->name)->afterLast('-');
foreach ($persistentVolumes as $persistentVolume) {
$volumeName = str($persistentVolume->name)->replace($this->resource->uuid, $new_resource->uuid)->value();
if ($volumeName === $persistentVolume->name) {
$volumeName = $new_resource->uuid.'-'.str($persistentVolume->name)->afterLast('-');
}
$newPersistentVolume = $volume->replicate()->fill([
$newPersistentVolume = $persistentVolume->replicate()->fill([
'name' => $volumeName,
'resource_id' => $new_resource->id,
]);
@@ -84,16 +93,15 @@ class ResourceOperations extends Component
]).'#resource-operations';
return redirect()->to($route);
} elseif (
$this->resource->getMorphClass() === \App\Models\StandalonePostgresql::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneMongodb::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneMysql::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneMariadb::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneRedis::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneKeydb::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneDragonfly::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneClickhouse::class
) {
}
if ($this->resource->getMorphClass() === StandalonePostgresql::class ||
$this->resource->getMorphClass() === StandaloneMongodb::class ||
$this->resource->getMorphClass() === StandaloneMysql::class ||
$this->resource->getMorphClass() === StandaloneMariadb::class ||
$this->resource->getMorphClass() === StandaloneRedis::class ||
$this->resource->getMorphClass() === StandaloneKeydb::class ||
$this->resource->getMorphClass() === StandaloneDragonfly::class ||
$this->resource->getMorphClass() === StandaloneClickhouse::class) {
$uuid = (string) new Cuid2;
$new_resource = $this->resource->replicate()->fill([
'uuid' => $uuid,
@@ -127,7 +135,8 @@ class ResourceOperations extends Component
]).'#resource-operations';
return redirect()->to($route);
} elseif ($this->resource->type() === 'service') {
}
if ($this->resource->type() === 'service') {
$uuid = (string) new Cuid2;
$new_resource = $this->resource->replicate()->fill([
'uuid' => $uuid,
@@ -154,12 +163,14 @@ class ResourceOperations extends Component
return redirect()->to($route);
}
return null;
}
public function moveTo($environment_id)
{
try {
$new_environment = Environment::findOrFail($environment_id);
$new_environment = Environment::query()->findOrFail($environment_id);
$this->resource->update([
'environment_id' => $environment_id,
]);
@@ -171,7 +182,8 @@ class ResourceOperations extends Component
]).'#resource-operations';
return redirect()->to($route);
} elseif (str($this->resource->type())->startsWith('standalone-')) {
}
if (str($this->resource->type())->startsWith('standalone-')) {
$route = route('project.database.configuration', [
'project_uuid' => $new_environment->project->uuid,
'environment_uuid' => $new_environment->uuid,
@@ -179,7 +191,8 @@ class ResourceOperations extends Component
]).'#resource-operations';
return redirect()->to($route);
} elseif ($this->resource->type() === 'service') {
}
if ($this->resource->type() === 'service') {
$route = route('project.service.configuration', [
'project_uuid' => $new_environment->project->uuid,
'environment_uuid' => $new_environment->uuid,
@@ -188,9 +201,11 @@ class ResourceOperations extends Component
return redirect()->to($route);
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -2,6 +2,7 @@
namespace App\Livewire\Project\Shared\ScheduledTask;
use Exception;
use Illuminate\Support\Collection;
use Livewire\Component;
@@ -53,12 +54,10 @@ class Add extends Component
if (! $isValid) {
$this->dispatch('error', 'Invalid Cron / Human expression.');
return;
return null;
}
if (empty($this->container) || $this->container === 'null') {
if ($this->type === 'service') {
$this->container = $this->subServiceName;
}
if (($this->container === null || $this->container === '' || $this->container === '0' || $this->container === 'null') && $this->type === 'service') {
$this->container = $this->subServiceName;
}
$this->dispatch('saveScheduledTask', [
'name' => $this->name,
@@ -67,9 +66,11 @@ class Add extends Component
'container' => $this->container,
]);
$this->clear();
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function clear()

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Project\Shared\ScheduledTask;
use App\Models\ScheduledTask;
use Illuminate\Support\Collection;
use Livewire\Component;
use Throwable;
class All extends Component
{
@@ -43,29 +44,31 @@ class All extends Component
public function submit($data)
{
try {
$task = new ScheduledTask;
$task->name = $data['name'];
$task->command = $data['command'];
$task->frequency = $data['frequency'];
$task->container = $data['container'];
$task->team_id = currentTeam()->id;
$scheduledTask = new ScheduledTask;
$scheduledTask->name = $data['name'];
$scheduledTask->command = $data['command'];
$scheduledTask->frequency = $data['frequency'];
$scheduledTask->container = $data['container'];
$scheduledTask->team_id = currentTeam()->id;
switch ($this->resource->type()) {
case 'application':
$task->application_id = $this->resource->id;
$scheduledTask->application_id = $this->resource->id;
break;
case 'standalone-postgresql':
$task->standalone_postgresql_id = $this->resource->id;
$scheduledTask->standalone_postgresql_id = $this->resource->id;
break;
case 'service':
$task->service_id = $this->resource->id;
$scheduledTask->service_id = $this->resource->id;
break;
}
$task->save();
$scheduledTask->save();
$this->refreshTasks();
$this->dispatch('success', 'Scheduled task added.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
}

View File

@@ -3,6 +3,9 @@
namespace App\Livewire\Project\Shared\ScheduledTask;
use App\Models\ScheduledTask;
use DateTime;
use DateTimeZone;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Locked;
@@ -28,7 +31,7 @@ class Executions extends Component
public $logsPerPage = 100;
public $selectedExecution = null;
public $selectedExecution;
public $isPollingActive = false;
@@ -45,7 +48,7 @@ class Executions extends Component
{
try {
$this->taskId = $taskId;
$this->task = ScheduledTask::findOrFail($taskId);
$this->task = ScheduledTask::query()->findOrFail($taskId);
$this->executions = $this->task->executions()->take(20)->get();
$this->serverTimezone = data_get($this->task, 'application.destination.server.settings.server_timezone');
if (! $this->serverTimezone) {
@@ -54,9 +57,11 @@ class Executions extends Component
if (! $this->serverTimezone) {
$this->serverTimezone = 'UTC';
}
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e);
}
return null;
}
public function refreshExecutions(): void
@@ -124,7 +129,7 @@ class Executions extends Component
{
$execution = $this->executions->firstWhere('id', $executionId);
if (! $execution) {
return;
return null;
}
return response()->streamDownload(function () use ($execution) {
@@ -145,11 +150,11 @@ class Executions extends Component
public function formatDateInServerTimezone($date)
{
$serverTimezone = $this->serverTimezone;
$dateObj = new \DateTime($date);
$dateObj = new DateTime($date);
try {
$dateObj->setTimezone(new \DateTimeZone($serverTimezone));
} catch (\Exception) {
$dateObj->setTimezone(new \DateTimeZone('UTC'));
$dateObj->setTimezone(new DateTimeZone($serverTimezone));
} catch (Exception) {
$dateObj->setTimezone(new DateTimeZone('UTC'));
}
return $dateObj->format('Y-m-d H:i:s T');

View File

@@ -6,6 +6,7 @@ use App\Jobs\ScheduledTaskJob;
use App\Models\Application;
use App\Models\ScheduledTask;
use App\Models\Service;
use Exception;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
use Livewire\Component;
@@ -68,9 +69,11 @@ class Show extends Component
$this->task = $this->resource->scheduled_tasks()->where('uuid', $task_uuid)->firstOrFail();
$this->syncData();
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e);
}
return null;
}
public function syncData(bool $toModel = false)
@@ -98,9 +101,11 @@ class Show extends Component
$this->syncData(true);
$this->dispatch('success', 'Scheduled task updated.');
$this->refreshTasks();
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e);
}
return null;
}
public function submit()
@@ -108,18 +113,22 @@ class Show extends Component
try {
$this->syncData(true);
$this->dispatch('success', 'Scheduled task updated.');
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e);
}
return null;
}
public function refreshTasks()
{
try {
$this->task->refresh();
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e);
}
return null;
}
public function delete()
@@ -129,10 +138,10 @@ class Show extends Component
if ($this->type === 'application') {
return redirect()->route('project.application.configuration', $this->parameters, $this->task->name);
} else {
return redirect()->route('project.service.configuration', $this->parameters, $this->task->name);
}
} catch (\Exception $e) {
return redirect()->route('project.service.configuration', $this->parameters, $this->task->name);
} catch (Exception $e) {
return handleError($e);
}
}
@@ -142,8 +151,10 @@ class Show extends Component
try {
ScheduledTaskJob::dispatch($this->task);
$this->dispatch('success', 'Scheduled task executed.');
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e);
}
return null;
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Project\Shared\Storages;
use App\Models\Application;
use App\Models\LocalFileVolume;
use Livewire\Component;
use Throwable;
class Add extends Component
{
@@ -63,7 +64,7 @@ class Add extends Component
$this->parameters = get_route_parameters();
if (data_get($this->parameters, 'application_uuid')) {
$applicationUuid = $this->parameters['application_uuid'];
$application = Application::where('uuid', $applicationUuid)->first();
$application = Application::query()->where('uuid', $applicationUuid)->first();
if (! $application) {
abort(404);
}
@@ -83,23 +84,23 @@ class Add extends Component
]);
$this->file_storage_path = trim($this->file_storage_path);
$this->file_storage_path = str($this->file_storage_path)->start('/')->value();
if ($this->resource->getMorphClass() === \App\Models\Application::class) {
if ($this->resource->getMorphClass() === Application::class) {
$fs_path = application_configuration_dir().'/'.$this->resource->uuid.$this->file_storage_path;
}
LocalFileVolume::create(
[
'fs_path' => $fs_path,
'mount_path' => $this->file_storage_path,
'content' => $this->file_storage_content,
'is_directory' => false,
'resource_id' => $this->resource->id,
'resource_type' => get_class($this->resource),
],
);
LocalFileVolume::query()->create([
'fs_path' => $fs_path,
'mount_path' => $this->file_storage_path,
'content' => $this->file_storage_content,
'is_directory' => false,
'resource_id' => $this->resource->id,
'resource_type' => get_class($this->resource),
]);
$this->dispatch('refreshStorages');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submitFileStorageDirectory()
@@ -113,19 +114,19 @@ class Add extends Component
$this->file_storage_directory_source = str($this->file_storage_directory_source)->start('/')->value();
$this->file_storage_directory_destination = trim($this->file_storage_directory_destination);
$this->file_storage_directory_destination = str($this->file_storage_directory_destination)->start('/')->value();
LocalFileVolume::create(
[
'fs_path' => $this->file_storage_directory_source,
'mount_path' => $this->file_storage_directory_destination,
'is_directory' => true,
'resource_id' => $this->resource->id,
'resource_type' => get_class($this->resource),
],
);
LocalFileVolume::query()->create([
'fs_path' => $this->file_storage_directory_source,
'mount_path' => $this->file_storage_directory_destination,
'is_directory' => true,
'resource_id' => $this->resource->id,
'resource_type' => get_class($this->resource),
]);
$this->dispatch('refreshStorages');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submitPersistentVolume()
@@ -142,9 +143,11 @@ class Add extends Component
'mount_path' => $this->mount_path,
'host_path' => $this->host_path,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function clear()

View File

@@ -41,12 +41,10 @@ class Show extends Component
public function delete($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.');
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
return;
}
return;
}
$this->storage->delete();

View File

@@ -3,13 +3,14 @@
namespace App\Livewire\Project\Shared;
use App\Models\Tag;
use Exception;
use Livewire\Attributes\Validate;
use Livewire\Component;
// Refactored ✅
class Tags extends Component
{
public $resource = null;
public $resource;
#[Validate('required|string|min:2')]
public string $newTags;
@@ -50,7 +51,7 @@ class Tags extends Component
}
$found = Tag::ownedByCurrentTeam()->where(['name' => $tag])->exists();
if (! $found) {
$found = Tag::create([
$found = Tag::query()->create([
'name' => $tag,
'team_id' => currentTeam()->id,
]);
@@ -58,9 +59,11 @@ class Tags extends Component
$this->resource->tags()->attach($found->id);
}
$this->refresh();
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function addTag(string $id, string $name)
@@ -70,14 +73,16 @@ class Tags extends Component
if ($this->resource->tags()->where('id', $id)->exists()) {
$this->dispatch('error', 'Duplicate tags.', "Tag <span class='dark:text-warning'>$name</span> already added.");
return;
return null;
}
$this->resource->tags()->attach($id);
$this->refresh();
$this->dispatch('success', 'Tag added.');
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function deleteTag(string $id)
@@ -90,9 +95,11 @@ class Tags extends Component
}
$this->refresh();
$this->dispatch('success', 'Tag deleted.');
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function refresh()

View File

@@ -4,6 +4,7 @@ namespace App\Livewire\Project\Shared;
use App\Helpers\SshMultiplexingHelper;
use App\Models\Server;
use InvalidArgumentException;
use Livewire\Attributes\On;
use Livewire\Component;
@@ -31,7 +32,7 @@ class Terminal extends Component
if ($isContainer) {
// Validate container identifier format (alphanumeric, dashes, and underscores only)
if (! preg_match('/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/', $identifier)) {
throw new \InvalidArgumentException('Invalid container identifier format');
throw new InvalidArgumentException('Invalid container identifier format');
}
// Verify container exists and belongs to the user's team

View File

@@ -3,6 +3,7 @@
namespace App\Livewire\Project\Shared;
use App\Models\Application;
use Exception;
use Livewire\Component;
class UploadConfig extends Component
@@ -29,10 +30,10 @@ class UploadConfig extends Component
public function uploadConfig()
{
try {
$application = Application::findOrFail($this->applicationId);
$application = Application::query()->findOrFail($this->applicationId);
$application->setConfig($this->config);
$this->dispatch('success', 'Application settings updated');
} catch (\Exception $e) {
} catch (Exception $e) {
$this->dispatch('error', $e->getMessage());
return;

View File

@@ -2,6 +2,7 @@
namespace App\Livewire\Project\Shared;
use Exception;
use Livewire\Component;
// Refactored ✅
@@ -57,8 +58,10 @@ class Webhooks extends Component
'manual_webhook_secret_gitea' => $this->giteaManualWebhookSecret,
]);
$this->dispatch('success', 'Secret Saved.');
} catch (\Exception $e) {
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
}