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

173 lines
4.6 KiB
PHP
Raw Normal View History

<?php
2016-05-20 04:59:54 -05:00
/**
* UpgradeFireflyInstructions.php
2017-10-21 01:40:00 -05:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
2016-05-20 04:59:54 -05:00
*
2017-10-21 01:40:00 -05:00
* This file is part of Firefly III.
*
2017-10-21 01:40:00 -05:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 07:41:58 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2016-05-20 04:59:54 -05:00
*/
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
use Illuminate\Console\Command;
/**
2017-11-15 05:25:49 -06:00
* Class UpgradeFireflyInstructions.
*/
class UpgradeFireflyInstructions extends Command
{
/**
2016-01-19 06:59:54 -06:00
* The console command description.
*
* @var string
*/
2016-07-15 15:26:08 -05:00
protected $description = 'Instructions in case of upgrade trouble.';
/**
2016-01-19 06:59:54 -06:00
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly:instructions {task}';
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
2017-11-15 05:25:49 -06:00
if ('update' === $this->argument('task')) {
$this->updateInstructions();
}
2017-11-15 05:25:49 -06:00
if ('install' === $this->argument('task')) {
$this->installInstructions();
}
}
/**
2017-11-15 05:25:49 -06:00
* Show a nice box.
*
* @param string $text
*/
private function boxed(string $text)
{
$parts = explode("\n", wordwrap($text));
foreach ($parts as $string) {
2017-01-24 04:49:05 -06:00
$this->line('| ' . sprintf('%-77s', $string) . '|');
}
}
/**
2017-11-15 05:25:49 -06:00
* Show a nice info box.
*
* @param string $text
*/
private function boxedInfo(string $text)
{
$parts = explode("\n", wordwrap($text));
foreach ($parts as $string) {
2017-01-24 04:49:05 -06:00
$this->info('| ' . sprintf('%-77s', $string) . '|');
}
}
2017-08-15 10:26:43 -05:00
/**
* Render instructions.
*/
2017-02-16 23:42:36 -06:00
private function installInstructions()
{
2016-04-26 14:40:15 -05:00
/** @var string $version */
$version = config('firefly.version');
$config = config('upgrade.text.install');
$text = '';
2016-09-14 13:35:45 -05:00
foreach (array_keys($config) as $compare) {
// if string starts with:
$len = strlen($compare);
if (substr($version, 0, $len) === $compare) {
$text = $config[$compare];
}
}
$this->showLine();
$this->boxed('');
2017-11-15 05:25:49 -06:00
if (null === $text) {
2017-08-15 10:26:43 -05: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-16 23:42:36 -06:00
2016-12-27 12:34:05 -06:00
return;
}
$this->boxed(sprintf('Thank you for installing Firefly III, v%s!', $version));
$this->boxedInfo($text);
$this->boxed('');
$this->showLine();
}
2016-12-27 12:34:05 -06:00
2017-02-16 23:42:36 -06:00
/**
2017-11-15 05:25:49 -06:00
* Show a line.
2017-02-16 23:42:36 -06:00
*/
private function showLine()
{
$line = '+';
2017-11-15 05:25:49 -06:00
for ($i = 0; $i < 78; ++$i) {
2017-02-16 23:42:36 -06:00
$line .= '-';
}
$line .= '+';
$this->line($line);
}
2017-08-15 10:26:43 -05:00
/**
* Render upgrade instructions.
*/
private function updateInstructions()
{
/** @var string $version */
$version = config('firefly.version');
$config = config('upgrade.text.upgrade');
$text = '';
foreach (array_keys($config) as $compare) {
// if string starts with:
$len = strlen($compare);
if (substr($version, 0, $len) === $compare) {
$text = $config[$compare];
}
}
$this->showLine();
$this->boxed('');
2017-11-15 05:25:49 -06: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-16 23:42:36 -06:00
return;
}
$this->boxed(sprintf('Thank you for updating to Firefly III, v%s!', $version));
$this->boxedInfo($text);
$this->boxed('');
$this->showLine();
}
}