. */ declare(strict_types=1); namespace FireflyIII\Console\Commands\Integrity; use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Support\System\OAuthKeys; use Illuminate\Console\Command; /** * Class RestoreOAuthKeys */ class RestoreOAuthKeys extends Command { use ShowsFriendlyMessages; protected $description = 'Will restore the OAuth keys generated for the system.'; protected $signature = 'firefly-iii:restore-oauth-keys'; /** * Execute the console command. * * @return int */ public function handle(): int { $this->restoreOAuthKeys(); return 0; } /** * */ private function restoreOAuthKeys(): void { if (!$this->keysInDatabase() && !$this->keysOnDrive()) { $this->generateKeys(); $this->storeKeysInDB(); $this->friendlyInfo('Generated and stored new keys.'); return; } if ($this->keysInDatabase() && !$this->keysOnDrive()) { $result = $this->restoreKeysFromDB(); if (true === $result) { $this->friendlyInfo('Restored OAuth keys from database.'); return; } $this->generateKeys(); $this->storeKeysInDB(); $this->friendlyInfo('Generated and stored new keys.'); return; } if (!$this->keysInDatabase() && $this->keysOnDrive()) { $this->storeKeysInDB(); $this->friendlyInfo('Stored OAuth keys in database.'); return; } $this->friendlyPositive('OAuth keys are OK'); } /** * @return bool */ private function keysInDatabase(): bool { return OAuthKeys::keysInDatabase(); } /** * @return bool */ private function keysOnDrive(): bool { return OAuthKeys::hasKeyFiles(); } /** * */ private function generateKeys(): void { OAuthKeys::generateKeys(); } /** * */ private function storeKeysInDB(): void { OAuthKeys::storeKeysInDB(); } /** * */ private function restoreKeysFromDB(): bool { return OAuthKeys::restoreKeysFromDB(); } }