Files
firefly-iii/app/Console/Commands/UpgradeFireflyInstructions.php

191 lines
5.4 KiB
PHP
Raw Normal View History

<?php
2016-05-20 11:59:54 +02:00
/**
* UpgradeFireflyInstructions.php
2020-01-23 20:35:02 +01:00
* Copyright (c) 2020 james@firefly-iii.org
2016-05-20 11:59:54 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2016-05-20 11:59:54 +02:00
*/
2018-05-11 10:08:34 +02:00
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
2020-06-06 06:57:44 +02:00
use FireflyIII\Support\System\GeneratesInstallationId;
use FireflyIII\User;
use Illuminate\Console\Command;
2020-09-10 19:16:03 +02:00
use Illuminate\Database\QueryException;
/**
2017-11-15 12:25:49 +01:00
* Class UpgradeFireflyInstructions.
*
* @codeCoverageIgnore
*/
class UpgradeFireflyInstructions extends Command
{
2020-06-06 06:57:44 +02:00
use GeneratesInstallationId;
/**
2016-01-19 13:59:54 +01:00
* The console command description.
*
* @var string
*/
2016-07-15 22:26:08 +02:00
protected $description = 'Instructions in case of upgrade trouble.';
/**
2016-01-19 13:59:54 +01:00
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly:instructions {task}';
/**
* Execute the console command.
*/
2018-07-22 10:05:06 +02:00
public function handle(): int
{
2020-06-06 06:57:44 +02:00
$this->generateInstallationId();
2020-09-10 19:16:03 +02:00
if ('update' === (string)$this->argument('task')) {
$this->updateInstructions();
}
2020-09-10 19:16:03 +02:00
if ('install' === (string)$this->argument('task')) {
$this->installInstructions();
}
2020-03-21 15:43:41 +01:00
2020-05-24 11:24:28 +02:00
// collect system telemetry
2020-05-25 19:40:22 +02:00
$isDocker = true === env('IS_DOCKER', false) ? 'true' : 'false';
2020-05-24 12:17:53 +02:00
app('telemetry')->feature('system.php.version', PHP_VERSION);
app('telemetry')->feature('system.os.version', PHP_OS);
2020-06-06 06:34:43 +02:00
app('telemetry')->feature('system.database.driver', env('DB_CONNECTION', '(unknown)'));
2020-05-25 19:40:22 +02:00
app('telemetry')->feature('system.os.is_docker', $isDocker);
2020-05-24 12:17:53 +02:00
app('telemetry')->feature('system.command.executed', $this->signature);
2020-09-10 19:16:03 +02:00
try {
app('telemetry')->feature('system.users.count', (string)User::count());
} catch (QueryException $e) {
// ignore error.
}
2020-06-06 06:57:44 +02:00
2018-07-22 10:05:06 +02:00
return 0;
}
/**
2017-11-15 12:25:49 +01:00
* Show a nice box.
*
* @param string $text
*/
2018-07-05 21:18:53 +02:00
private function boxed(string $text): void
{
$parts = explode("\n", wordwrap($text));
foreach ($parts as $string) {
2017-01-24 11:49:05 +01:00
$this->line('| ' . sprintf('%-77s', $string) . '|');
}
}
/**
2017-11-15 12:25:49 +01:00
* Show a nice info box.
*
* @param string $text
*/
2018-07-05 21:18:53 +02:00
private function boxedInfo(string $text): void
{
$parts = explode("\n", wordwrap($text));
foreach ($parts as $string) {
2017-01-24 11:49:05 +01:00
$this->info('| ' . sprintf('%-77s', $string) . '|');
}
}
2017-08-15 17:26:43 +02:00
/**
* Render instructions.
*/
2018-07-05 21:18:53 +02:00
private function installInstructions(): void
{
2016-04-26 21:40:15 +02:00
/** @var string $version */
$version = config('firefly.version');
2020-09-10 19:16:03 +02:00
$config = config('upgrade.text.install');
$text = '';
2016-09-14 20:35:45 +02:00
foreach (array_keys($config) as $compare) {
// if string starts with:
2018-07-05 21:18:53 +02:00
if (0 === strpos($version, $compare)) {
2016-09-14 20:35:45 +02:00
$text = $config[$compare];
}
}
2020-03-20 18:05:40 +01:00
$this->showLine();
$this->boxed('');
2017-11-15 12:25:49 +01:00
if (null === $text) {
2017-08-15 17:26:43 +02:00
$this->boxed(sprintf('Thank you for installing Firefly III, v%s!', $version));
$this->boxedInfo('There are no extra installation instructions.');
$this->boxed('Firefly III should be ready for use.');
$this->boxed('');
$this->showLine();
2017-02-17 06:42:36 +01:00
2016-12-27 19:34:05 +01:00
return;
}
$this->boxed(sprintf('Thank you for installing Firefly III, v%s!', $version));
$this->boxedInfo($text);
$this->boxed('');
$this->showLine();
}
2016-12-27 19:34:05 +01:00
2017-02-17 06:42:36 +01:00
/**
2017-11-15 12:25:49 +01:00
* Show a line.
2017-02-17 06:42:36 +01:00
*/
2018-07-05 21:18:53 +02:00
private function showLine(): void
2017-02-17 06:42:36 +01:00
{
$line = '+';
2017-11-15 12:25:49 +01:00
for ($i = 0; $i < 78; ++$i) {
2017-02-17 06:42:36 +01:00
$line .= '-';
}
$line .= '+';
$this->line($line);
}
2017-08-15 17:26:43 +02:00
/**
* Render upgrade instructions.
*/
2018-07-05 21:18:53 +02:00
private function updateInstructions(): void
{
/** @var string $version */
$version = config('firefly.version');
2020-09-10 19:16:03 +02:00
$config = config('upgrade.text.upgrade');
$text = '';
foreach (array_keys($config) as $compare) {
// if string starts with:
2018-07-05 21:18:53 +02:00
if (0 === strpos($version, $compare)) {
$text = $config[$compare];
}
}
2020-03-20 18:05:40 +01:00
$this->showLine();
$this->boxed('');
2017-11-15 12:25:49 +01:00
if (null === $text) {
$this->boxed(sprintf('Thank you for updating to Firefly III, v%s', $version));
$this->boxedInfo('There are no extra upgrade instructions.');
$this->boxed('Firefly III should be ready for use.');
$this->boxed('');
$this->showLine();
2017-02-17 06:42:36 +01:00
return;
}
$this->boxed(sprintf('Thank you for updating to Firefly III, v%s!', $version));
$this->boxedInfo($text);
$this->boxed('');
$this->showLine();
}
}