From 777913923f879b7947b44abd177ecbaef06e985a Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Wed, 14 Aug 2024 23:00:39 +0200
Subject: [PATCH 06/42] fix faulty DB migration and remove default, server is
the default
---
.../2024_08_12_155023_add_timezone_to_server_settings_table.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/database/migrations/2024_08_12_155023_add_timezone_to_server_settings_table.php b/database/migrations/2024_08_12_155023_add_timezone_to_server_settings_table.php
index 971195d6d..62511ffb3 100644
--- a/database/migrations/2024_08_12_155023_add_timezone_to_server_settings_table.php
+++ b/database/migrations/2024_08_12_155023_add_timezone_to_server_settings_table.php
@@ -9,7 +9,7 @@ class AddTimezoneToServerSettingsTable extends Migration
public function up()
{
Schema::table('server_settings', function (Blueprint $table) {
- $table->string('server_timezone')->default('UTC');
+ $table->string('server_timezone')->default('');
});
}
From 99f2d4d71113c7f693fbfd90bedecfdb17110ec2 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Wed, 14 Aug 2024 23:18:55 +0200
Subject: [PATCH 07/42] Feat: actually update timezone on the server
---
app/Livewire/Server/Form.php | 130 +++++++++++++++++++++--------------
1 file changed, 79 insertions(+), 51 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index 1da9237f0..318b0a8b4 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -5,8 +5,7 @@ namespace App\Livewire\Server;
use App\Actions\Server\StartSentinel;
use App\Actions\Server\StopSentinel;
use App\Jobs\PullSentinelImageJob;
-use App\Models\Server;
-use DateTimeZone;
+use App\Models\Server;;
use Livewire\Component;
class Form extends Component
@@ -179,7 +178,8 @@ class Form extends Component
public function submit()
{
- if (isCloud() && ! isDev()) {
+ ray('Submit method called');
+ if (isCloud() && !isDev()) {
$this->validate();
$this->validate([
'server.ip' => 'required',
@@ -192,29 +192,50 @@ class Form extends Component
})->pluck('ip')->toArray();
if (in_array($this->server->ip, $uniqueIPs)) {
$this->dispatch('error', 'IP address is already in use by another team.');
-
return;
}
refresh_server_connection($this->server->privateKey);
$this->server->settings->wildcard_domain = $this->wildcard_domain;
$this->server->settings->cleanup_after_percentage = $this->cleanup_after_percentage;
- // Update the timezone if it has changed
- if ($this->server->settings->isDirty('server_timezone')) {
+ ray('Current timezone:', $this->server->settings->getOriginal('server_timezone'));
+ ray('New timezone:', $this->server->settings->server_timezone);
+
+ $currentTimezone = $this->server->settings->getOriginal('server_timezone');
+ $newTimezone = $this->server->settings->server_timezone;
+
+ ray('Comparing timezones:', $currentTimezone, $newTimezone);
+
+ if ($currentTimezone !== $newTimezone || $currentTimezone === '') {
+ ray('Timezone change detected');
try {
- $message = $this->updateServerTimezone($this->server->settings->server_timezone);
- $this->dispatch('success', $message);
+ ray('Calling updateServerTimezone');
+ $timezoneUpdated = $this->updateServerTimezone($newTimezone);
+ ray('updateServerTimezone result:', $timezoneUpdated);
+ if ($timezoneUpdated) {
+ $this->server->settings->server_timezone = $newTimezone;
+ $this->server->settings->save();
+ ray('New timezone saved to database:', $newTimezone);
+ } else {
+ ray('Timezone update failed');
+ return;
+ }
} catch (\Exception $e) {
+ ray('Exception in updateServerTimezone:', $e->getMessage());
$this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());
return;
}
+ } else {
+ ray('No timezone change detected');
}
+ ray('Saving server settings');
$this->server->settings->save();
$this->server->save();
$this->dispatch('success', 'Server updated.');
+ ray('Submit method completed');
}
-
+
public function updatedServerTimezone($value)
{
if (!is_string($value) || !in_array($value, timezone_identifiers_list())) {
@@ -226,52 +247,59 @@ class Form extends Component
private function updateServerTimezone($value)
{
- $commands = [
- "date +%Z",
- "if command -v timedatectl >/dev/null 2>&1; then timedatectl set-timezone " . escapeshellarg($value) . " 2>&1 || echo 'timedatectl failed'; fi",
- "if [ -f /etc/timezone ]; then echo " . escapeshellarg($value) . " > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata 2>&1 || echo '/etc/timezone update failed'; fi",
- "if [ -L /etc/localtime ]; then ln -sf /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 || echo '/etc/localtime update failed'; fi",
- "date +%Z",
- ];
-
- $result = instant_remote_process($commands, $this->server);
-
- if (!isset($result['output']) || empty($result['output'])) {
- throw new \Exception("No output received from server. The timezone may not have been updated.");
- }
-
- $output = is_array($result['output']) ? $result['output'] : explode("\n", trim($result['output']));
- $output = array_filter($output); // Remove empty lines
-
- if (count($output) < 2) {
- throw new \Exception("Unexpected output format: " . implode("\n", $output));
- }
-
- $oldTimezone = $output[0];
- $newTimezone = end($output);
-
- $errors = array_filter($output, function($line) {
- return strpos($line, 'failed') !== false;
- });
-
- if (!empty($errors)) {
- throw new \Exception("Timezone change failed. Errors: " . implode(", ", $errors));
- }
-
- if ($oldTimezone === $newTimezone) {
- throw new \Exception("Timezone change failed. The timezone is still set to {$oldTimezone}.");
- }
-
+ ray('updateServerTimezone called with value:', $value);
try {
+ $commands = [
+ "date +%Z",
+ "if command -v timedatectl >/dev/null 2>&1; then timedatectl set-timezone " . escapeshellarg($value) . " 2>&1 || echo 'timedatectl failed'; fi",
+ "if [ -f /etc/timezone ]; then echo " . escapeshellarg($value) . " > /etc/timezone 2>&1 || echo '/etc/timezone update failed'; fi",
+ "if [ -L /etc/localtime ] || [ -f /etc/localtime ]; then ln -sf /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 || echo '/etc/localtime update failed'; fi",
+ "if command -v dpkg-reconfigure >/dev/null 2>&1; then dpkg-reconfigure -f noninteractive tzdata 2>&1 || echo 'dpkg-reconfigure failed'; fi",
+ "if command -v apk >/dev/null 2>&1; then apk add --no-cache tzdata 2>&1 && cp /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 && echo " . escapeshellarg($value) . " > /etc/timezone 2>&1 || echo 'Alpine timezone update failed'; fi",
+ "if [ -f /etc/sysconfig/clock ]; then sed -i 's/^ZONE=.*/ZONE=\"" . escapeshellarg($value) . "\"/' /etc/sysconfig/clock 2>&1 || echo '/etc/sysconfig/clock update failed'; fi",
+ "date +%Z",
+ "cat /etc/timezone 2>/dev/null || echo 'Unable to read /etc/timezone'",
+ ];
+
+ $result = instant_remote_process($commands, $this->server);
+
+ if (!isset($result['output']) || empty($result['output'])) {
+ throw new \Exception("No output received from server. The timezone may not have been updated.");
+ }
+
+ $output = is_array($result['output']) ? $result['output'] : explode("\n", trim($result['output']));
+ $output = array_filter($output); // Remove empty lines
+
+ if (count($output) < 2) {
+ throw new \Exception("Unexpected output format: " . implode("\n", $output));
+ }
+
+ $oldTimezone = $output[0];
+ $newTimezone = end($output);
+
+ $errors = array_filter($output, function($line) {
+ return strpos($line, 'failed') !== false;
+ });
+
+ if (!empty($errors)) {
+ throw new \Exception("Timezone change failed. Errors: " . implode(", ", $errors));
+ }
+
+ if ($oldTimezone === $newTimezone) {
+ throw new \Exception("Timezone change failed. The timezone is still set to {$oldTimezone}.");
+ }
+
$dateTime = new \DateTime('now', new \DateTimeZone($value));
$phpTimezone = $dateTime->getTimezone()->getName();
+
+ $this->server->settings->server_timezone = $phpTimezone;
+ $this->server->settings->save();
+
+ $this->dispatch('success', "Timezone successfully changed from {$oldTimezone} to {$newTimezone} (PHP: {$phpTimezone}).");
+ return true;
} catch (\Exception $e) {
- throw new \Exception("Invalid PHP timezone: {$value}. Error: " . $e->getMessage());
+ $this->dispatch('error', $e->getMessage());
+ return false;
}
-
- $this->server->settings->server_timezone = $phpTimezone;
- $this->server->settings->save();
-
- return "Timezone successfully changed from {$oldTimezone} to {$newTimezone} (PHP: {$phpTimezone}).";
}
}
\ No newline at end of file
From 44f319460f42b6d727f8f8538a03b6d3f7ec978c Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Wed, 14 Aug 2024 23:29:33 +0200
Subject: [PATCH 08/42] remove unnecessary validation and fix safe to DB
---
app/Livewire/Server/Form.php | 42 ++++++------------------------------
1 file changed, 7 insertions(+), 35 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index 318b0a8b4..c5ffcf974 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -243,6 +243,7 @@ class Form extends Component
return;
}
$this->server->settings->server_timezone = $value;
+ $this->updateServerTimezone($value);
}
private function updateServerTimezone($value)
@@ -260,42 +261,13 @@ class Form extends Component
"date +%Z",
"cat /etc/timezone 2>/dev/null || echo 'Unable to read /etc/timezone'",
];
-
- $result = instant_remote_process($commands, $this->server);
-
- if (!isset($result['output']) || empty($result['output'])) {
- throw new \Exception("No output received from server. The timezone may not have been updated.");
- }
-
- $output = is_array($result['output']) ? $result['output'] : explode("\n", trim($result['output']));
- $output = array_filter($output); // Remove empty lines
-
- if (count($output) < 2) {
- throw new \Exception("Unexpected output format: " . implode("\n", $output));
- }
-
- $oldTimezone = $output[0];
- $newTimezone = end($output);
-
- $errors = array_filter($output, function($line) {
- return strpos($line, 'failed') !== false;
- });
-
- if (!empty($errors)) {
- throw new \Exception("Timezone change failed. Errors: " . implode(", ", $errors));
- }
-
- if ($oldTimezone === $newTimezone) {
- throw new \Exception("Timezone change failed. The timezone is still set to {$oldTimezone}.");
- }
-
- $dateTime = new \DateTime('now', new \DateTimeZone($value));
- $phpTimezone = $dateTime->getTimezone()->getName();
-
- $this->server->settings->server_timezone = $phpTimezone;
+
+ instant_remote_process($commands, $this->server);
+
+ $this->server->settings->server_timezone = $value;
$this->server->settings->save();
-
- $this->dispatch('success', "Timezone successfully changed from {$oldTimezone} to {$newTimezone} (PHP: {$phpTimezone}).");
+
+ $this->dispatch('success', "Timezone successfully changed to {$value}.");
return true;
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
From f0b9bd2cf2d540778b9d7f7daf0b7a9b01822461 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Thu, 15 Aug 2024 00:31:23 +0200
Subject: [PATCH 09/42] set default time zone and remove success message
---
app/Livewire/Server/Form.php | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index c5ffcf974..54cdf7a14 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -78,6 +78,11 @@ class Form extends Component
$this->timezones = collect(timezone_identifiers_list())->sort()->values()->toArray();
$this->wildcard_domain = $this->server->settings->wildcard_domain;
$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;
+
+ if ($this->server->settings->server_timezone === '') {
+ $defaultTimezone = config('app.timezone');
+ $this->updateServerTimezone($defaultTimezone);
+ }
}
public function serverInstalled()
@@ -267,11 +272,10 @@ class Form extends Component
$this->server->settings->server_timezone = $value;
$this->server->settings->save();
- $this->dispatch('success', "Timezone successfully changed to {$value}.");
return true;
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
return false;
}
}
-}
\ No newline at end of file
+}
From ef6cfd47c3205756b21eeea3a9321e77ef4d0f6a Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Thu, 15 Aug 2024 00:51:45 +0200
Subject: [PATCH 10/42] add check if timezone was actually changed
---
app/Livewire/Server/Form.php | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index 54cdf7a14..daf21614b 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -267,15 +267,32 @@ class Form extends Component
"cat /etc/timezone 2>/dev/null || echo 'Unable to read /etc/timezone'",
];
- instant_remote_process($commands, $this->server);
-
+ ray('Commands to be executed:', $commands);
+
+ $result = instant_remote_process($commands, $this->server);
+ ray('Result of instant_remote_process:', $result);
+
+ // Check if the timezone was actually changed
+ $newTimezone = trim(instant_remote_process(["date +%Z"], $this->server, false));
+ ray('New timezone after update:', $newTimezone);
+
+ if ($newTimezone !== $value) {
+ ray('Timezone update failed. New timezone does not match requested value.');
+ $this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');
+ return false;
+ }
+
+ ray('Updating server settings');
$this->server->settings->server_timezone = $value;
$this->server->settings->save();
+ ray('Server settings updated');
+ ray('Timezone update completed successfully');
return true;
} catch (\Exception $e) {
- $this->dispatch('error', $e->getMessage());
+ ray('Exception caught:', $e->getMessage());
+ $this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());
return false;
}
}
-}
+}
\ No newline at end of file
From 1376846077b73b288a1aeaf248ce79e841792801 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Thu, 15 Aug 2024 12:04:06 +0200
Subject: [PATCH 11/42] fix: timezone not updated when systemd is missing
---
app/Livewire/Server/Form.php | 44 ++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index daf21614b..0602dce07 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -6,6 +6,7 @@ use App\Actions\Server\StartSentinel;
use App\Actions\Server\StopSentinel;
use App\Jobs\PullSentinelImageJob;
use App\Models\Server;;
+
use Livewire\Component;
class Form extends Component
@@ -78,9 +79,13 @@ class Form extends Component
$this->timezones = collect(timezone_identifiers_list())->sort()->values()->toArray();
$this->wildcard_domain = $this->server->settings->wildcard_domain;
$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;
-
+
if ($this->server->settings->server_timezone === '') {
+ ray($this->server->settings->server_timezone);
+ ray('Server timezone is empty. Setting default timezone.');
+ ray('Current timezone:', $this->server->settings->server_timezone);
$defaultTimezone = config('app.timezone');
+ ray('Default timezone:', $defaultTimezone);
$this->updateServerTimezone($defaultTimezone);
}
}
@@ -127,7 +132,6 @@ class Form extends Component
}
if ($this->server->settings->isDirty('is_server_api_enabled') && $this->server->settings->is_server_api_enabled === true) {
ray('Starting sentinel');
-
}
} else {
ray('Sentinel is not enabled');
@@ -167,7 +171,7 @@ class Form extends Component
$this->server->settings->save();
$this->dispatch('proxyStatusUpdated');
} else {
- $this->dispatch('error', 'Server is not reachable.', 'Please validate your configuration and connection.
Check this
documentation for further help.
Error: '.$error);
+ $this->dispatch('error', 'Server is not reachable.', 'Please validate your configuration and connection.
Check this
documentation for further help.
Error: ' . $error);
return;
}
@@ -240,7 +244,7 @@ class Form extends Component
$this->dispatch('success', 'Server updated.');
ray('Submit method completed');
}
-
+
public function updatedServerTimezone($value)
{
if (!is_string($value) || !in_array($value, timezone_identifiers_list())) {
@@ -251,20 +255,22 @@ class Form extends Component
$this->updateServerTimezone($value);
}
- private function updateServerTimezone($value)
+ private function updateServerTimezone($desired_timezone)
{
- ray('updateServerTimezone called with value:', $value);
+ ray('updateServerTimezone called with value:', $desired_timezone);
try {
$commands = [
- "date +%Z",
- "if command -v timedatectl >/dev/null 2>&1; then timedatectl set-timezone " . escapeshellarg($value) . " 2>&1 || echo 'timedatectl failed'; fi",
- "if [ -f /etc/timezone ]; then echo " . escapeshellarg($value) . " > /etc/timezone 2>&1 || echo '/etc/timezone update failed'; fi",
- "if [ -L /etc/localtime ] || [ -f /etc/localtime ]; then ln -sf /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 || echo '/etc/localtime update failed'; fi",
- "if command -v dpkg-reconfigure >/dev/null 2>&1; then dpkg-reconfigure -f noninteractive tzdata 2>&1 || echo 'dpkg-reconfigure failed'; fi",
- "if command -v apk >/dev/null 2>&1; then apk add --no-cache tzdata 2>&1 && cp /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 && echo " . escapeshellarg($value) . " > /etc/timezone 2>&1 || echo 'Alpine timezone update failed'; fi",
- "if [ -f /etc/sysconfig/clock ]; then sed -i 's/^ZONE=.*/ZONE=\"" . escapeshellarg($value) . "\"/' /etc/sysconfig/clock 2>&1 || echo '/etc/sysconfig/clock update failed'; fi",
- "date +%Z",
- "cat /etc/timezone 2>/dev/null || echo 'Unable to read /etc/timezone'",
+ "if [ -f /etc/timezone ]; then",
+ " echo " . escapeshellarg($desired_timezone) . " > /etc/timezone",
+ " ln -sf /usr/share/zoneinfo/" . escapeshellarg($desired_timezone) . " /etc/localtime",
+ "elif [ -f /etc/localtime ]; then",
+ " ln -sf /usr/share/zoneinfo/" . escapeshellarg($desired_timezone) . " /etc/localtime",
+ "else",
+ " echo 'Unable to set timezone'",
+ " exit 1",
+ "fi",
+ "echo \"Timezone updated to: $desired_timezone\"",
+ "date"
];
ray('Commands to be executed:', $commands);
@@ -273,17 +279,17 @@ class Form extends Component
ray('Result of instant_remote_process:', $result);
// Check if the timezone was actually changed
- $newTimezone = trim(instant_remote_process(["date +%Z"], $this->server, false));
+ $newTimezone = trim(instant_remote_process(["cat /etc/timezone 2>/dev/null || readlink /etc/localtime | sed 's#/usr/share/zoneinfo/##'"], $this->server, false));
ray('New timezone after update:', $newTimezone);
- if ($newTimezone !== $value) {
+ if ($newTimezone !== $desired_timezone) {
ray('Timezone update failed. New timezone does not match requested value.');
$this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');
return false;
}
ray('Updating server settings');
- $this->server->settings->server_timezone = $value;
+ $this->server->settings->server_timezone = $desired_timezone;
$this->server->settings->save();
ray('Server settings updated');
@@ -295,4 +301,4 @@ class Form extends Component
return false;
}
}
-}
\ No newline at end of file
+}
From a51b306c083f144b0ac0871219f0ea03fb374dae Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Thu, 15 Aug 2024 13:13:52 +0200
Subject: [PATCH 12/42] support all coolify supported os and improve symbolic
link creation
---
app/Livewire/Server/Form.php | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index 0602dce07..7f99375d1 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -260,15 +260,32 @@ class Form extends Component
ray('updateServerTimezone called with value:', $desired_timezone);
try {
$commands = [
- "if [ -f /etc/timezone ]; then",
+ "if command -v timedatectl > /dev/null 2>&1 && pidof systemd > /dev/null; then",
+ " timedatectl set-timezone " . escapeshellarg($desired_timezone),
+ "elif [ -f /etc/timezone ]; then",
" echo " . escapeshellarg($desired_timezone) . " > /etc/timezone",
+ " rm -f /etc/localtime",
" ln -sf /usr/share/zoneinfo/" . escapeshellarg($desired_timezone) . " /etc/localtime",
"elif [ -f /etc/localtime ]; then",
+ " rm -f /etc/localtime",
" ln -sf /usr/share/zoneinfo/" . escapeshellarg($desired_timezone) . " /etc/localtime",
"else",
" echo 'Unable to set timezone'",
" exit 1",
"fi",
+ "if command -v dpkg-reconfigure > /dev/null 2>&1; then",
+ " dpkg-reconfigure -f noninteractive tzdata",
+ "elif command -v tzdata-update > /dev/null 2>&1; then",
+ " tzdata-update",
+ "elif [ -f /etc/sysconfig/clock ]; then",
+ " sed -i 's/^ZONE=.*/ZONE=\"" . $desired_timezone . "\"/' /etc/sysconfig/clock",
+ " source /etc/sysconfig/clock",
+ "fi",
+ "if command -v systemctl > /dev/null 2>&1 && pidof systemd > /dev/null; then",
+ " systemctl try-restart systemd-timesyncd.service || true",
+ "elif command -v service > /dev/null 2>&1; then",
+ " service ntpd restart || service ntp restart || true",
+ "fi",
"echo \"Timezone updated to: $desired_timezone\"",
"date"
];
@@ -279,7 +296,7 @@ class Form extends Component
ray('Result of instant_remote_process:', $result);
// Check if the timezone was actually changed
- $newTimezone = trim(instant_remote_process(["cat /etc/timezone 2>/dev/null || readlink /etc/localtime | sed 's#/usr/share/zoneinfo/##'"], $this->server, false));
+ $newTimezone = trim(instant_remote_process(["date +%Z"], $this->server, false));
ray('New timezone after update:', $newTimezone);
if ($newTimezone !== $desired_timezone) {
@@ -301,4 +318,4 @@ class Form extends Component
return false;
}
}
-}
+}
\ No newline at end of file
From a1915e40f7a03f687a87be1a267f72a5169a8a66 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Thu, 15 Aug 2024 13:25:30 +0200
Subject: [PATCH 13/42] new timezone validation and conversion to check
---
app/Livewire/Server/Form.php | 50 ++++++++++++++++++++++++++----------
1 file changed, 37 insertions(+), 13 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index 7f99375d1..362f49803 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -295,27 +295,51 @@ class Form extends Component
$result = instant_remote_process($commands, $this->server);
ray('Result of instant_remote_process:', $result);
- // Check if the timezone was actually changed
- $newTimezone = trim(instant_remote_process(["date +%Z"], $this->server, false));
- ray('New timezone after update:', $newTimezone);
-
- if ($newTimezone !== $desired_timezone) {
- ray('Timezone update failed. New timezone does not match requested value.');
- $this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');
+ // Improved verification
+ $verificationCommands = [
+ "date +'%Z %:z'",
+ "readlink /etc/localtime | sed 's#/usr/share/zoneinfo/##'",
+ ];
+ $verificationResult = instant_remote_process($verificationCommands, $this->server, false);
+ $verificationLines = explode("\n", trim($verificationResult));
+
+ if (count($verificationLines) !== 2) {
+ ray('Unexpected verification result:', $verificationResult);
+ $this->dispatch('error', 'Failed to verify timezone update. Unexpected server response.');
return false;
}
- ray('Updating server settings');
- $this->server->settings->server_timezone = $desired_timezone;
- $this->server->settings->save();
- ray('Server settings updated');
+ [$abbreviation, $offset] = explode(' ', $verificationLines[0]);
+ $actualTimezone = trim($verificationLines[1]);
- ray('Timezone update completed successfully');
- return true;
+ // Convert desired_timezone to DateTimeZone for comparison
+ $desiredTz = new \DateTimeZone($desired_timezone);
+ $desiredAbbr = (new \DateTime('now', $desiredTz))->format('T');
+ $desiredOffset = $desiredTz->getOffset(new \DateTime('now', $desiredTz));
+
+ // Compare abbreviation, offset, and actual timezone
+ if ($abbreviation === $desiredAbbr && $offset === $this->formatOffset($desiredOffset) && $actualTimezone === $desired_timezone) {
+ ray('Timezone update verified successfully');
+ $this->server->settings->server_timezone = $desired_timezone;
+ $this->server->settings->save();
+ ray('Server settings updated');
+ return true;
+ } else {
+ ray('Timezone verification failed. Expected:', $desired_timezone, 'Actual:', $actualTimezone);
+ $this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');
+ return false;
+ }
} catch (\Exception $e) {
ray('Exception caught:', $e->getMessage());
$this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());
return false;
}
}
+
+ private function formatOffset($offsetSeconds)
+ {
+ $hours = abs($offsetSeconds) / 3600;
+ $minutes = (abs($offsetSeconds) % 3600) / 60;
+ return sprintf('%s%02d:%02d', $offsetSeconds >= 0 ? '+' : '-', $hours, $minutes);
+ }
}
\ No newline at end of file
From 39b132f7e9ad204e469764e3aaec7e1274045723 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Thu, 15 Aug 2024 13:30:08 +0200
Subject: [PATCH 14/42] verification compares to destination timezone
---
app/Livewire/Server/Form.php | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index 362f49803..15b235f1b 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -289,16 +289,16 @@ class Form extends Component
"echo \"Timezone updated to: $desired_timezone\"",
"date"
];
-
+
ray('Commands to be executed:', $commands);
-
+
$result = instant_remote_process($commands, $this->server);
ray('Result of instant_remote_process:', $result);
-
+
// Improved verification
$verificationCommands = [
- "date +'%Z %:z'",
"readlink /etc/localtime | sed 's#/usr/share/zoneinfo/##'",
+ "date +'%Z %:z'"
];
$verificationResult = instant_remote_process($verificationCommands, $this->server, false);
$verificationLines = explode("\n", trim($verificationResult));
@@ -308,17 +308,17 @@ class Form extends Component
$this->dispatch('error', 'Failed to verify timezone update. Unexpected server response.');
return false;
}
-
- [$abbreviation, $offset] = explode(' ', $verificationLines[0]);
- $actualTimezone = trim($verificationLines[1]);
-
+
+ $actualTimezone = trim($verificationLines[0]);
+ [$abbreviation, $offset] = explode(' ', trim($verificationLines[1]));
+
// Convert desired_timezone to DateTimeZone for comparison
$desiredTz = new \DateTimeZone($desired_timezone);
$desiredAbbr = (new \DateTime('now', $desiredTz))->format('T');
- $desiredOffset = $desiredTz->getOffset(new \DateTime('now', $desiredTz));
-
- // Compare abbreviation, offset, and actual timezone
- if ($abbreviation === $desiredAbbr && $offset === $this->formatOffset($desiredOffset) && $actualTimezone === $desired_timezone) {
+ $desiredOffset = $this->formatOffset($desiredTz->getOffset(new \DateTime('now', $desiredTz)));
+
+ // Compare actual timezone, abbreviation, and offset with the desired timezone
+ if ($actualTimezone === $desired_timezone && $abbreviation === $desiredAbbr && $offset === $desiredOffset) {
ray('Timezone update verified successfully');
$this->server->settings->server_timezone = $desired_timezone;
$this->server->settings->save();
@@ -326,6 +326,8 @@ class Form extends Component
return true;
} else {
ray('Timezone verification failed. Expected:', $desired_timezone, 'Actual:', $actualTimezone);
+ ray('Expected abbreviation:', $desiredAbbr, 'Actual:', $abbreviation);
+ ray('Expected offset:', $desiredOffset, 'Actual:', $offset);
$this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');
return false;
}
@@ -335,7 +337,7 @@ class Form extends Component
return false;
}
}
-
+
private function formatOffset($offsetSeconds)
{
$hours = abs($offsetSeconds) / 3600;
From f281e9295487b12d771ee3d6e107394b7e629e44 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Thu, 15 Aug 2024 13:36:17 +0200
Subject: [PATCH 15/42] remove ray
---
app/Livewire/Server/Form.php | 50 ++++++------------------------------
1 file changed, 8 insertions(+), 42 deletions(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index 15b235f1b..a9277068c 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -81,11 +81,7 @@ class Form extends Component
$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;
if ($this->server->settings->server_timezone === '') {
- ray($this->server->settings->server_timezone);
- ray('Server timezone is empty. Setting default timezone.');
- ray('Current timezone:', $this->server->settings->server_timezone);
$defaultTimezone = config('app.timezone');
- ray('Default timezone:', $defaultTimezone);
$this->updateServerTimezone($defaultTimezone);
}
}
@@ -187,7 +183,6 @@ class Form extends Component
public function submit()
{
- ray('Submit method called');
if (isCloud() && !isDev()) {
$this->validate();
$this->validate([
@@ -207,42 +202,27 @@ class Form extends Component
$this->server->settings->wildcard_domain = $this->wildcard_domain;
$this->server->settings->cleanup_after_percentage = $this->cleanup_after_percentage;
- ray('Current timezone:', $this->server->settings->getOriginal('server_timezone'));
- ray('New timezone:', $this->server->settings->server_timezone);
-
$currentTimezone = $this->server->settings->getOriginal('server_timezone');
$newTimezone = $this->server->settings->server_timezone;
- ray('Comparing timezones:', $currentTimezone, $newTimezone);
-
if ($currentTimezone !== $newTimezone || $currentTimezone === '') {
- ray('Timezone change detected');
try {
- ray('Calling updateServerTimezone');
$timezoneUpdated = $this->updateServerTimezone($newTimezone);
- ray('updateServerTimezone result:', $timezoneUpdated);
if ($timezoneUpdated) {
$this->server->settings->server_timezone = $newTimezone;
$this->server->settings->save();
- ray('New timezone saved to database:', $newTimezone);
} else {
- ray('Timezone update failed');
return;
}
} catch (\Exception $e) {
- ray('Exception in updateServerTimezone:', $e->getMessage());
$this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());
return;
}
- } else {
- ray('No timezone change detected');
}
- ray('Saving server settings');
$this->server->settings->save();
$this->server->save();
$this->dispatch('success', 'Server updated.');
- ray('Submit method completed');
}
public function updatedServerTimezone($value)
@@ -257,7 +237,6 @@ class Form extends Component
private function updateServerTimezone($desired_timezone)
{
- ray('updateServerTimezone called with value:', $desired_timezone);
try {
$commands = [
"if command -v timedatectl > /dev/null 2>&1 && pidof systemd > /dev/null; then",
@@ -289,59 +268,46 @@ class Form extends Component
"echo \"Timezone updated to: $desired_timezone\"",
"date"
];
-
- ray('Commands to be executed:', $commands);
-
+
$result = instant_remote_process($commands, $this->server);
- ray('Result of instant_remote_process:', $result);
-
- // Improved verification
+
$verificationCommands = [
"readlink /etc/localtime | sed 's#/usr/share/zoneinfo/##'",
"date +'%Z %:z'"
];
$verificationResult = instant_remote_process($verificationCommands, $this->server, false);
$verificationLines = explode("\n", trim($verificationResult));
-
+
if (count($verificationLines) !== 2) {
- ray('Unexpected verification result:', $verificationResult);
$this->dispatch('error', 'Failed to verify timezone update. Unexpected server response.');
return false;
}
-
+
$actualTimezone = trim($verificationLines[0]);
[$abbreviation, $offset] = explode(' ', trim($verificationLines[1]));
-
- // Convert desired_timezone to DateTimeZone for comparison
+
$desiredTz = new \DateTimeZone($desired_timezone);
$desiredAbbr = (new \DateTime('now', $desiredTz))->format('T');
$desiredOffset = $this->formatOffset($desiredTz->getOffset(new \DateTime('now', $desiredTz)));
-
- // Compare actual timezone, abbreviation, and offset with the desired timezone
+
if ($actualTimezone === $desired_timezone && $abbreviation === $desiredAbbr && $offset === $desiredOffset) {
- ray('Timezone update verified successfully');
$this->server->settings->server_timezone = $desired_timezone;
$this->server->settings->save();
- ray('Server settings updated');
return true;
} else {
- ray('Timezone verification failed. Expected:', $desired_timezone, 'Actual:', $actualTimezone);
- ray('Expected abbreviation:', $desiredAbbr, 'Actual:', $abbreviation);
- ray('Expected offset:', $desiredOffset, 'Actual:', $offset);
$this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');
return false;
}
} catch (\Exception $e) {
- ray('Exception caught:', $e->getMessage());
$this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());
return false;
}
}
-
+
private function formatOffset($offsetSeconds)
{
$hours = abs($offsetSeconds) / 3600;
$minutes = (abs($offsetSeconds) % 3600) / 60;
return sprintf('%s%02d:%02d', $offsetSeconds >= 0 ? '+' : '-', $hours, $minutes);
}
-}
\ No newline at end of file
+}
From a478ebef2ec562bb5caa29a9ad648adbb21def7b Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Thu, 15 Aug 2024 13:37:52 +0200
Subject: [PATCH 16/42] remove result var
---
app/Livewire/Server/Form.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index a9277068c..fbd354e05 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -269,7 +269,7 @@ class Form extends Component
"date"
];
- $result = instant_remote_process($commands, $this->server);
+ instant_remote_process($commands, $this->server);
$verificationCommands = [
"readlink /etc/localtime | sed 's#/usr/share/zoneinfo/##'",
From 1892ce4e123c4bbf35715a90bbdee1ea69920617 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Fri, 16 Aug 2024 12:58:19 +0200
Subject: [PATCH 17/42] Feat: cron jobs are executed based on the server
timezone
---
app/Console/Kernel.php | 10 ++++++----
app/Jobs/ScheduledTaskJob.php | 8 +++++++-
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index e8f213b16..f1b9bf3d4 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -139,10 +139,9 @@ class Kernel extends ConsoleKernel
$service = $scheduled_task->service;
$application = $scheduled_task->application;
- if (! $application && ! $service) {
+ if (!$application && !$service) {
ray('application/service attached to scheduled task does not exist');
$scheduled_task->delete();
-
continue;
}
if ($application) {
@@ -158,9 +157,12 @@ class Kernel extends ConsoleKernel
if (isset(VALID_CRON_STRINGS[$scheduled_task->frequency])) {
$scheduled_task->frequency = VALID_CRON_STRINGS[$scheduled_task->frequency];
}
+ $server_timezone = $application ? $application->destination->server->settings->server_timezone : $service->destination->server->settings->server_timezone;
+ $server_timezone = $server_timezone;
+ ray($server_timezone);
$schedule->job(new ScheduledTaskJob(
task: $scheduled_task
- ))->cron($scheduled_task->frequency)->onOneServer();
+ ))->cron($scheduled_task->frequency)->timezone($server_timezone)->onOneServer();
}
}
@@ -170,4 +172,4 @@ class Kernel extends ConsoleKernel
require base_path('routes/console.php');
}
-}
+}
\ No newline at end of file
diff --git a/app/Jobs/ScheduledTaskJob.php b/app/Jobs/ScheduledTaskJob.php
index 819e28f89..2e8bf4015 100644
--- a/app/Jobs/ScheduledTaskJob.php
+++ b/app/Jobs/ScheduledTaskJob.php
@@ -36,6 +36,8 @@ class ScheduledTaskJob implements ShouldQueue
public array $containers = [];
+ public string $server_timezone;
+
public function __construct($task)
{
$this->task = $task;
@@ -47,6 +49,7 @@ class ScheduledTaskJob implements ShouldQueue
throw new \RuntimeException('ScheduledTaskJob failed: No resource found.');
}
$this->team = Team::find($task->team_id);
+ $this->server_timezone = $this->resource->destination->server->settings->server_timezone;
}
public function middleware(): array
@@ -61,6 +64,7 @@ class ScheduledTaskJob implements ShouldQueue
public function handle(): void
{
+
try {
$this->task_log = ScheduledTaskExecution::create([
'scheduled_task_id' => $this->task->id,
@@ -121,6 +125,8 @@ class ScheduledTaskJob implements ShouldQueue
$this->team?->notify(new TaskFailed($this->task, $e->getMessage()));
// send_internal_notification('ScheduledTaskJob failed with: ' . $e->getMessage());
throw $e;
+ } finally {
+
}
}
-}
+}
\ No newline at end of file
From ea4b085dbe082f75070e8db1fc2caaf847785334 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Fri, 16 Aug 2024 13:04:44 +0200
Subject: [PATCH 18/42] add server timezone to every schedule
---
app/Console/Kernel.php | 73 ++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 34 deletions(-)
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index f1b9bf3d4..8cfcb0168 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -30,62 +30,70 @@ class Kernel extends ConsoleKernel
$this->all_servers = Server::all();
$settings = InstanceSettings::get();
+ $serverTimezone = $this->getServerTimezone();
+
if (isDev()) {
// Instance Jobs
- $schedule->command('horizon:snapshot')->everyMinute();
- $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
+ $schedule->command('horizon:snapshot')->everyMinute()->timezone($serverTimezone);
+ $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer()->timezone($serverTimezone);
// Server Jobs
- $this->check_scheduled_backups($schedule);
- $this->check_resources($schedule);
- $this->check_scheduled_tasks($schedule);
- $schedule->command('uploads:clear')->everyTwoMinutes();
+ $this->check_scheduled_backups($schedule, $serverTimezone);
+ $this->check_resources($schedule, $serverTimezone);
+ $this->check_scheduled_tasks($schedule, $serverTimezone);
+ $schedule->command('uploads:clear')->everyTwoMinutes()->timezone($serverTimezone);
} else {
// Instance Jobs
- $schedule->command('horizon:snapshot')->everyFiveMinutes();
- $schedule->command('cleanup:unreachable-servers')->daily();
- $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();
- $schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->onOneServer();
- $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
- $this->schedule_updates($schedule);
+ $schedule->command('horizon:snapshot')->everyFiveMinutes()->timezone($serverTimezone);
+ $schedule->command('cleanup:unreachable-servers')->daily()->timezone($serverTimezone);
+ $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer()->timezone($serverTimezone);
+ $schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->onOneServer()->timezone($serverTimezone);
+ $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer()->timezone($serverTimezone);
+ $this->schedule_updates($schedule, $serverTimezone);
// Server Jobs
- $this->check_scheduled_backups($schedule);
- $this->check_resources($schedule);
- $this->pull_images($schedule);
- $this->check_scheduled_tasks($schedule);
+ $this->check_scheduled_backups($schedule, $serverTimezone);
+ $this->check_resources($schedule, $serverTimezone);
+ $this->pull_images($schedule, $serverTimezone);
+ $this->check_scheduled_tasks($schedule, $serverTimezone);
- $schedule->command('cleanup:database --yes')->daily();
- $schedule->command('uploads:clear')->everyTwoMinutes();
+ $schedule->command('cleanup:database --yes')->daily()->timezone($serverTimezone);
+ $schedule->command('uploads:clear')->everyTwoMinutes()->timezone($serverTimezone);
}
}
- private function pull_images($schedule)
+ private function getServerTimezone()
+ {
+ $server = Server::find(0); // Only main server is used for scheduling tasks, not each server timezone?
+ return $server->settings->server_timezone;
+ }
+
+ private function pull_images($schedule, $serverTimezone)
{
$settings = InstanceSettings::get();
$servers = $this->all_servers->where('settings.is_usable', true)->where('settings.is_reachable', true)->where('ip', '!=', '1.2.3.4');
foreach ($servers as $server) {
if ($server->isSentinelEnabled()) {
- $schedule->job(new PullSentinelImageJob($server))->cron($settings->update_check_frequency)->onOneServer();
+ $schedule->job(new PullSentinelImageJob($server))->cron($settings->update_check_frequency)->onOneServer()->timezone($serverTimezone);
}
- $schedule->job(new PullHelperImageJob($server))->cron($settings->update_check_frequency)->onOneServer();
+ $schedule->job(new PullHelperImageJob($server))->cron($settings->update_check_frequency)->onOneServer()->timezone($serverTimezone);
}
}
- private function schedule_updates($schedule)
+ private function schedule_updates($schedule, $serverTimezone)
{
$settings = InstanceSettings::get();
$updateCheckFrequency = $settings->update_check_frequency;
- $schedule->job(new CheckForUpdatesJob)->cron($updateCheckFrequency)->onOneServer();
+ $schedule->job(new CheckForUpdatesJob)->cron($updateCheckFrequency)->onOneServer()->timezone($serverTimezone);
if ($settings->is_auto_update_enabled) {
$autoUpdateFrequency = $settings->auto_update_frequency;
- $schedule->job(new UpdateCoolifyJob)->cron($autoUpdateFrequency)->onOneServer();
+ $schedule->job(new UpdateCoolifyJob)->cron($autoUpdateFrequency)->onOneServer()->timezone($serverTimezone);
}
}
- private function check_resources($schedule)
+ private function check_resources($schedule, $serverTimezone)
{
if (isCloud()) {
$servers = $this->all_servers->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false)->where('ip', '!=', '1.2.3.4');
@@ -95,12 +103,12 @@ class Kernel extends ConsoleKernel
$servers = $this->all_servers->where('ip', '!=', '1.2.3.4');
}
foreach ($servers as $server) {
- $schedule->job(new ServerCheckJob($server))->everyMinute()->onOneServer();
- $schedule->job(new DockerCleanupJob($server))->everyTenMinutes()->onOneServer();
+ $schedule->job(new ServerCheckJob($server))->everyMinute()->onOneServer()->timezone($serverTimezone);
+ $schedule->job(new DockerCleanupJob($server))->everyTenMinutes()->onOneServer()->timezone($serverTimezone);
}
}
- private function check_scheduled_backups($schedule)
+ private function check_scheduled_backups($schedule, $serverTimezone)
{
$scheduled_backups = ScheduledDatabaseBackup::all();
if ($scheduled_backups->isEmpty()) {
@@ -122,11 +130,11 @@ class Kernel extends ConsoleKernel
}
$schedule->job(new DatabaseBackupJob(
backup: $scheduled_backup
- ))->cron($scheduled_backup->frequency)->onOneServer();
+ ))->cron($scheduled_backup->frequency)->onOneServer()->timezone($serverTimezone);
}
}
- private function check_scheduled_tasks($schedule)
+ private function check_scheduled_tasks($schedule, $serverTimezone)
{
$scheduled_tasks = ScheduledTask::all();
if ($scheduled_tasks->isEmpty()) {
@@ -157,12 +165,9 @@ class Kernel extends ConsoleKernel
if (isset(VALID_CRON_STRINGS[$scheduled_task->frequency])) {
$scheduled_task->frequency = VALID_CRON_STRINGS[$scheduled_task->frequency];
}
- $server_timezone = $application ? $application->destination->server->settings->server_timezone : $service->destination->server->settings->server_timezone;
- $server_timezone = $server_timezone;
- ray($server_timezone);
$schedule->job(new ScheduledTaskJob(
task: $scheduled_task
- ))->cron($scheduled_task->frequency)->timezone($server_timezone)->onOneServer();
+ ))->cron($scheduled_task->frequency)->timezone($serverTimezone)->onOneServer();
}
}
From e3b988424711ee61fe60d658783497d57f61f011 Mon Sep 17 00:00:00 2001
From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com>
Date: Fri, 16 Aug 2024 14:45:40 +0200
Subject: [PATCH 19/42] UI fix
---
.../Shared/ScheduledTask/Executions.php | 12 +++++++++--
.../scheduled-task/executions.blade.php | 20 +++++++++++++++++--
.../shared/scheduled-task/show.blade.php | 4 ++--
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/app/Livewire/Project/Shared/ScheduledTask/Executions.php b/app/Livewire/Project/Shared/ScheduledTask/Executions.php
index 7a2e14e89..3ee053e3e 100644
--- a/app/Livewire/Project/Shared/ScheduledTask/Executions.php
+++ b/app/Livewire/Project/Shared/ScheduledTask/Executions.php
@@ -7,8 +7,8 @@ use Livewire\Component;
class Executions extends Component
{
public $executions = [];
-
public $selectedKey;
+ public $task;
public function getListeners()
{
@@ -26,4 +26,12 @@ class Executions extends Component
}
$this->selectedKey = $key;
}
-}
+
+ public function getServerTimezone()
+ {
+ $server = data_get($this, 'destination.server');
+ $serverTimezone = $server->settings->server_timezone;
+ ray('Server Timezone:', $serverTimezone);
+ return $serverTimezone;
+ }
+}
\ No newline at end of file
diff --git a/resources/views/livewire/project/shared/scheduled-task/executions.blade.php b/resources/views/livewire/project/shared/scheduled-task/executions.blade.php
index afbf1ea93..cf7a591d7 100644
--- a/resources/views/livewire/project/shared/scheduled-task/executions.blade.php
+++ b/resources/views/livewire/project/shared/scheduled-task/executions.blade.php
@@ -24,9 +24,25 @@
Started At:
+ @php
+ $createdAt = data_get($execution, 'created_at', now());
+ $serverTimezone = $this->getServerTimezone();
+ ray('Created At:', $createdAt, 'Server Timezone:', $serverTimezone);
+
+ $date = new DateTime($createdAt);
+ if ($serverTimezone) {
+ try {
+ $date->setTimezone(new DateTimeZone($serverTimezone));
+ } catch (\Exception $e) {
+ ray('Invalid timezone:', $serverTimezone);
+ }
+ }
+ echo $date->format('Y-m-d H:i:s T');
+ @endphp
+
No executions found.