diff --git a/src/Command/Self/SelfStatusCommand.php b/src/Command/Self/SelfStatusCommand.php new file mode 100644 index 000000000..731427b16 --- /dev/null +++ b/src/Command/Self/SelfStatusCommand.php @@ -0,0 +1,34 @@ +setStyle('borderless'); + $table->setHeaders(['Property', 'Value']); + $table->addRow(['Version', $this->getApplication()->getVersion()]); + $table->addRow(['Cloud datastore', $this->datastoreCloud->filepath]); + $table->addRow(['ACLI datastore', $this->datastoreAcli->filepath]); + $table->addRow(['Telemetry enabled', var_export($this->telemetryHelper->telemetryEnabled(), true)]); + $table->addRow(['User ID', $this->telemetryHelper->getUserId()]); + foreach ($this->telemetryHelper->getTelemetryUserData() as $key => $value) { + $table->addRow([$key, $value]); + } + $table->render(); + return Command::SUCCESS; + } +} diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index e5e575a66..d306b1f65 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -39,8 +39,7 @@ public function initializeBugsnag(): void if (empty($this->bugSnagKey)) { return; } - $sendTelemetry = $this->datastoreCloud->get(DataStoreContract::SEND_TELEMETRY); - if ($sendTelemetry === false) { + if (!$this->telemetryEnabled()) { return; } // It's safe-ish to make this key public. @@ -89,11 +88,10 @@ public function initializeAmplitude(): void if (empty($this->amplitudeKey)) { return; } - $sendTelemetry = $this->datastoreCloud->get(DataStoreContract::SEND_TELEMETRY); $amplitude = Amplitude::getInstance(); - $amplitude->setOptOut($sendTelemetry === false); + $amplitude->setOptOut($this->telemetryEnabled()); - if ($sendTelemetry === false) { + if (!$this->telemetryEnabled()) { return; } try { @@ -109,6 +107,11 @@ public function initializeAmplitude(): void } } + public function telemetryEnabled(): bool + { + return (bool) $this->datastoreCloud->get(DataStoreContract::SEND_TELEMETRY); + } + /** * @param string $ah_env * Environment name from AH_ENV. @@ -140,7 +143,7 @@ public static function normalizeAhEnv(string $ah_env): string * * @return array Telemetry user data. */ - private function getTelemetryUserData(): array + public function getTelemetryUserData(): array { $data = [ 'ah_app_uuid' => getenv('AH_APPLICATION_UUID'), @@ -179,7 +182,7 @@ public static function getEnvironmentProvider(): ?string return null; } - private function getUserId(): ?string + public function getUserId(): ?string { $user = $this->getUserData(); if ($user && isset($user['uuid'])) {