Files
firefly-iii/app/Console/Commands/System/OutputsInstructions.php

237 lines
8.0 KiB
PHP
Raw Normal View History

<?php
2023-04-16 07:33:12 +02:00
/*
2016-05-20 11:59:54 +02:00
* UpgradeFireflyInstructions.php
2023-04-16 07:33:12 +02:00
* Copyright (c) 2023 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);
2023-04-16 07:33:12 +02:00
namespace FireflyIII\Console\Commands\System;
use Carbon\Carbon;
2020-06-06 06:57:44 +02:00
use FireflyIII\Support\System\GeneratesInstallationId;
use Illuminate\Console\Command;
2024-12-27 09:30:41 +01:00
class OutputsInstructions extends Command
{
2020-06-06 06:57:44 +02:00
use GeneratesInstallationId;
2016-07-15 22:26:08 +02:00
protected $description = 'Instructions in case of upgrade trouble.';
2023-11-05 09:54:53 +01:00
2024-12-27 09:30:41 +01:00
protected $signature = 'firefly-iii:instructions {task=install}';
/**
* 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();
2023-11-04 19:06:47 +01:00
if ('update' === $this->argument('task')) {
$this->updateInstructions();
}
2023-11-04 19:06:47 +01:00
if ('install' === $this->argument('task')) {
$this->installInstructions();
}
2020-03-21 15:43:41 +01:00
2018-07-22 10:05:06 +02:00
return 0;
}
/**
2023-06-21 12:34:58 +02:00
* Render upgrade instructions.
2023-05-07 20:17:29 +02:00
*/
2023-06-21 12:34:58 +02:00
private function updateInstructions(): void
{
2024-12-22 08:43:12 +01:00
$version = (string) config('firefly.version');
2023-12-20 19:35:52 +01:00
2023-11-26 12:10:42 +01:00
/** @var array $config */
$config = config('upgrade.text.upgrade');
$text = '';
2023-12-20 19:35:52 +01:00
2023-11-26 12:10:42 +01:00
/** @var string $compare */
2016-09-14 20:35:45 +02:00
foreach (array_keys($config) as $compare) {
// if string starts with:
2023-10-29 06:22:57 +01:00
if (str_starts_with($version, $compare)) {
2024-12-22 08:43:12 +01:00
$text = (string) $config[$compare];
2016-09-14 20:35:45 +02:00
}
}
2023-06-21 12:34:58 +02:00
2024-02-18 11:35:08 +01:00
// validate some settings.
2024-12-22 08:43:12 +01:00
if ('' === $text && 'local' === (string) config('app.env')) {
2024-02-18 11:35:08 +01:00
$text = 'Please set APP_ENV=production for a safer environment.';
}
$prefix = 'v';
2024-12-27 09:30:41 +01:00
if (str_starts_with($version, 'develop') || str_starts_with($version, 'branch')) {
2024-02-18 11:35:08 +01:00
$prefix = '';
}
2023-06-04 06:58:35 +02:00
$this->newLine();
$this->showLogo();
$this->newLine();
$this->showLine();
2023-06-21 12:34:58 +02:00
$this->boxed('');
2023-11-26 12:10:42 +01:00
if ('' === $text) {
2024-02-18 11:35:08 +01:00
$this->boxed(sprintf('Thank you for updating to Firefly III, %s%s', $prefix, $version));
2023-06-21 12:34:58 +02:00
$this->boxedInfo('There are no extra upgrade instructions.');
$this->boxed('Firefly III should be ready for use.');
$this->boxed('');
2024-12-27 09:30:41 +01:00
$this->donationText();
$this->boxed('');
$this->showLine();
2017-02-17 06:42:36 +01:00
2016-12-27 19:34:05 +01:00
return;
}
2024-02-18 11:35:08 +01:00
$this->boxed(sprintf('Thank you for updating to Firefly III, %s%s!', $prefix, $version));
$this->boxedInfo($text);
$this->boxed('');
2024-12-27 09:30:41 +01:00
$this->donationText();
$this->boxed('');
$this->showLine();
}
2016-12-27 19:34:05 +01:00
2023-06-04 06:58:35 +02:00
/**
* The logo takes up 8 lines of code. So 8 colors can be used.
*/
private function showLogo(): void
{
$today = Carbon::now()->format('m-d');
$month = Carbon::now()->format('m');
2023-06-04 06:58:35 +02:00
// variation in colors and effects just because I can!
// default is Ukraine flag:
$colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default'];
// 5th of May is Dutch liberation day and 29th of April is Dutch King's Day and September 17 is my birthday.
if ('05-01' === $today || '04-29' === $today || '09-17' === $today) {
$colors = ['red', 'red', 'red', 'white', 'white', 'blue', 'blue', 'blue'];
}
// National Coming Out Day, International Day Against Homophobia, Biphobia and Transphobia and Pride Month
if ('10-11' === $today || '05-17' === $today || '06' === $month) {
$colors = ['red', 'bright-red', 'yellow', 'green', 'blue', 'magenta', 'default', 'default'];
}
// International Transgender Day of Visibility
if ('03-31' === $today) {
$colors = ['bright-blue', 'bright-red', 'white', 'white', 'bright-red', 'bright-blue', 'default', 'default'];
}
2023-06-06 12:42:20 +02:00
$this->line(sprintf('<fg=%s> ______ _ __ _ _____ _____ _____ </>', $colors[0]));
$this->line(sprintf('<fg=%s> | ____(_) / _| | |_ _|_ _|_ _| </>', $colors[1]));
$this->line(sprintf('<fg=%s> | |__ _ _ __ ___| |_| |_ _ | | | | | | </>', $colors[2]));
$this->line(sprintf('<fg=%s> | __| | | \'__/ _ \ _| | | | | | | | | | | </>', $colors[3]));
$this->line(sprintf('<fg=%s> | | | | | | __/ | | | |_| | _| |_ _| |_ _| |_ </>', $colors[4]));
$this->line(sprintf('<fg=%s> |_| |_|_| \___|_| |_|\__, | |_____|_____|_____| </>', $colors[5]));
$this->line(sprintf('<fg=%s> __/ | </>', $colors[6]));
$this->line(sprintf('<fg=%s> |___/ </>', $colors[7]));
2023-06-04 06:58:35 +02:00
}
2017-08-15 17:26:43 +02:00
/**
2023-06-21 12:34:58 +02:00
* Show a line.
2021-03-21 09:15:40 +01:00
*/
2023-06-21 12:34:58 +02:00
private function showLine(): void
{
2025-05-04 12:20:54 +02:00
$this->line(sprintf('+%s+', str_repeat('-', 78)));
2023-06-21 12:34:58 +02:00
}
/**
* Show a nice box.
*/
private function boxed(string $text): void
{
$parts = explode("\n", wordwrap($text));
foreach ($parts as $string) {
2023-12-20 19:35:52 +01:00
$this->line('| '.sprintf('%-77s', $string).'|');
2023-06-21 12:34:58 +02:00
}
}
/**
* Show a nice info box.
*/
private function boxedInfo(string $text): void
{
$parts = explode("\n", wordwrap($text));
foreach ($parts as $string) {
2023-12-20 19:35:52 +01:00
$this->info('| '.sprintf('%-77s', $string).'|');
2023-06-21 12:34:58 +02:00
}
}
2025-05-04 17:41:26 +02:00
private function donationText(): void
{
$this->boxed('Did you know you can support the development of Firefly III?');
$this->boxed('You can donate in many ways, like GitHub Sponsors or Patreon.');
$this->boxed('For more information, please visit https://bit.ly/donate-to-Firefly-III');
}
2023-06-21 12:34:58 +02:00
/**
* Render instructions.
*/
private function installInstructions(): void
{
2024-12-22 08:43:12 +01:00
$version = (string) config('firefly.version');
2023-12-20 19:35:52 +01:00
2023-11-26 12:10:42 +01:00
/** @var array $config */
$config = config('upgrade.text.install');
$text = '';
2023-12-20 19:35:52 +01:00
2023-11-26 12:10:42 +01:00
/** @var string $compare */
foreach (array_keys($config) as $compare) {
// if string starts with:
2023-10-29 06:22:57 +01:00
if (str_starts_with($version, $compare)) {
2024-12-22 08:43:12 +01:00
$text = (string) $config[$compare];
}
}
2024-02-18 11:35:08 +01:00
// validate some settings.
2024-12-22 08:43:12 +01:00
if ('' === $text && 'local' === (string) config('app.env')) {
2024-02-18 11:35:08 +01:00
$text = 'Please set APP_ENV=production for a safer environment.';
}
$prefix = 'v';
if (str_starts_with($version, 'develop')) {
2024-02-18 11:35:08 +01:00
$prefix = '';
}
2023-06-04 06:58:35 +02:00
$this->newLine();
$this->showLogo();
$this->newLine();
$this->showLine();
$this->boxed('');
2023-11-26 12:10:42 +01:00
if ('' === $text) {
2024-02-18 11:35:08 +01:00
$this->boxed(sprintf('Thank you for installing Firefly III, %s%s!', $prefix, $version));
2023-06-21 12:34:58 +02:00
$this->boxedInfo('There are no extra installation instructions.');
$this->boxed('Firefly III should be ready for use.');
$this->boxed('');
2024-12-27 09:30:41 +01:00
$this->donationText();
$this->boxed('');
$this->showLine();
2017-02-17 06:42:36 +01:00
return;
}
2024-02-18 11:35:08 +01:00
$this->boxed(sprintf('Thank you for installing Firefly III, %s%s!', $prefix, $version));
$this->boxedInfo($text);
$this->boxed('');
2024-12-27 09:30:41 +01:00
$this->donationText();
$this->boxed('');
$this->showLine();
}
}