coolify/app/Http/Livewire/Project/Database/Heading.php

69 lines
2.1 KiB
PHP
Raw Normal View History

2023-08-07 18:46:40 +02:00
<?php
namespace App\Http\Livewire\Project\Database;
2023-10-24 14:31:28 +02:00
use App\Actions\Database\StartMariadb;
2023-10-19 13:32:03 +02:00
use App\Actions\Database\StartMongodb;
2023-10-24 14:31:28 +02:00
use App\Actions\Database\StartMysql;
2023-08-07 18:46:40 +02:00
use App\Actions\Database\StartPostgresql;
2023-10-12 17:18:33 +02:00
use App\Actions\Database\StartRedis;
use App\Actions\Database\StopDatabase;
2023-09-14 12:45:50 +02:00
use App\Jobs\ContainerStatusJob;
use Livewire\Component;
2023-08-07 18:46:40 +02:00
class Heading extends Component
{
public $database;
public array $parameters;
2023-08-07 22:14:21 +02:00
protected $listeners = ['activityFinished'];
public function activityFinished()
{
2023-08-07 22:14:21 +02:00
$this->database->update([
'started_at' => now(),
]);
$this->emit('refresh');
$this->check_status();
}
2023-08-07 22:14:21 +02:00
public function check_status()
{
2023-09-14 12:45:50 +02:00
dispatch_sync(new ContainerStatusJob($this->database->destination->server));
2023-08-07 22:14:21 +02:00
$this->database->refresh();
}
2023-08-07 18:46:40 +02:00
public function mount()
{
$this->parameters = get_route_parameters();
2023-08-07 18:46:40 +02:00
}
public function stop()
{
StopDatabase::run($this->database);
2023-09-18 12:38:11 +02:00
$this->database->status = 'exited';
2023-08-07 22:14:21 +02:00
$this->database->save();
$this->check_status();
2023-08-07 22:14:21 +02:00
}
public function start()
{
2023-08-07 22:14:21 +02:00
if ($this->database->type() === 'standalone-postgresql') {
2023-10-20 14:51:01 +02:00
$activity = StartPostgresql::run($this->database);
2023-08-07 18:46:40 +02:00
$this->emit('newMonitorActivity', $activity->id);
2023-10-24 14:31:28 +02:00
} else if ($this->database->type() === 'standalone-redis') {
2023-10-20 14:51:01 +02:00
$activity = StartRedis::run($this->database);
2023-10-12 17:18:33 +02:00
$this->emit('newMonitorActivity', $activity->id);
2023-10-24 14:31:28 +02:00
} else if ($this->database->type() === 'standalone-mongodb') {
2023-10-20 14:51:01 +02:00
$activity = StartMongodb::run($this->database);
2023-10-19 13:32:03 +02:00
$this->emit('newMonitorActivity', $activity->id);
2023-10-24 14:31:28 +02:00
} else if ($this->database->type() === 'standalone-mysql') {
$activity = StartMysql::run($this->database);
$this->emit('newMonitorActivity', $activity->id);
} else if ($this->database->type() === 'standalone-mariadb') {
$activity = StartMariadb::run($this->database);
$this->emit('newMonitorActivity', $activity->id);
2023-10-19 13:32:03 +02:00
}
2023-08-07 18:46:40 +02:00
}
2023-08-07 22:14:21 +02:00
}