From f59796e29064bac8c8eb4ba1b2a2c079c4f714d4 Mon Sep 17 00:00:00 2001 From: Darshan Date: Mon, 26 Jan 2026 18:06:36 +0530 Subject: [PATCH] update: use helpers. --- .../Platform/Installer/HttpHandler.php | 9 +++++++-- .../Platform/Installer/Runtime/Config.php | 18 +++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Installer/HttpHandler.php b/src/Appwrite/Platform/Installer/HttpHandler.php index 46dc87bd4b..0ad2c6f048 100644 --- a/src/Appwrite/Platform/Installer/HttpHandler.php +++ b/src/Appwrite/Platform/Installer/HttpHandler.php @@ -152,7 +152,7 @@ class HttpHandler } $data = $this->state->readProgressFile($installId); - if (is_array($data) && isset($data['payload']) && is_array($data['payload'])) { + if ($this->hasPayload($data)) { unset($data['payload']['opensslKey'], $data['payload']['assistantOpenAIKey']); } echo json_encode(['success' => true, 'progress' => $data]); @@ -413,7 +413,7 @@ class HttpHandler '_APP_ASSISTANT_OPENAI_API_KEY' => $input['assistantOpenAIKey'] ?? '', ]; - if (is_array($existing) && isset($existing['payload']) && is_array($existing['payload'])) { + if ($this->hasPayload($existing)) { $stored = $existing['payload']; $fieldsToCompare = [ 'httpPort', @@ -636,6 +636,11 @@ class HttpHandler return $details; } + private function hasPayload(mixed $data): bool + { + return is_array($data) && isset($data['payload']) && is_array($data['payload']); + } + private function handleInstallationError(\Throwable $e, string $installId, bool $wantsStream): void { http_response_code(self::HTTP_INTERNAL_SERVER_ERROR); diff --git a/src/Appwrite/Platform/Installer/Runtime/Config.php b/src/Appwrite/Platform/Installer/Runtime/Config.php index 4161a6e444..d29411ea61 100644 --- a/src/Appwrite/Platform/Installer/Runtime/Config.php +++ b/src/Appwrite/Platform/Installer/Runtime/Config.php @@ -41,16 +41,16 @@ final class Config public function apply(array $values): void { - if (array_key_exists('defaultHttpPort', $values) && $values['defaultHttpPort'] !== null && $values['defaultHttpPort'] !== '') { + if ($this->hasValidStringValue($values, 'defaultHttpPort')) { $this->setDefaultHttpPort((string) $values['defaultHttpPort']); } - if (array_key_exists('defaultHttpsPort', $values) && $values['defaultHttpsPort'] !== null && $values['defaultHttpsPort'] !== '') { + if ($this->hasValidStringValue($values, 'defaultHttpsPort')) { $this->setDefaultHttpsPort((string) $values['defaultHttpsPort']); } - if (array_key_exists('organization', $values) && $values['organization'] !== null && $values['organization'] !== '') { + if ($this->hasValidStringValue($values, 'organization')) { $this->setOrganization((string) $values['organization']); } - if (array_key_exists('image', $values) && $values['image'] !== null && $values['image'] !== '') { + if ($this->hasValidStringValue($values, 'image')) { $this->setImage((string) $values['image']); } if (array_key_exists('noStart', $values) && $values['noStart'] !== null) { @@ -69,15 +69,19 @@ final class Config $hostPath = $values['hostPath']; $this->setHostPath($hostPath !== null && $hostPath !== '' ? (string) $hostPath : null); } - if (array_key_exists('lockedDatabase', $values) && $values['lockedDatabase'] !== null && $values['lockedDatabase'] !== '') { - $locked = $values['lockedDatabase']; - $this->setLockedDatabase($locked !== null && $locked !== '' ? (string) $locked : null); + if ($this->hasValidStringValue($values, 'lockedDatabase')) { + $this->setLockedDatabase((string) $values['lockedDatabase']); } if (array_key_exists('vars', $values) && is_array($values['vars'])) { $this->setVars($values['vars']); } } + private function hasValidStringValue(array $values, string $key): bool + { + return array_key_exists($key, $values) && $values[$key] !== null && $values[$key] !== ''; + } + private function containsKnownKeys(array $values): bool { foreach (self::KNOWN_KEYS as $key) {