lasthourcloud/app/Livewire/Project/Database/Heading.php

75 lines
1.9 KiB
PHP
Raw Normal View History

2023-08-07 16:46:40 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Database;
2023-08-07 16:46:40 +00:00
use App\Actions\Database\RestartDatabase;
use App\Actions\Database\StartDatabase;
use App\Actions\Database\StopDatabase;
2024-05-07 13:41:50 +00:00
use App\Actions\Docker\GetContainersStatus;
use Livewire\Component;
2023-08-07 16:46:40 +00:00
class Heading extends Component
{
public $database;
2024-06-10 20:43:34 +00:00
2023-08-07 16:46:40 +00:00
public array $parameters;
2023-12-11 08:02:53 +00:00
public function getListeners()
{
$userId = auth()->user()->id;
2024-06-10 20:43:34 +00:00
2023-12-11 08:02:53 +00:00
return [
"echo-private:user.{$userId},DatabaseStatusChanged" => 'activityFinished',
2023-12-11 08:02:53 +00:00
];
}
public function activityFinished()
{
2023-08-07 20:14:21 +00:00
$this->database->update([
'started_at' => now(),
]);
2023-12-07 18:06:32 +00:00
$this->dispatch('refresh');
2023-08-07 20:14:21 +00:00
$this->check_status();
if (is_null($this->database->config_hash) || $this->database->isConfigurationChanged()) {
$this->database->isConfigurationChanged(true);
$this->dispatch('configurationChanged');
} else {
$this->dispatch('configurationChanged');
}
2023-08-07 20:14:21 +00:00
}
public function check_status($showNotification = false)
2023-08-07 20:14:21 +00:00
{
GetContainersStatus::run($this->database->destination->server);
2023-08-07 20:14:21 +00:00
$this->database->refresh();
2024-06-10 20:43:34 +00:00
if ($showNotification) {
$this->dispatch('success', 'Database status updated.');
}
2023-08-07 20:14:21 +00:00
}
2023-08-07 16:46:40 +00:00
public function mount()
{
$this->parameters = get_route_parameters();
2023-08-07 16:46:40 +00:00
}
public function stop()
{
StopDatabase::run($this->database);
2023-09-18 10:38:11 +00:00
$this->database->status = 'exited';
2023-08-07 20:14:21 +00:00
$this->database->save();
$this->check_status();
2023-08-07 20:14:21 +00:00
}
public function restart()
{
$activity = RestartDatabase::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
}
public function start()
{
$activity = StartDatabase::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
2023-08-07 16:46:40 +00:00
}
2023-08-07 20:14:21 +00:00
}