coolify/app/Http/Livewire/Project/Shared/Logs.php

74 lines
3.1 KiB
PHP
Raw Normal View History

2023-10-02 13:38:16 +02:00
<?php
namespace App\Http\Livewire\Project\Shared;
use App\Models\Application;
use App\Models\Server;
use App\Models\Service;
2023-10-24 14:31:28 +02:00
use App\Models\StandaloneMariadb;
2023-10-19 13:32:03 +02:00
use App\Models\StandaloneMongodb;
2023-10-24 14:31:28 +02:00
use App\Models\StandaloneMysql;
2023-10-02 13:38:16 +02:00
use App\Models\StandalonePostgresql;
2023-10-12 17:18:33 +02:00
use App\Models\StandaloneRedis;
2023-10-02 13:38:16 +02:00
use Livewire\Component;
class Logs extends Component
{
public ?string $type = null;
2023-10-24 14:31:28 +02:00
public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb $resource;
2023-10-02 13:38:16 +02:00
public Server $server;
public ?string $container = null;
public $parameters;
public $query;
public $status;
public function mount()
{
$this->parameters = get_route_parameters();
$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->status = $this->resource->status;
$this->server = $this->resource->destination->server;
$containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id, 0);
2023-10-02 13:38:16 +02:00
if ($containers->count() > 0) {
$this->container = data_get($containers[0], 'Names');
}
} else if (data_get($this->parameters, 'database_uuid')) {
$this->type = 'database';
2023-10-12 17:18:33 +02:00
$resource = StandalonePostgresql::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
$resource = StandaloneRedis::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
2023-10-19 13:32:03 +02:00
$resource = StandaloneMongodb::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
2023-10-24 14:31:28 +02:00
$resource = StandaloneMysql::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
$resource = StandaloneMariadb::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
abort(404);
}
}
2023-10-19 13:32:03 +02:00
}
2023-10-12 17:18:33 +02:00
}
}
$this->resource = $resource;
2023-10-02 13:38:16 +02:00
$this->status = $this->resource->status;
$this->server = $this->resource->destination->server;
$this->container = $this->resource->uuid;
} else if (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->status = $this->resource->status;
$this->server = $this->resource->server;
$this->container = data_get($this->parameters, 'service_name') . '-' . $this->resource->uuid;
}
}
public function render()
{
return view('livewire.project.shared.logs');
}
}