remove unnecessary validation and fix safe to DB
This commit is contained in:
@@ -243,6 +243,7 @@ class Form extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->server->settings->server_timezone = $value;
|
$this->server->settings->server_timezone = $value;
|
||||||
|
$this->updateServerTimezone($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateServerTimezone($value)
|
private function updateServerTimezone($value)
|
||||||
@@ -261,41 +262,12 @@ class Form extends Component
|
|||||||
"cat /etc/timezone 2>/dev/null || echo 'Unable to read /etc/timezone'",
|
"cat /etc/timezone 2>/dev/null || echo 'Unable to read /etc/timezone'",
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = instant_remote_process($commands, $this->server);
|
instant_remote_process($commands, $this->server);
|
||||||
|
|
||||||
if (!isset($result['output']) || empty($result['output'])) {
|
$this->server->settings->server_timezone = $value;
|
||||||
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->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;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->dispatch('error', $e->getMessage());
|
$this->dispatch('error', $e->getMessage());
|
||||||
|
Reference in New Issue
Block a user