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

58 lines
1.4 KiB
PHP
Raw Normal View History

2023-08-07 18:46:40 +02:00
<?php
namespace App\Http\Livewire\Project\Database;
use App\Actions\Database\StartPostgresql;
2023-08-21 18:00:12 +02:00
use App\Jobs\DatabaseContainerStatusJob;
2023-08-07 22:14:21 +02:00
use App\Notifications\Application\StatusChanged;
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-08-21 18:00:12 +02:00
dispatch_sync(new DatabaseContainerStatusJob(
database: $this->database,
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()
{
2023-08-07 22:14:21 +02:00
remote_process(
["docker rm -f {$this->database->uuid}"],
$this->database->destination->server
);
$this->database->status = 'stopped';
$this->database->save();
$this->database->environment->project->team->notify(new StatusChanged($this->database));
}
public function start()
{
2023-08-07 22:14:21 +02:00
if ($this->database->type() === 'standalone-postgresql') {
2023-08-07 18:46:40 +02:00
$activity = resolve(StartPostgresql::class)($this->database->destination->server, $this->database);
$this->emit('newMonitorActivity', $activity->id);
}
}
2023-08-07 22:14:21 +02:00
}