From 14acd9e3c2444d5ff569a20f45752b23c2a31363 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 29 Jul 2026 04:52:10 +0000 Subject: [PATCH] fix(install): honor resolved telemetry opt-out and DO_NOT_TRACK=yes Check _APP_TELEMETRY from resolved installer input (existing .env) and accept the standard DO_NOT_TRACK=yes value so upgrade pings respect opt-out. Co-authored-by: Chirag Aggarwal --- src/Appwrite/Platform/Tasks/Install.php | 25 ++++++++++++++++++----- tests/unit/Platform/Tasks/InstallTest.php | 17 +++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index f32c5a8e19..280f48deef 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -881,7 +881,7 @@ class Install extends Action */ public function buildSelfHostedInstallPayload(array $input, bool $isUpgrade, string $version): ?array { - if ($this->isTelemetryDisabled()) { + if ($this->isTelemetryDisabled($input)) { return null; } @@ -928,16 +928,31 @@ class Install extends Action /** * Whether the operator opted out of anonymous install/upgrade telemetry. * - * Honors DO_NOT_TRACK (https://consoledonottrack.com) and _APP_TELEMETRY=disabled. + * Honors DO_NOT_TRACK (https://consoledonottrack.com) and _APP_TELEMETRY=disabled + * from the process environment or resolved installer `$input` (e.g. existing `.env`). + * + * @param array|null $input Resolved environment variables */ - public function isTelemetryDisabled(): bool + public function isTelemetryDisabled(?array $input = null): bool { $doNotTrack = \strtolower((string) System::getEnv('DO_NOT_TRACK', '')); - if ($doNotTrack === '1' || $doNotTrack === 'true') { + if (\in_array($doNotTrack, ['1', 'true', 'yes'], true)) { return true; } - return \strtolower((string) System::getEnv('_APP_TELEMETRY', '')) === 'disabled'; + $telemetry = \strtolower((string) System::getEnv('_APP_TELEMETRY', '')); + if ($telemetry === 'disabled') { + return true; + } + + if ($input !== null) { + $fromInput = \strtolower((string) ($input['_APP_TELEMETRY'] ?? '')); + if ($fromInput === 'disabled') { + return true; + } + } + + return false; } /** diff --git a/tests/unit/Platform/Tasks/InstallTest.php b/tests/unit/Platform/Tasks/InstallTest.php index a5573f0453..291a2abb66 100644 --- a/tests/unit/Platform/Tasks/InstallTest.php +++ b/tests/unit/Platform/Tasks/InstallTest.php @@ -87,6 +87,14 @@ final class InstallTest extends TestCase $this->assertTrue($this->install->isTelemetryDisabled()); } + public function testDoNotTrackYesValueDisablesTelemetry(): void + { + \putenv('DO_NOT_TRACK=yes'); + + $this->assertTrue($this->install->isTelemetryDisabled()); + $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); + } + public function testAppTelemetryDisabledDisablesTelemetry(): void { \putenv('_APP_TELEMETRY=disabled'); @@ -95,6 +103,15 @@ final class InstallTest extends TestCase $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); } + public function testResolvedInputTelemetryDisabledDisablesTelemetry(): void + { + $input = $this->productionInput(); + $input['_APP_TELEMETRY'] = 'disabled'; + + $this->assertTrue($this->install->isTelemetryDisabled($input)); + $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6')); + } + public function testTelemetryEnabledByDefault(): void { $this->assertFalse($this->install->isTelemetryDisabled());