coolify/app/Livewire/Project/Shared/ScheduledTask/Executions.php

75 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Livewire\Project\Shared\ScheduledTask;
use Livewire\Component;
class Executions extends Component
{
public $executions = [];
2024-09-23 17:51:31 +00:00
public $selectedKey;
2024-09-23 17:51:31 +00:00
2024-08-16 12:45:40 +00:00
public $task;
2024-06-10 20:43:34 +00:00
public function getListeners()
{
return [
2024-06-10 20:43:34 +00:00
'selectTask',
];
}
public function selectTask($key): void
{
if ($key == $this->selectedKey) {
$this->selectedKey = null;
2024-06-10 20:43:34 +00:00
return;
}
$this->selectedKey = $key;
}
2024-08-16 12:45:40 +00:00
2024-08-16 14:01:57 +00:00
public function server()
{
2024-09-23 17:51:31 +00:00
if (! $this->task) {
return null;
}
if ($this->task->application) {
if ($this->task->application->destination && $this->task->application->destination->server) {
return $this->task->application->destination->server;
}
} elseif ($this->task->service) {
if ($this->task->service->destination && $this->task->service->destination->server) {
return $this->task->service->destination->server;
}
}
2024-09-23 17:51:31 +00:00
return null;
2024-08-16 14:01:57 +00:00
}
2024-08-16 19:21:37 +00:00
2024-08-16 12:45:40 +00:00
public function getServerTimezone()
{
2024-08-16 14:01:57 +00:00
$server = $this->server();
2024-09-23 17:51:31 +00:00
if (! $server) {
return 'UTC';
}
2024-08-16 19:21:37 +00:00
$serverTimezone = $server->settings->server_timezone;
2024-09-23 17:51:31 +00:00
2024-08-16 12:45:40 +00:00
return $serverTimezone;
}
2024-08-16 14:01:57 +00:00
public function formatDateInServerTimezone($date)
{
$serverTimezone = $this->getServerTimezone();
$dateObj = new \DateTime($date);
try {
$dateObj->setTimezone(new \DateTimeZone($serverTimezone));
} catch (\Exception $e) {
$dateObj->setTimezone(new \DateTimeZone('UTC'));
2024-08-16 14:01:57 +00:00
}
2024-09-23 17:51:31 +00:00
2024-08-16 14:01:57 +00:00
return $dateObj->format('Y-m-d H:i:s T');
}
2024-08-16 19:21:37 +00:00
}