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
|
|
|
|
2023-10-24 12:31:28 +00:00
|
|
|
use App\Actions\Database\StartMariadb;
|
2023-10-19 11:32:03 +00:00
|
|
|
use App\Actions\Database\StartMongodb;
|
2023-10-24 12:31:28 +00:00
|
|
|
use App\Actions\Database\StartMysql;
|
2023-08-07 16:46:40 +00:00
|
|
|
use App\Actions\Database\StartPostgresql;
|
2023-10-12 15:18:33 +00:00
|
|
|
use App\Actions\Database\StartRedis;
|
2023-10-14 12:22:07 +00:00
|
|
|
use App\Actions\Database\StopDatabase;
|
2023-12-11 08:02:53 +00:00
|
|
|
use App\Events\DatabaseStatusChanged;
|
2023-09-14 10:45:50 +00:00
|
|
|
use App\Jobs\ContainerStatusJob;
|
2023-08-08 09:51:36 +00:00
|
|
|
use Livewire\Component;
|
2023-08-07 16:46:40 +00:00
|
|
|
|
|
|
|
class Heading extends Component
|
|
|
|
{
|
|
|
|
public $database;
|
|
|
|
public array $parameters;
|
|
|
|
|
2023-12-11 08:02:53 +00:00
|
|
|
public function getListeners()
|
|
|
|
{
|
|
|
|
$userId = auth()->user()->id;
|
|
|
|
return [
|
2023-12-11 09:23:10 +00:00
|
|
|
"echo-private:user.{$userId},DatabaseStatusChanged" => 'activityFinished',
|
2023-12-11 08:02:53 +00:00
|
|
|
];
|
|
|
|
}
|
2023-08-08 09:51:36 +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();
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-12-11 12:43:16 +00:00
|
|
|
public function check_status($showNotification = false)
|
2023-08-07 20:14:21 +00:00
|
|
|
{
|
2023-09-14 10:45:50 +00:00
|
|
|
dispatch_sync(new ContainerStatusJob($this->database->destination->server));
|
2023-08-07 20:14:21 +00:00
|
|
|
$this->database->refresh();
|
2024-02-22 13:53:42 +00:00
|
|
|
if ($showNotification) $this->dispatch('success', 'Database status updated.');
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-07 16:46:40 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-09 13:57:53 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-08-07 16:46:40 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function stop()
|
|
|
|
{
|
2023-10-14 12:22:07 +00:00
|
|
|
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();
|
2023-09-15 13:34:25 +00:00
|
|
|
$this->check_status();
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function start()
|
|
|
|
{
|
2023-08-07 20:14:21 +00:00
|
|
|
if ($this->database->type() === 'standalone-postgresql') {
|
2023-10-20 12:51:01 +00:00
|
|
|
$activity = StartPostgresql::run($this->database);
|
2024-02-05 13:40:54 +00:00
|
|
|
$this->dispatch('activityMonitor', $activity->id);
|
2023-10-24 12:31:28 +00:00
|
|
|
} else if ($this->database->type() === 'standalone-redis') {
|
2023-10-20 12:51:01 +00:00
|
|
|
$activity = StartRedis::run($this->database);
|
2024-02-05 13:40:54 +00:00
|
|
|
$this->dispatch('activityMonitor', $activity->id);
|
2023-10-24 12:31:28 +00:00
|
|
|
} else if ($this->database->type() === 'standalone-mongodb') {
|
2023-10-20 12:51:01 +00:00
|
|
|
$activity = StartMongodb::run($this->database);
|
2024-02-05 13:40:54 +00:00
|
|
|
$this->dispatch('activityMonitor', $activity->id);
|
2023-10-24 12:31:28 +00:00
|
|
|
} else if ($this->database->type() === 'standalone-mysql') {
|
|
|
|
$activity = StartMysql::run($this->database);
|
2024-02-05 13:40:54 +00:00
|
|
|
$this->dispatch('activityMonitor', $activity->id);
|
2023-10-24 12:31:28 +00:00
|
|
|
} else if ($this->database->type() === 'standalone-mariadb') {
|
|
|
|
$activity = StartMariadb::run($this->database);
|
2024-02-05 13:40:54 +00:00
|
|
|
$this->dispatch('activityMonitor', $activity->id);
|
2023-10-19 11:32:03 +00:00
|
|
|
}
|
2023-08-07 16:46:40 +00:00
|
|
|
}
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|