maj grav
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Console\Cli;
|
||||
|
||||
use Grav\Common\Backup\Backups;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Backup\ZipBackup;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
use RocketTheme\Toolbox\File\JsonFile;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class BackupCommand extends ConsoleCommand
|
||||
{
|
||||
@@ -23,61 +25,89 @@ class BackupCommand extends ConsoleCommand
|
||||
/** @var ProgressBar $progress */
|
||||
protected $progress;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("backup")
|
||||
->setName('backup')
|
||||
->addArgument(
|
||||
'destination',
|
||||
'id',
|
||||
InputArgument::OPTIONAL,
|
||||
'Where to store the backup (/backup is default)'
|
||||
'The ID of the backup profile to perform without prompting'
|
||||
|
||||
)
|
||||
->setDescription("Creates a backup of the Grav instance")
|
||||
->setHelp('The <info>backup</info> creates a zipped backup. Optionally can be saved in a different destination.');
|
||||
->setDescription('Creates a backup of the Grav instance')
|
||||
->setHelp('The <info>backup</info> creates a zipped backup.');
|
||||
|
||||
$this->source = getcwd();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$this->progress = new ProgressBar($this->output);
|
||||
$this->progress->setFormat('Archiving <cyan>%current%</cyan> files [<green>%bar%</green>] %elapsed:6s% %memory:6s%');
|
||||
$this->progress->setFormat('Archiving <cyan>%current%</cyan> files [<green>%bar%</green>] <white>%percent:3s%%</white> %elapsed:6s% <yellow>%message%</yellow>');
|
||||
$this->progress->setBarWidth(100);
|
||||
|
||||
Grav::instance()['config']->init();
|
||||
|
||||
$destination = ($this->input->getArgument('destination')) ? $this->input->getArgument('destination') : null;
|
||||
$log = JsonFile::instance(Grav::instance()['locator']->findResource("log://backup.log", true, true));
|
||||
$backup = ZipBackup::backup($destination, [$this, 'output']);
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
$io->title('Grav Backup');
|
||||
|
||||
$log->content([
|
||||
'time' => time(),
|
||||
'location' => $backup
|
||||
]);
|
||||
$log->save();
|
||||
/** @var Backups $backups */
|
||||
$backups = Grav::instance()['backups'];
|
||||
$backups_list = $backups->getBackupProfiles();
|
||||
$backups_names = $backups->getBackupNames();
|
||||
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln('');
|
||||
$id = null;
|
||||
|
||||
$inline_id = $this->input->getArgument('id');
|
||||
if (null !== $inline_id && is_numeric($inline_id)) {
|
||||
$id = $inline_id;
|
||||
}
|
||||
|
||||
if (null === $id) {
|
||||
if (\count($backups_list) > 1) {
|
||||
$helper = $this->getHelper('question');
|
||||
$question = new ChoiceQuestion(
|
||||
'Choose a backup?',
|
||||
$backups_names,
|
||||
0
|
||||
);
|
||||
$question->setErrorMessage('Option %s is invalid.');
|
||||
$backup_name = $helper->ask($this->input, $this->output, $question);
|
||||
$id = array_search($backup_name, $backups_names, true);
|
||||
|
||||
$io->newLine();
|
||||
$io->note('Selected backup: ' . $backup_name);
|
||||
} else {
|
||||
$id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$backup = $backups->backup($id, [$this, 'outputProgress']);
|
||||
|
||||
$io->newline(2);
|
||||
$io->success('Backup Successfully Created: ' . $backup);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $args
|
||||
* @param array $args
|
||||
*/
|
||||
public function output($args)
|
||||
public function outputProgress($args)
|
||||
{
|
||||
switch ($args['type']) {
|
||||
case 'count':
|
||||
$steps = $args['steps'];
|
||||
$freq = (int)($steps > 100 ? round($steps / 100) : $steps);
|
||||
$this->progress->setMaxSteps($steps);
|
||||
$this->progress->setRedrawFrequency($freq);
|
||||
$this->progress->setMessage('Adding files...');
|
||||
break;
|
||||
case 'message':
|
||||
$this->output->writeln($args['message']);
|
||||
$this->progress->setMessage($args['message']);
|
||||
$this->progress->display();
|
||||
break;
|
||||
case 'progress':
|
||||
if ($args['complete']) {
|
||||
if (isset($args['complete']) && $args['complete']) {
|
||||
$this->progress->finish();
|
||||
} else {
|
||||
$this->progress->advance();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -22,9 +23,7 @@ class CleanCommand extends Command
|
||||
/* @var OutputInterface $output */
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var array */
|
||||
protected $paths_to_remove = [
|
||||
'codeception.yml',
|
||||
'tests/',
|
||||
@@ -75,11 +74,15 @@ class CleanCommand extends Command
|
||||
'vendor/doctrine/collections/tests',
|
||||
'vendor/donatj/phpuseragentparser/.git',
|
||||
'vendor/donatj/phpuseragentparser/.gitignore',
|
||||
'vendor/donatj/phpuseragentparser/.editorconfig',
|
||||
'vendor/donatj/phpuseragentparser/.travis.yml',
|
||||
'vendor/donatj/phpuseragentparser/composer.json',
|
||||
'vendor/donatj/phpuseragentparser/phpunit.xml.dist',
|
||||
'vendor/donatj/phpuseragentparser/Tests',
|
||||
'vendor/donatj/phpuseragentparser/Tools',
|
||||
'vendor/dragonmantank/cron-expression/.editorconfig',
|
||||
'vendor/dragonmantank/cron-expression/composer.json',
|
||||
'vendor/dragonmantank/cron-expression/tests',
|
||||
'vendor/erusev/parsedown/composer.json',
|
||||
'vendor/erusev/parsedown/phpunit.xml.dist',
|
||||
'vendor/erusev/parsedown/.travis.yml',
|
||||
@@ -101,6 +104,12 @@ class CleanCommand extends Command
|
||||
'vendor/filp/whoops/phpunit.xml.dist',
|
||||
'vendor/gregwar/image/Gregwar/Image/composer.json',
|
||||
'vendor/gregwar/image/Gregwar/Image/phpunit.xml',
|
||||
'vendor/gregwar/image/Gregwar/Image/phpunit.xml.dist',
|
||||
'vendor/gregwar/image/Gregwar/Image/Makefile',
|
||||
'vendor/gregwar/image/Gregwar/Image/.editorconfig',
|
||||
'vendor/gregwar/image/Gregwar/Image/.php_cs',
|
||||
'vendor/gregwar/image/Gregwar/Image/.styleci.yml',
|
||||
'vendor/gregwar/image/Gregwar/Image/.travis.yml',
|
||||
'vendor/gregwar/image/Gregwar/Image/.gitignore',
|
||||
'vendor/gregwar/image/Gregwar/Image/.git',
|
||||
'vendor/gregwar/image/Gregwar/Image/doc',
|
||||
@@ -108,19 +117,24 @@ class CleanCommand extends Command
|
||||
'vendor/gregwar/image/Gregwar/Image/tests',
|
||||
'vendor/gregwar/cache/Gregwar/Cache/composer.json',
|
||||
'vendor/gregwar/cache/Gregwar/Cache/phpunit.xml',
|
||||
'vendor/gregwar/cache/Gregwar/Cache/.travis.yml',
|
||||
'vendor/gregwar/cache/Gregwar/Cache/.gitignore',
|
||||
'vendor/gregwar/cache/Gregwar/Cache/.git',
|
||||
'vendor/gregwar/cache/Gregwar/Cache/demo',
|
||||
'vendor/gregwar/cache/Gregwar/Cache/tests',
|
||||
'vendor/guzzlehttp/psr7/composer.json',
|
||||
'vendor/guzzlehttp/psr7/.editorconfig',
|
||||
'vendor/kodus/psr7-server/composer.json',
|
||||
'vendor/ircmaxell/password-compat/composer.json',
|
||||
'vendor/ircmaxell/password-compat/phpunit.xml.dist',
|
||||
'vendor/ircmaxell/password-compat/version-test.php',
|
||||
'vendor/ircmaxell/password-compat/.travis.yml',
|
||||
'vendor/ircmaxell/password-compat/test',
|
||||
'vendor/league/climate/composer.json',
|
||||
'vendor/league/climate/CODE_OF_CONDUCT.md',
|
||||
'vendor/matthiasmullie/minify/bin',
|
||||
'vendor/matthiasmullie/minify/composer.json',
|
||||
'vendor/matthiasmullie/minify/docker-composer.yml',
|
||||
'vendor/matthiasmullie/minify/docker-compose.yml',
|
||||
'vendor/matthiasmullie/minify/Dockerfile',
|
||||
'vendor/matthiasmullie/minify/CONTRIBUTING.md',
|
||||
'vendor/matthiasmullie/path-converter/composer.json',
|
||||
@@ -145,6 +159,15 @@ class CleanCommand extends Command
|
||||
'vendor/monolog/monolog/phpunit.xml.dist',
|
||||
'vendor/monolog/monolog/.php_cs',
|
||||
'vendor/monolog/monolog/tests',
|
||||
'vendor/nyholm/psr7/composer.json',
|
||||
'vendor/nyholm/psr7/phpstan.neon.dist',
|
||||
'vendor/phive/twig-extensions-deferred/.gitignore',
|
||||
'vendor/phive/twig-extensions-deferred/.travis.yml',
|
||||
'vendor/phive/twig-extensions-deferred/composer.json',
|
||||
'vendor/phive/twig-extensions-deferred/phpunit.xml.dist',
|
||||
'vendor/phive/twig-extensions-deferred/tests',
|
||||
'vendor/php-http/message-factory/composer.json',
|
||||
'vendor/php-http/message-factory/puli.json',
|
||||
'vendor/pimple/pimple/.gitignore',
|
||||
'vendor/pimple/pimple/.travis.yml',
|
||||
'vendor/pimple/pimple/composer.json',
|
||||
@@ -153,9 +176,21 @@ class CleanCommand extends Command
|
||||
'vendor/pimple/pimple/src/Pimple/Tests',
|
||||
'vendor/psr/container/composer.json',
|
||||
'vendor/psr/container/.gitignore',
|
||||
'vendor/psr/http-factory/.gitignore',
|
||||
'vendor/psr/http-factory/.pullapprove.yml',
|
||||
'vendor/psr/http-factory/composer.json',
|
||||
'vendor/psr/http-message/composer.json',
|
||||
'vendor/psr/http-server-handler/composer.json',
|
||||
'vendor/psr/http-server-middleware/composer.json',
|
||||
'vendor/psr/simple-cache/.editorconfig',
|
||||
'vendor/psr/simple-cache/composer.json',
|
||||
'vendor/psr/log/composer.json',
|
||||
'vendor/psr/log/.gitignore',
|
||||
'vendor/ralouphie/getallheaders/.gitignore',
|
||||
'vendor/ralouphie/getallheaders/.travis.yml',
|
||||
'vendor/ralouphie/getallheaders/composer.json',
|
||||
'vendor/ralouphie/getallheaders/phpunit.xml',
|
||||
'vendor/ralouphie/getallheaders/tests/',
|
||||
'vendor/rockettheme/toolbox/.git',
|
||||
'vendor/rockettheme/toolbox/.gitignore',
|
||||
'vendor/rockettheme/toolbox/.scrutinizer.yml',
|
||||
@@ -181,12 +216,19 @@ class CleanCommand extends Command
|
||||
'vendor/symfony/event-dispatcher/composer.json',
|
||||
'vendor/symfony/event-dispatcher/phpunit.xml.dist',
|
||||
'vendor/symfony/event-dispatcher/Tests',
|
||||
'vendor/symfony/polyfill-ctype/composer.json',
|
||||
'vendor/symfony/polyfill-iconv/.git',
|
||||
'vendor/symfony/polyfill-iconv/.gitignore',
|
||||
'vendor/symfony/polyfill-iconv/composer.json',
|
||||
'vendor/symfony/polyfill-mbstring/.git',
|
||||
'vendor/symfony/polyfill-mbstring/.gitignore',
|
||||
'vendor/symfony/polyfill-mbstring/composer.json',
|
||||
'vendor/symfony/polyfill-php72/composer.json',
|
||||
'vendor/symfony/polyfill-php73/composer.json',
|
||||
'vendor/symfony/process/.gitignore',
|
||||
'vendor/symfony/process/composer.json',
|
||||
'vendor/symfony/process/phpunit.xml.dist',
|
||||
'vendor/symfony/process/Tests',
|
||||
'vendor/symfony/var-dumper/.git',
|
||||
'vendor/symfony/var-dumper/.gitignore',
|
||||
'vendor/symfony/var-dumper/composer.json',
|
||||
@@ -208,24 +250,27 @@ class CleanCommand extends Command
|
||||
'vendor/twig/twig/doc',
|
||||
'vendor/twig/twig/ext',
|
||||
'vendor/twig/twig/test',
|
||||
'vendor/willdurand/negotiation/.gitignore',
|
||||
'vendor/willdurand/negotiation/.travis.yml',
|
||||
'vendor/willdurand/negotiation/appveyor.yml',
|
||||
'vendor/willdurand/negotiation/composer.json',
|
||||
'vendor/willdurand/negotiation/phpunit.xml.dist',
|
||||
'vendor/willdurand/negotiation/tests',
|
||||
'user/config/security.yaml',
|
||||
'cache/compiled/',
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("clean")
|
||||
->setDescription("Handles cleaning chores for Grav distribution")
|
||||
->setName('clean')
|
||||
->setDescription('Handles cleaning chores for Grav distribution')
|
||||
->setHelp('The <info>clean</info> clean extraneous folders and data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -14,26 +15,23 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ClearCacheCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('clear-cache')
|
||||
->setAliases(['clearcache'])
|
||||
->setName('cache')
|
||||
->setAliases(['clearcache', 'cache-clear'])
|
||||
->setDescription('Clears Grav cache')
|
||||
->addOption('invalidate', null, InputOption::VALUE_NONE, 'Invalidate cache, but do not remove any files')
|
||||
->addOption('purge', null, InputOption::VALUE_NONE, 'If set purge old caches')
|
||||
->addOption('all', null, InputOption::VALUE_NONE, 'If set will remove all including compiled, twig, doctrine caches')
|
||||
->addOption('assets-only', null, InputOption::VALUE_NONE, 'If set will remove only assets/*')
|
||||
->addOption('images-only', null, InputOption::VALUE_NONE, 'If set will remove only images/*')
|
||||
->addOption('cache-only', null, InputOption::VALUE_NONE, 'If set will remove only cache/*')
|
||||
->addOption('tmp-only', null, InputOption::VALUE_NONE, 'If set will remove only tmp/*')
|
||||
->setHelp('The <info>clear-cache</info> deletes all cache files');
|
||||
|
||||
->setHelp('The <info>cache</info> command allows you to interact with Grav cache');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$this->cleanPaths();
|
||||
@@ -45,25 +43,37 @@ class ClearCacheCommand extends ConsoleCommand
|
||||
private function cleanPaths()
|
||||
{
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln('<magenta>Clearing cache</magenta>');
|
||||
$this->output->writeln('');
|
||||
|
||||
if ($this->input->getOption('all')) {
|
||||
$remove = 'all';
|
||||
} elseif ($this->input->getOption('assets-only')) {
|
||||
$remove = 'assets-only';
|
||||
} elseif ($this->input->getOption('images-only')) {
|
||||
$remove = 'images-only';
|
||||
} elseif ($this->input->getOption('cache-only')) {
|
||||
$remove = 'cache-only';
|
||||
} elseif ($this->input->getOption('tmp-only')) {
|
||||
$remove = 'tmp-only';
|
||||
|
||||
if ($this->input->getOption('purge')) {
|
||||
$this->output->writeln('<magenta>Purging old cache</magenta>');
|
||||
$this->output->writeln('');
|
||||
|
||||
$msg = Cache::purgeJob();
|
||||
$this->output->writeln($msg);
|
||||
} else {
|
||||
$remove = 'standard';
|
||||
}
|
||||
$this->output->writeln('<magenta>Clearing cache</magenta>');
|
||||
$this->output->writeln('');
|
||||
|
||||
foreach (Cache::clearCache($remove) as $result) {
|
||||
$this->output->writeln($result);
|
||||
if ($this->input->getOption('all')) {
|
||||
$remove = 'all';
|
||||
} elseif ($this->input->getOption('assets-only')) {
|
||||
$remove = 'assets-only';
|
||||
} elseif ($this->input->getOption('images-only')) {
|
||||
$remove = 'images-only';
|
||||
} elseif ($this->input->getOption('cache-only')) {
|
||||
$remove = 'cache-only';
|
||||
} elseif ($this->input->getOption('tmp-only')) {
|
||||
$remove = 'tmp-only';
|
||||
} elseif ($this->input->getOption('invalidate')) {
|
||||
$remove = 'invalidate';
|
||||
} else {
|
||||
$remove = 'standard';
|
||||
}
|
||||
|
||||
foreach (Cache::clearCache($remove) as $result) {
|
||||
$this->output->writeln($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -13,26 +14,6 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ComposerCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $config;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $local_config;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $destination;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $user_path;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -53,9 +34,6 @@ class ComposerCommand extends ConsoleCommand
|
||||
->setHelp('The <info>composer</info> command updates the composer vendor dependencies needed by Grav');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$action = $this->input->getOption('install') ? 'install' : ($this->input->getOption('update') ? 'update' : 'install');
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -15,30 +16,22 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InstallCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
/** @var array */
|
||||
protected $config;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var array */
|
||||
protected $local_config;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
protected $destination;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
protected $user_path;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("install")
|
||||
->setName('install')
|
||||
->addOption(
|
||||
'symlink',
|
||||
's',
|
||||
@@ -50,17 +43,14 @@ class InstallCommand extends ConsoleCommand
|
||||
InputArgument::OPTIONAL,
|
||||
'Where to install the required bits (default to current project)'
|
||||
)
|
||||
->setDescription("Installs the dependencies needed by Grav. Optionally can create symbolic links")
|
||||
->setDescription('Installs the dependencies needed by Grav. Optionally can create symbolic links')
|
||||
->setHelp('The <info>install</info> command installs the dependencies needed by Grav. Optionally can create symbolic links');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$dependencies_file = '.dependencies';
|
||||
$this->destination = ($this->input->getArgument('destination')) ? $this->input->getArgument('destination') : ROOT_DIR;
|
||||
$this->destination = $this->input->getArgument('destination') ?: ROOT_DIR;
|
||||
|
||||
// fix trailing slash
|
||||
$this->destination = rtrim($this->destination, DS) . DS;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Console\Cli;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Helpers\LogViewer;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class LogViewerCommand extends ConsoleCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('logviewer')
|
||||
->addOption(
|
||||
'file',
|
||||
'f',
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'custom log file location (default = grav.log)'
|
||||
)
|
||||
->addOption(
|
||||
'lines',
|
||||
'l',
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'number of lines (default = 10)'
|
||||
)
|
||||
->setDescription('Display the last few entries of Grav log')
|
||||
->setHelp("Display the last few entries of Grav log");
|
||||
}
|
||||
|
||||
protected function serve()
|
||||
{
|
||||
$grav = Grav::instance();
|
||||
$grav->setup();
|
||||
|
||||
$file = $this->input->getOption('file') ?? 'grav.log';
|
||||
$lines = $this->input->getOption('lines') ?? 20;
|
||||
$verbose = $this->input->getOption('verbose', false);
|
||||
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
|
||||
$io->title('Log Viewer');
|
||||
|
||||
$io->writeln(sprintf('viewing last %s entries in <white>%s</white>', $lines, $file));
|
||||
$io->newLine();
|
||||
|
||||
$viewer = new LogViewer();
|
||||
|
||||
$logfile = $grav['locator']->findResource("log://" . $file);
|
||||
|
||||
if ($logfile) {
|
||||
$rows = $viewer->objectTail($logfile, $lines, true);
|
||||
foreach ($rows as $log) {
|
||||
$date = $log['date'];
|
||||
$level_color = LogViewer::levelColor($log['level']);
|
||||
|
||||
if ($date instanceof \DateTime) {
|
||||
$output = "<yellow>{$log['date']->format('Y-m-d h:i:s')}</yellow> [<{$level_color}>{$log['level']}</{$level_color}>]";
|
||||
if ($log['trace'] && $verbose) {
|
||||
$output .= " <white>{$log['message']}</white>\n";
|
||||
foreach ((array) $log['trace'] as $index => $tracerow) {
|
||||
$output .= "<white>{$index}</white>${tracerow}\n";
|
||||
}
|
||||
} else {
|
||||
$output .= " {$log['message']}";
|
||||
}
|
||||
$io->writeln($output);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$io->error('cannot find the log file: logs/' . $file);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -15,9 +16,6 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class NewProjectCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -38,9 +36,6 @@ class NewProjectCommand extends ConsoleCommand
|
||||
->setHelp("The <info>new-project</info> command is a combination of the `setup` and `install` commands.\nCreates a new Grav instance and performs the installation of all the required dependencies.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$sandboxCommand = $this->getApplication()->find('sandbox');
|
||||
@@ -60,6 +55,5 @@ class NewProjectCommand extends ConsoleCommand
|
||||
|
||||
$sandboxCommand->run($sandboxArguments, $this->output);
|
||||
$installCommand->run($installArguments, $this->output);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -15,9 +16,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class SandboxCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var array */
|
||||
protected $directories = [
|
||||
'/assets',
|
||||
'/backup',
|
||||
@@ -33,9 +32,7 @@ class SandboxCommand extends ConsoleCommand
|
||||
'/user/themes',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var array */
|
||||
protected $files = [
|
||||
'/.dependencies',
|
||||
'/.htaccess',
|
||||
@@ -43,11 +40,10 @@ class SandboxCommand extends ConsoleCommand
|
||||
'/user/config/system.yaml',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var array */
|
||||
protected $mappings = [
|
||||
'/.gitignore' => '/.gitignore',
|
||||
'/.editorconfig' => '/.editorconfig',
|
||||
'/CHANGELOG.md' => '/CHANGELOG.md',
|
||||
'/LICENSE.txt' => '/LICENSE.txt',
|
||||
'/README.md' => '/README.md',
|
||||
@@ -60,18 +56,12 @@ class SandboxCommand extends ConsoleCommand
|
||||
'/webserver-configs' => '/webserver-configs',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
protected $default_file = "---\ntitle: HomePage\n---\n# HomePage\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque porttitor eu felis sed ornare. Sed a mauris venenatis, pulvinar velit vel, dictum enim. Phasellus ac rutrum velit. Nunc lorem purus, hendrerit sit amet augue aliquet, iaculis ultricies nisl. Suspendisse tincidunt euismod risus, quis feugiat arcu tincidunt eget. Nulla eros mi, commodo vel ipsum vel, aliquet congue odio. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque velit orci, laoreet at adipiscing eu, interdum quis nibh. Nunc a accumsan purus.";
|
||||
|
||||
protected $source;
|
||||
protected $destination;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -92,9 +82,6 @@ class SandboxCommand extends ConsoleCommand
|
||||
$this->source = getcwd();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$this->destination = $this->input->getArgument('destination');
|
||||
@@ -121,9 +108,6 @@ class SandboxCommand extends ConsoleCommand
|
||||
$this->perms();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function createDirectories()
|
||||
{
|
||||
$this->output->writeln('');
|
||||
@@ -131,14 +115,14 @@ class SandboxCommand extends ConsoleCommand
|
||||
$dirs_created = false;
|
||||
|
||||
if (!file_exists($this->destination)) {
|
||||
mkdir($this->destination, 0777, true);
|
||||
Folder::create($this->destination);
|
||||
}
|
||||
|
||||
foreach ($this->directories as $dir) {
|
||||
if (!file_exists($this->destination . $dir)) {
|
||||
$dirs_created = true;
|
||||
$this->output->writeln(' <cyan>' . $dir . '</cyan>');
|
||||
mkdir($this->destination . $dir, 0777, true);
|
||||
Folder::create($this->destination . $dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,9 +131,6 @@ class SandboxCommand extends ConsoleCommand
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function copy()
|
||||
{
|
||||
$this->output->writeln('');
|
||||
@@ -157,7 +138,7 @@ class SandboxCommand extends ConsoleCommand
|
||||
|
||||
|
||||
foreach ($this->mappings as $source => $target) {
|
||||
if ((int)$source == $source) {
|
||||
if ((string)(int)$source === (string)$source) {
|
||||
$source = $target;
|
||||
}
|
||||
|
||||
@@ -169,9 +150,6 @@ class SandboxCommand extends ConsoleCommand
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function symlink()
|
||||
{
|
||||
$this->output->writeln('');
|
||||
@@ -179,7 +157,7 @@ class SandboxCommand extends ConsoleCommand
|
||||
|
||||
|
||||
foreach ($this->mappings as $source => $target) {
|
||||
if ((int)$source == $source) {
|
||||
if ((string)(int)$source === (string)$source) {
|
||||
$source = $target;
|
||||
}
|
||||
|
||||
@@ -197,9 +175,6 @@ class SandboxCommand extends ConsoleCommand
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function initFiles()
|
||||
{
|
||||
$this->check();
|
||||
@@ -210,7 +185,7 @@ class SandboxCommand extends ConsoleCommand
|
||||
|
||||
// Copy files if they do not exist
|
||||
foreach ($this->files as $source => $target) {
|
||||
if ((int)$source == $source) {
|
||||
if ((string)(int)$source === (string)$source) {
|
||||
$source = $target;
|
||||
}
|
||||
|
||||
@@ -229,9 +204,6 @@ class SandboxCommand extends ConsoleCommand
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function pages()
|
||||
{
|
||||
$this->output->writeln('');
|
||||
@@ -241,7 +213,7 @@ class SandboxCommand extends ConsoleCommand
|
||||
$pages_dir = $this->destination . '/user/pages';
|
||||
$pages_files = array_diff(scandir($pages_dir), ['..', '.']);
|
||||
|
||||
if (count($pages_files) == 0) {
|
||||
if (\count($pages_files) === 0) {
|
||||
$destination = $this->source . '/user/pages';
|
||||
Folder::rcopy($destination, $pages_dir);
|
||||
$this->output->writeln(' <cyan>' . $destination . '</cyan> <comment>-></comment> Created');
|
||||
@@ -249,9 +221,6 @@ class SandboxCommand extends ConsoleCommand
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function perms()
|
||||
{
|
||||
$this->output->writeln('');
|
||||
@@ -269,9 +238,6 @@ class SandboxCommand extends ConsoleCommand
|
||||
$this->output->writeln("");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function check()
|
||||
{
|
||||
$success = true;
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Console\Cli;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\Scheduler\Scheduler;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SchedulerCommand extends ConsoleCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('scheduler')
|
||||
->addOption(
|
||||
'install',
|
||||
'i',
|
||||
InputOption::VALUE_NONE,
|
||||
'Show Install Command'
|
||||
)
|
||||
->addOption(
|
||||
'jobs',
|
||||
'j',
|
||||
InputOption::VALUE_NONE,
|
||||
'Show Jobs Summary'
|
||||
)
|
||||
->addOption(
|
||||
'details',
|
||||
'd',
|
||||
InputOption::VALUE_NONE,
|
||||
'Show Job Details'
|
||||
)
|
||||
->setDescription('Run the Grav Scheduler. Best when integrated with system cron')
|
||||
->setHelp("Running without any options will force the Scheduler to run through it's jobs and process them");
|
||||
}
|
||||
|
||||
protected function serve()
|
||||
{
|
||||
// error_reporting(1);
|
||||
$grav = Grav::instance();
|
||||
$grav->setup();
|
||||
|
||||
$grav['uri']->init();
|
||||
$grav['config']->init();
|
||||
$grav['plugins']->init();
|
||||
$grav['themes']->init();
|
||||
$grav['backups']->init();
|
||||
|
||||
// Initialize Plugins
|
||||
$grav->fireEvent('onPluginsInitialized');
|
||||
|
||||
/** @var Scheduler $scheduler */
|
||||
$scheduler = $grav['scheduler'];
|
||||
$grav->fireEvent('onSchedulerInitialized', new Event(['scheduler' => $scheduler]));
|
||||
|
||||
$this->setHelp('foo');
|
||||
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
|
||||
if ($this->input->getOption('jobs')) {
|
||||
// Show jobs list
|
||||
|
||||
$jobs = $scheduler->getAllJobs();
|
||||
$job_states = $scheduler->getJobStates()->content();
|
||||
$rows = [];
|
||||
|
||||
$table = new Table($this->output);
|
||||
$table->setStyle('box');
|
||||
$headers = ['Job ID', 'Command', 'Run At', 'Status', 'Last Run', 'State'];
|
||||
|
||||
$io->title('Scheduler Jobs Listing');
|
||||
|
||||
foreach ($jobs as $job) {
|
||||
$job_status = ucfirst($job_states[$job->getId()]['state'] ?? 'ready');
|
||||
$last_run = $job_states[$job->getId()]['last-run'] ?? 0;
|
||||
$status = $job_status === 'Failure' ? "<red>{$job_status}</red>" : "<green>{$job_status}</green>";
|
||||
$state = $job->getEnabled() ? '<cyan>Enabled</cyan>' : '<red>Disabled</red>';
|
||||
$row = [
|
||||
$job->getId(),
|
||||
"<white>{$job->getCommand()}</white>",
|
||||
"<magenta>{$job->getAt()}</magenta>",
|
||||
$status,
|
||||
'<yellow>' . ($last_run === 0 ? 'Never' : date('Y-m-d H:i', $last_run)) . '</yellow>',
|
||||
$state,
|
||||
|
||||
];
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
if (!empty($rows)) {
|
||||
$table->setHeaders($headers);
|
||||
$table->setRows($rows);
|
||||
$table->render();
|
||||
} else {
|
||||
$io->text('no jobs found...');
|
||||
}
|
||||
|
||||
$io->newLine();
|
||||
$io->note('For error details run "bin/grav scheduler -d"');
|
||||
$io->newLine();
|
||||
} elseif ($this->input->getOption('details')) {
|
||||
$jobs = $scheduler->getAllJobs();
|
||||
$job_states = $scheduler->getJobStates()->content();
|
||||
|
||||
$io->title('Job Details');
|
||||
|
||||
$table = new Table($this->output);
|
||||
$table->setStyle('box');
|
||||
$table->setHeaders(['Job ID', 'Last Run', 'Next Run', 'Errors']);
|
||||
$rows = [];
|
||||
|
||||
foreach ($jobs as $job) {
|
||||
$job_state = $job_states[$job->getId()];
|
||||
$error = isset($job_state['error']) ? trim($job_state['error']) : false;
|
||||
|
||||
/** @var CronExpression $expression */
|
||||
$expression = $job->getCronExpression();
|
||||
$next_run = $expression->getNextRunDate();
|
||||
|
||||
$row = [];
|
||||
$row[] = $job->getId();
|
||||
if (!is_null($job_state['last-run'])) {
|
||||
$row[] = '<yellow>' . date('Y-m-d H:i', $job_state['last-run']) . '</yellow>';
|
||||
} else {
|
||||
$row[] = '<yellow>Never</yellow>';
|
||||
}
|
||||
$row[] = '<yellow>' . $next_run->format('Y-m-d H:i') . '</yellow>';
|
||||
|
||||
if ($error) {
|
||||
$row[] = "<error>{$error}</error>";
|
||||
} else {
|
||||
$row[] = '<green>None</green>';
|
||||
}
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
$table->setRows($rows);
|
||||
$table->render();
|
||||
|
||||
} elseif ($this->input->getOption('install')) {
|
||||
$io->title('Install Scheduler');
|
||||
|
||||
if ($scheduler->isCrontabSetup()) {
|
||||
$io->success('All Ready! You have already set up Grav\'s Scheduler in your crontab');
|
||||
} else {
|
||||
$io->error('You still need to set up Grav\'s Scheduler in your crontab');
|
||||
}
|
||||
if (!Utils::isWindows()) {
|
||||
$io->note('To install, run the following command from your terminal:');
|
||||
$io->newLine();
|
||||
$io->text(trim($scheduler->getCronCommand()));
|
||||
} else {
|
||||
$io->note('To install, create a scheduled task in Windows.');
|
||||
$io->text('Learn more at https://learn.getgrav.org/advanced/scheduler');
|
||||
}
|
||||
} else {
|
||||
// Run scheduler
|
||||
$scheduler->run();
|
||||
|
||||
if ($this->input->getOption('verbose')) {
|
||||
$io->title('Running Scheduled Jobs');
|
||||
$io->text($scheduler->getVerboseOutput());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -12,7 +13,6 @@ use Grav\Common\Grav;
|
||||
use Grav\Common\Security;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SecurityCommand extends ConsoleCommand
|
||||
@@ -20,48 +20,41 @@ class SecurityCommand extends ConsoleCommand
|
||||
/** @var ProgressBar $progress */
|
||||
protected $progress;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("security")
|
||||
->setDescription("Capable of running various Security checks")
|
||||
->setName('security')
|
||||
->setDescription('Capable of running various Security checks')
|
||||
->setHelp('The <info>security</info> runs various security checks on your Grav site');
|
||||
|
||||
$this->source = getcwd();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
|
||||
|
||||
/** @var Grav $grav */
|
||||
$grav = Grav::instance();
|
||||
$grav->setup();
|
||||
|
||||
$grav['uri']->init();
|
||||
$grav['config']->init();
|
||||
$grav['debugger']->enabled(false);
|
||||
$grav['streams'];
|
||||
$grav['plugins']->init();
|
||||
$grav['themes']->init();
|
||||
|
||||
|
||||
$grav['twig']->init();
|
||||
$grav['pages']->init();
|
||||
|
||||
$this->progress = new ProgressBar($this->output, (count($grav['pages']->routes()) - 1));
|
||||
$this->progress = new ProgressBar($this->output, \count($grav['pages']->routes()) - 1);
|
||||
$this->progress->setFormat('Scanning <cyan>%current%</cyan> pages [<green>%bar%</green>] <white>%percent:3s%%</white> %elapsed:6s%');
|
||||
$this->progress->setBarWidth(100);
|
||||
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
$io->title('Grav Security Check');
|
||||
|
||||
$output = Security::detectXssFromPages($grav['pages'], [$this, 'outputProgress']);
|
||||
$output = Security::detectXssFromPages($grav['pages'], false, [$this, 'outputProgress']);
|
||||
|
||||
$io->newline(2);
|
||||
|
||||
@@ -77,7 +70,7 @@ class SecurityCommand extends ConsoleCommand
|
||||
$io->writeln($counter++ .' - <cyan>' . $route . '</cyan> → <red>' . implode(', ', $results_parts) . '</red>');
|
||||
}
|
||||
|
||||
$io->error('Security Scan complete: ' . count($output) . ' potential XSS issues found...');
|
||||
$io->error('Security Scan complete: ' . \count($output) . ' potential XSS issues found...');
|
||||
|
||||
} else {
|
||||
$io->success('Security Scan complete: No issues found...');
|
||||
@@ -88,14 +81,14 @@ class SecurityCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $args
|
||||
* @param array $args
|
||||
*/
|
||||
public function outputProgress($args)
|
||||
{
|
||||
switch ($args['type']) {
|
||||
case 'count':
|
||||
$steps = $args['steps'];
|
||||
$freq = intval($steps > 100 ? round($steps / 100) : $steps);
|
||||
$freq = (int)($steps > 100 ? round($steps / 100) : $steps);
|
||||
$this->progress->setMaxSteps($steps);
|
||||
$this->progress->setRedrawFrequency($freq);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Console\Cli
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Console\Cli;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Helpers\LogViewer;
|
||||
use Grav\Common\Helpers\YamlLinter;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class YamlLinterCommand extends ConsoleCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('yamllinter')
|
||||
->addOption(
|
||||
'env',
|
||||
'e',
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'The environment to trigger a specific configuration. For example: localhost, mysite.dev, www.mysite.com'
|
||||
)
|
||||
->setDescription('Checks various files for YAML errors')
|
||||
->setHelp("Checks various files for YAML errors");
|
||||
}
|
||||
|
||||
protected function serve()
|
||||
{
|
||||
$grav = Grav::instance();
|
||||
$grav->setup();
|
||||
|
||||
$io = new SymfonyStyle($this->input, $this->output);
|
||||
|
||||
$io->title('Yaml Linter');
|
||||
|
||||
$io->section('User Configuration');
|
||||
$errors = YamlLinter::lintConfig();
|
||||
|
||||
if (empty($errors)) {
|
||||
$io->success('No YAML Linting issues with configuration');
|
||||
} else {
|
||||
$this->displayErrors($errors, $io);
|
||||
}
|
||||
|
||||
|
||||
$io->section('Pages Frontmatter');
|
||||
$errors = YamlLinter::lintPages();
|
||||
|
||||
if (empty($errors)) {
|
||||
$io->success('No YAML Linting issues with pages');
|
||||
} else {
|
||||
$this->displayErrors($errors, $io);
|
||||
}
|
||||
|
||||
$io->section('Page Blueprints');
|
||||
$errors = YamlLinter::lintBlueprints();
|
||||
|
||||
if (empty($errors)) {
|
||||
$io->success('No YAML Linting issues with blueprints');
|
||||
} else {
|
||||
$this->displayErrors($errors, $io);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function displayErrors($errors, $io)
|
||||
{
|
||||
$io->error("YAML Linting issues found...");
|
||||
foreach ($errors as $path => $error) {
|
||||
$io->writeln("<yellow>$path</yellow> - $error");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -34,7 +35,6 @@ class ConsoleCommand extends Command
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function displayGPMRelease()
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Console;
|
||||
|
||||
use Grav\Common\Cache;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Composer;
|
||||
use Grav\Common\GravTrait;
|
||||
@@ -20,11 +22,6 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
trait ConsoleTrait
|
||||
{
|
||||
use GravTrait;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $argv;
|
||||
|
||||
/* @var InputInterface $output */
|
||||
@@ -33,6 +30,9 @@ trait ConsoleTrait
|
||||
/* @var OutputInterface $output */
|
||||
protected $output;
|
||||
|
||||
/** @var array */
|
||||
protected $local_config;
|
||||
|
||||
/**
|
||||
* Set colors style definition for the formatter.
|
||||
*
|
||||
@@ -59,7 +59,7 @@ trait ConsoleTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param string $path
|
||||
*/
|
||||
public function isGravInstance($path)
|
||||
{
|
||||
@@ -81,7 +81,7 @@ trait ConsoleTrait
|
||||
|
||||
if (!file_exists($path . DS . 'index.php') || !file_exists($path . DS . '.dependencies') || !file_exists($path . DS . 'system' . DS . 'config' . DS . 'system.yaml')) {
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("<red>ERROR</red>: Destination chosen to install does not appear to be a Grav instance:");
|
||||
$this->output->writeln('<red>ERROR</red>: Destination chosen to install does not appear to be a Grav instance:');
|
||||
$this->output->writeln(" <white>$path</white>");
|
||||
$this->output->writeln('');
|
||||
exit;
|
||||
@@ -112,6 +112,11 @@ trait ConsoleTrait
|
||||
return $command->run($input, $this->output);
|
||||
}
|
||||
|
||||
public function invalidateCache()
|
||||
{
|
||||
Cache::invalidateCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the local config file
|
||||
*
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Gpm
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Console\Gpm;
|
||||
|
||||
use Grav\Common\Cache;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\GPM\GPM;
|
||||
@@ -20,14 +22,16 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
class DirectInstallCommand extends ConsoleCommand
|
||||
{
|
||||
/** @var string */
|
||||
protected $all_yes;
|
||||
|
||||
/** @var string */
|
||||
protected $destination;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("direct-install")
|
||||
->setName('direct-install')
|
||||
->setAliases(['directinstall'])
|
||||
->addArgument(
|
||||
'package-file',
|
||||
@@ -47,7 +51,7 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
'The destination where the package should be installed at. By default this would be where the grav instance has been launched from',
|
||||
GRAV_ROOT
|
||||
)
|
||||
->setDescription("Installs Grav, plugin, or theme directly from a file or a URL")
|
||||
->setDescription('Installs Grav, plugin, or theme directly from a file or a URL')
|
||||
->setHelp('The <info>direct-install</info> command installs Grav, plugin, or theme directly from a file or a URL');
|
||||
}
|
||||
|
||||
@@ -63,7 +67,7 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
!Installer::isGravInstance($this->destination) ||
|
||||
!Installer::isValidDestination($this->destination, [Installer::EXISTS, Installer::IS_LINK])
|
||||
) {
|
||||
$this->output->writeln("<red>ERROR</red>: " . Installer::lastErrorMsg());
|
||||
$this->output->writeln('<red>ERROR</red>: ' . Installer::lastErrorMsg());
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -73,12 +77,12 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
$package_file = $this->input->getArgument('package-file');
|
||||
|
||||
$helper = $this->getHelper('question');
|
||||
$question = new ConfirmationQuestion('Are you sure you want to direct-install <cyan>'.$package_file.'</cyan> [y|N] ', false);
|
||||
$question = new ConfirmationQuestion("Are you sure you want to direct-install <cyan>{$package_file}</cyan> [y|N] ", false);
|
||||
|
||||
$answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question);
|
||||
|
||||
if (!$answer) {
|
||||
$this->output->writeln("exiting...");
|
||||
$this->output->writeln('exiting...');
|
||||
$this->output->writeln('');
|
||||
exit;
|
||||
}
|
||||
@@ -86,32 +90,32 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
$tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
|
||||
$tmp_zip = $tmp_dir . '/Grav-' . uniqid();
|
||||
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln("Preparing to install <cyan>" . $package_file . "</cyan>");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("Preparing to install <cyan>{$package_file}</cyan>");
|
||||
|
||||
|
||||
if (Response::isRemote($package_file)) {
|
||||
$this->output->write(" |- Downloading package... 0%");
|
||||
$this->output->write(' |- Downloading package... 0%');
|
||||
try {
|
||||
$zip = GPM::downloadPackage($package_file, $tmp_zip);
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln(" `- <red>ERROR: " . $e->getMessage() . "</red>");
|
||||
$this->output->writeln(" `- <red>ERROR: {$e->getMessage()}</red>");
|
||||
$this->output->writeln('');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($zip) {
|
||||
$this->output->write("\x0D");
|
||||
$this->output->write(" |- Downloading package... 100%");
|
||||
$this->output->write(' |- Downloading package... 100%');
|
||||
$this->output->writeln('');
|
||||
}
|
||||
} else {
|
||||
$this->output->write(" |- Copying package... 0%");
|
||||
$this->output->write(' |- Copying package... 0%');
|
||||
$zip = GPM::copyPackage($package_file, $tmp_zip);
|
||||
if ($zip) {
|
||||
$this->output->write("\x0D");
|
||||
$this->output->write(" |- Copying package... 100%");
|
||||
$this->output->write(' |- Copying package... 100%');
|
||||
$this->output->writeln('');
|
||||
}
|
||||
}
|
||||
@@ -119,19 +123,19 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
if (file_exists($zip)) {
|
||||
$tmp_source = $tmp_dir . '/Grav-' . uniqid();
|
||||
|
||||
$this->output->write(" |- Extracting package... ");
|
||||
$this->output->write(' |- Extracting package... ');
|
||||
$extracted = Installer::unZip($zip, $tmp_source);
|
||||
|
||||
if (!$extracted) {
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Extracting package... <red>failed</red>");
|
||||
$this->output->writeln(' |- Extracting package... <red>failed</red>');
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Extracting package... <green>ok</green>");
|
||||
$this->output->writeln(' |- Extracting package... <green>ok</green>');
|
||||
|
||||
|
||||
$type = GPM::getPackageType($extracted);
|
||||
@@ -147,26 +151,26 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
$blueprint = GPM::getBlueprints($extracted);
|
||||
if ($blueprint) {
|
||||
if (isset($blueprint['dependencies'])) {
|
||||
$depencencies = [];
|
||||
$dependencies = [];
|
||||
foreach ($blueprint['dependencies'] as $dependency) {
|
||||
if (is_array($dependency)){
|
||||
if (isset($dependency['name'])) {
|
||||
$depencencies[] = $dependency['name'];
|
||||
$dependencies[] = $dependency['name'];
|
||||
}
|
||||
if (isset($dependency['github'])) {
|
||||
$depencencies[] = $dependency['github'];
|
||||
$dependencies[] = $dependency['github'];
|
||||
}
|
||||
} else {
|
||||
$depencencies[] = $dependency;
|
||||
$dependencies[] = $dependency;
|
||||
}
|
||||
}
|
||||
$this->output->writeln(" |- Dependencies found... <cyan>[" . implode(',', $depencencies) . "]</cyan>");
|
||||
$this->output->writeln(' |- Dependencies found... <cyan>[' . implode(',', $dependencies) . ']</cyan>');
|
||||
|
||||
$question = new ConfirmationQuestion(" | '- Dependencies will not be satisfied. Continue ? [y|N] ", false);
|
||||
$answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question);
|
||||
|
||||
if (!$answer) {
|
||||
$this->output->writeln("exiting...");
|
||||
$this->output->writeln('exiting...');
|
||||
$this->output->writeln('');
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
@@ -175,14 +179,14 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
}
|
||||
}
|
||||
|
||||
if ($type == 'grav') {
|
||||
if ($type === 'grav') {
|
||||
|
||||
$this->output->write(" |- Checking destination... ");
|
||||
$this->output->write(' |- Checking destination... ');
|
||||
Installer::isValidDestination(GRAV_ROOT . '/system');
|
||||
if (Installer::IS_LINK === Installer::lastErrorCode()) {
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Checking destination... <yellow>symbolic link</yellow>");
|
||||
$this->output->writeln(" '- <red>ERROR: symlinks found...</red> <yellow>" . GRAV_ROOT."</yellow>");
|
||||
$this->output->writeln(' |- Checking destination... <yellow>symbolic link</yellow>');
|
||||
$this->output->writeln(" '- <red>ERROR: symlinks found...</red> <yellow>" . GRAV_ROOT . '</yellow>');
|
||||
$this->output->writeln('');
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
@@ -190,15 +194,16 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Checking destination... <green>ok</green>");
|
||||
$this->output->writeln(' |- Checking destination... <green>ok</green>');
|
||||
|
||||
$this->output->write(" |- Installing package... ");
|
||||
Installer::install($zip, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true], $extracted);
|
||||
$this->output->write(' |- Installing package... ');
|
||||
|
||||
static::upgradeGrav($zip, $extracted);
|
||||
} else {
|
||||
$name = GPM::getPackageName($extracted);
|
||||
|
||||
if (!$name) {
|
||||
$this->output->writeln("<red>ERROR: Name could not be determined.</red> Please specify with --name|-n");
|
||||
$this->output->writeln('<red>ERROR: Name could not be determined.</red> Please specify with --name|-n');
|
||||
$this->output->writeln('');
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
@@ -208,31 +213,31 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
$install_path = GPM::getInstallPath($type, $name);
|
||||
$is_update = file_exists($install_path);
|
||||
|
||||
$this->output->write(" |- Checking destination... ");
|
||||
$this->output->write(' |- Checking destination... ');
|
||||
|
||||
Installer::isValidDestination(GRAV_ROOT . DS . $install_path);
|
||||
if (Installer::lastErrorCode() == Installer::IS_LINK) {
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Checking destination... <yellow>symbolic link</yellow>");
|
||||
$this->output->writeln(' |- Checking destination... <yellow>symbolic link</yellow>');
|
||||
$this->output->writeln(" '- <red>ERROR: symlink found...</red> <yellow>" . GRAV_ROOT . DS . $install_path . '</yellow>');
|
||||
$this->output->writeln('');
|
||||
Folder::delete($tmp_source);
|
||||
Folder::delete($tmp_zip);
|
||||
exit;
|
||||
|
||||
} else {
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Checking destination... <green>ok</green>");
|
||||
}
|
||||
|
||||
$this->output->write(" |- Installing package... ");
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(' |- Checking destination... <green>ok</green>');
|
||||
|
||||
$this->output->write(' |- Installing package... ');
|
||||
|
||||
Installer::install(
|
||||
$zip,
|
||||
$this->destination,
|
||||
$options = [
|
||||
'install_path' => $install_path,
|
||||
'theme' => (($type == 'theme')),
|
||||
'theme' => (($type === 'theme')),
|
||||
'is_update' => $is_update
|
||||
],
|
||||
$extracted
|
||||
@@ -244,10 +249,10 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
$this->output->write("\x0D");
|
||||
|
||||
if(Installer::lastErrorCode()) {
|
||||
$this->output->writeln(" '- <red>" . Installer::lastErrorMsg() . "</red>");
|
||||
$this->output->writeln(" '- <red>" . Installer::lastErrorMsg() . '</red>');
|
||||
$this->output->writeln('');
|
||||
} else {
|
||||
$this->output->writeln(" |- Installing package... <green>ok</green>");
|
||||
$this->output->writeln(' |- Installing package... <green>ok</green>');
|
||||
$this->output->writeln(" '- <green>Success!</green> ");
|
||||
$this->output->writeln('');
|
||||
}
|
||||
@@ -262,6 +267,43 @@ class DirectInstallCommand extends ConsoleCommand
|
||||
$this->clearCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function upgradeGrav($zip, $folder, $keepFolder = false)
|
||||
{
|
||||
static $ignores = [
|
||||
'backup',
|
||||
'cache',
|
||||
'images',
|
||||
'logs',
|
||||
'tmp',
|
||||
'user',
|
||||
'.htaccess',
|
||||
'robots.txt'
|
||||
];
|
||||
|
||||
if (!is_dir($folder)) {
|
||||
Installer::setError('Invalid source folder');
|
||||
}
|
||||
|
||||
try {
|
||||
$script = $folder . '/system/install.php';
|
||||
/** Install $installer */
|
||||
if ((file_exists($script) && $install = include $script) && is_callable($install)) {
|
||||
$install($zip);
|
||||
} else {
|
||||
Installer::install(
|
||||
$zip,
|
||||
GRAV_ROOT,
|
||||
['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true, 'ignores' => $ignores],
|
||||
$folder,
|
||||
$keepFolder
|
||||
);
|
||||
|
||||
Cache::clearCache();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Installer::setError($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Gpm
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Console\Gpm;
|
||||
|
||||
use Grav\Common\GPM\Remote\Package;
|
||||
use Grav\Common\GPM\GPM;
|
||||
use Grav\Common\GPM\Remote\Packages;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
use League\CLImate\CLImate;
|
||||
@@ -16,32 +19,22 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class IndexCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
/** @var array */
|
||||
protected $data;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var GPM */
|
||||
protected $gpm;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
/** @var array */
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var array */
|
||||
protected $sortKeys = ['name', 'slug', 'author', 'date'];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("index")
|
||||
->setName('index')
|
||||
->addOption(
|
||||
'force',
|
||||
'f',
|
||||
@@ -91,14 +84,11 @@ class IndexCommand extends ConsoleCommand
|
||||
InputOption::VALUE_NONE,
|
||||
'Reverses the order of the output.'
|
||||
)
|
||||
->setDescription("Lists the plugins and themes available for installation")
|
||||
->setDescription('Lists the plugins and themes available for installation')
|
||||
->setHelp('The <info>index</info> command lists the plugins and themes available for installation')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$this->options = $this->input->getOptions();
|
||||
@@ -123,7 +113,7 @@ class IndexCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
foreach ($data as $type => $packages) {
|
||||
$this->output->writeln("<green>" . strtoupper($type) . "</green> [ " . count($packages) . " ]");
|
||||
$this->output->writeln('<green>' . strtoupper($type) . '</green> [ ' . \count($packages) . ' ]');
|
||||
$packages = $this->sort($packages);
|
||||
|
||||
if (!empty($packages)) {
|
||||
@@ -134,7 +124,7 @@ class IndexCommand extends ConsoleCommand
|
||||
foreach ($packages as $slug => $package) {
|
||||
$row = [
|
||||
'Count' => $index++ + 1,
|
||||
'Name' => "<cyan>" . Utils::truncate($package->name, 20, false, ' ', '...') . "</cyan> ",
|
||||
'Name' => '<cyan>' . Utils::truncate($package->name, 20, false, ' ', '...') . '</cyan> ',
|
||||
'Slug' => $slug,
|
||||
'Version'=> $this->version($package),
|
||||
'Installed' => $this->installed($package)
|
||||
@@ -149,55 +139,56 @@ class IndexCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
$this->output->writeln('You can either get more informations about a package by typing:');
|
||||
$this->output->writeln(' <green>' . $this->argv . ' info <cyan><package></cyan></green>');
|
||||
$this->output->writeln(" <green>{$this->argv} info <cyan><package></cyan></green>");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln('Or you can install a package by typing:');
|
||||
$this->output->writeln(' <green>' . $this->argv . ' install <cyan><package></cyan></green>');
|
||||
$this->output->writeln(" <green>{$this->argv} install <cyan><package></cyan></green>");
|
||||
$this->output->writeln('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function version($package)
|
||||
{
|
||||
$list = $this->gpm->{'getUpdatable' . ucfirst($package->package_type)}();
|
||||
$package = isset($list[$package->slug]) ? $list[$package->slug] : $package;
|
||||
$type = ucfirst(preg_replace("/s$/", '', $package->package_type));
|
||||
$package = $list[$package->slug] ?? $package;
|
||||
$type = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
$updatable = $this->gpm->{'is' . $type . 'Updatable'}($package->slug);
|
||||
$installed = $this->gpm->{'is' . $type . 'Installed'}($package->slug);
|
||||
$local = $this->gpm->{'getInstalled' . $type}($package->slug);
|
||||
|
||||
if (!$installed || !$updatable) {
|
||||
$version = $installed ? $local->version : $package->version;
|
||||
return "v<green>" . $version . "</green>";
|
||||
return "v<green>{$version}</green>";
|
||||
}
|
||||
|
||||
if ($updatable) {
|
||||
return "v<red>" . $package->version . "</red> <cyan>-></cyan> v<green>" . $package->available . "</green>";
|
||||
return "v<red>{$package->version}</red> <cyan>-></cyan> v<green>{$package->available}</green>";
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function installed($package)
|
||||
{
|
||||
$package = isset($list[$package->slug]) ? $list[$package->slug] : $package;
|
||||
$type = ucfirst(preg_replace("/s$/", '', $package->package_type));
|
||||
$installed = $this->gpm->{'is' . $type . 'Installed'}($package->slug);
|
||||
$package = $list[$package->slug] ?? $package;
|
||||
$type = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
$method = 'is' . $type . 'Installed';
|
||||
$installed = $this->gpm->{$method}($package->slug);
|
||||
|
||||
return !$installed ? '<magenta>not installed</magenta>' : '<cyan>installed</cyan>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -218,26 +209,28 @@ class IndexCommand extends ConsoleCommand
|
||||
$this->options['desc']
|
||||
];
|
||||
|
||||
if (count(array_filter($filter))) {
|
||||
if (\count(array_filter($filter))) {
|
||||
foreach ($data as $type => $packages) {
|
||||
foreach ($packages as $slug => $package) {
|
||||
$filter = true;
|
||||
|
||||
// Filtering by string
|
||||
if ($this->options['filter']) {
|
||||
$filter = preg_grep('/(' . (implode('|', $this->options['filter'])) . ')/i', [$slug, $package->name]);
|
||||
$filter = preg_grep('/(' . implode('|', $this->options['filter']) . ')/i', [$slug, $package->name]);
|
||||
}
|
||||
|
||||
// Filtering updatables only
|
||||
if ($this->options['installed-only'] && $filter) {
|
||||
$method = ucfirst(preg_replace("/s$/", '', $package->package_type));
|
||||
$filter = $this->gpm->{'is' . $method . 'Installed'}($package->slug);
|
||||
if ($filter && $this->options['installed-only']) {
|
||||
$method = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
$function = 'is' . $method . 'Installed';
|
||||
$filter = $this->gpm->{$function}($package->slug);
|
||||
}
|
||||
|
||||
// Filtering updatables only
|
||||
if ($this->options['updates-only'] && $filter) {
|
||||
$method = ucfirst(preg_replace("/s$/", '', $package->package_type));
|
||||
$filter = $this->gpm->{'is' . $method . 'Updatable'}($package->slug);
|
||||
if ($filter && $this->options['updates-only']) {
|
||||
$method = ucfirst(preg_replace('/s$/', '', $package->package_type));
|
||||
$function = 'is' . $method . 'Updatable';
|
||||
$filter = $this->gpm->{$function}($package->slug);
|
||||
}
|
||||
|
||||
if (!$filter) {
|
||||
@@ -251,7 +244,7 @@ class IndexCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $packages
|
||||
* @param Packages $packages
|
||||
*/
|
||||
public function sort($packages)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Gpm
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -16,15 +17,13 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
class InfoCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
/** @var array */
|
||||
protected $data;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var GPM */
|
||||
protected $gpm;
|
||||
|
||||
/** @var string */
|
||||
protected $all_yes;
|
||||
|
||||
/**
|
||||
@@ -33,7 +32,7 @@ class InfoCommand extends ConsoleCommand
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("info")
|
||||
->setName('info')
|
||||
->addOption(
|
||||
'force',
|
||||
'f',
|
||||
@@ -51,7 +50,7 @@ class InfoCommand extends ConsoleCommand
|
||||
InputArgument::REQUIRED,
|
||||
'The package of which more informations are desired. Use the "index" command for a list of packages'
|
||||
)
|
||||
->setDescription("Shows more informations about a package")
|
||||
->setDescription('Shows more informations about a package')
|
||||
->setHelp('The <info>info</info> shows more informations about a package');
|
||||
}
|
||||
|
||||
@@ -69,19 +68,19 @@ class InfoCommand extends ConsoleCommand
|
||||
$foundPackage = $this->gpm->findPackage($this->input->getArgument('package'));
|
||||
|
||||
if (!$foundPackage) {
|
||||
$this->output->writeln("The package <cyan>'" . $this->input->getArgument('package') . "'</cyan> was not found in the Grav repository.");
|
||||
$this->output->writeln("The package <cyan>'{$this->input->getArgument('package')}'</cyan> was not found in the Grav repository.");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("You can list all the available packages by typing:");
|
||||
$this->output->writeln(" <green>" . $this->argv . " index</green>");
|
||||
$this->output->writeln('You can list all the available packages by typing:');
|
||||
$this->output->writeln(" <green>{$this->argv} index</green>");
|
||||
$this->output->writeln('');
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->output->writeln("Found package <cyan>'" . $this->input->getArgument('package') . "'</cyan> under the '<green>" . ucfirst($foundPackage->package_type) . "</green>' section");
|
||||
$this->output->writeln("Found package <cyan>'{$this->input->getArgument('package')}'</cyan> under the '<green>" . ucfirst($foundPackage->package_type) . "</green>' section");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("<cyan>" . $foundPackage->name . "</cyan> [" . $foundPackage->slug . "]");
|
||||
$this->output->writeln(str_repeat('-', strlen($foundPackage->name) + strlen($foundPackage->slug) + 3));
|
||||
$this->output->writeln("<white>" . strip_tags($foundPackage->description_plain) . "</white>");
|
||||
$this->output->writeln("<cyan>{$foundPackage->name}</cyan> [{$foundPackage->slug}]");
|
||||
$this->output->writeln(str_repeat('-', \strlen($foundPackage->name) + \strlen($foundPackage->slug) + 3));
|
||||
$this->output->writeln('<white>' . strip_tags($foundPackage->description_plain) . '</white>');
|
||||
$this->output->writeln('');
|
||||
|
||||
$packageURL = '';
|
||||
@@ -89,8 +88,8 @@ class InfoCommand extends ConsoleCommand
|
||||
$packageURL = '<' . $foundPackage->author['url'] . '>';
|
||||
}
|
||||
|
||||
$this->output->writeln("<green>" . str_pad("Author",
|
||||
12) . ":</green> " . $foundPackage->author['name'] . ' <' . $foundPackage->author['email'] . '> ' . $packageURL);
|
||||
$this->output->writeln('<green>' . str_pad('Author',
|
||||
12) . ':</green> ' . $foundPackage->author['name'] . ' <' . $foundPackage->author['email'] . '> ' . $packageURL);
|
||||
|
||||
foreach ([
|
||||
'version',
|
||||
@@ -105,21 +104,21 @@ class InfoCommand extends ConsoleCommand
|
||||
'zipball_url',
|
||||
'license'
|
||||
] as $info) {
|
||||
if (isset($foundPackage->$info)) {
|
||||
if (isset($foundPackage->{$info})) {
|
||||
$name = ucfirst($info);
|
||||
$data = $foundPackage->$info;
|
||||
$data = $foundPackage->{$info};
|
||||
|
||||
if ($info == 'zipball_url') {
|
||||
$name = "Download";
|
||||
if ($info === 'zipball_url') {
|
||||
$name = 'Download';
|
||||
}
|
||||
|
||||
if ($info == 'date') {
|
||||
$name = "Last Update";
|
||||
$data = date('D, j M Y, H:i:s, P ', strtotime('2014-09-16T00:07:16Z'));
|
||||
if ($info === 'date') {
|
||||
$name = 'Last Update';
|
||||
$data = date('D, j M Y, H:i:s, P ', strtotime($data));
|
||||
}
|
||||
|
||||
$name = str_pad($name, 12);
|
||||
$this->output->writeln("<green>" . $name . ":</green> " . $data);
|
||||
$this->output->writeln("<green>{$name}:</green> {$data}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,48 +130,48 @@ class InfoCommand extends ConsoleCommand
|
||||
if ($installed && $updatable) {
|
||||
$local = $this->gpm->{'getInstalled'. $type}($foundPackage->slug);
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("Currently installed version: <magenta>" . $local->version . "</magenta>");
|
||||
$this->output->writeln("Currently installed version: <magenta>{$local->version}</magenta>");
|
||||
$this->output->writeln('');
|
||||
}
|
||||
|
||||
// display changelog information
|
||||
$questionHelper = $this->getHelper('question');
|
||||
$question = new ConfirmationQuestion("Would you like to read the changelog? [y|N] ",
|
||||
$question = new ConfirmationQuestion('Would you like to read the changelog? [y|N] ',
|
||||
false);
|
||||
$answer = $this->all_yes ? true : $questionHelper->ask($this->input, $this->output, $question);
|
||||
|
||||
if ($answer) {
|
||||
$changelog = $foundPackage->changelog;
|
||||
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('');
|
||||
foreach ($changelog as $version => $log) {
|
||||
$title = $version . ' [' . $log['date'] . ']';
|
||||
$content = preg_replace_callback('/\d\.\s\[\]\(#(.*)\)/', function ($match) {
|
||||
return "\n" . ucfirst($match[1]) . ":";
|
||||
return "\n" . ucfirst($match[1]) . ':';
|
||||
}, $log['content']);
|
||||
|
||||
$this->output->writeln('<cyan>'.$title.'</cyan>');
|
||||
$this->output->writeln(str_repeat('-', strlen($title)));
|
||||
$this->output->writeln("<cyan>{$title}</cyan>");
|
||||
$this->output->writeln(str_repeat('-', \strlen($title)));
|
||||
$this->output->writeln($content);
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('');
|
||||
|
||||
$question = new ConfirmationQuestion("Press [ENTER] to continue or [q] to quit ", true);
|
||||
$question = new ConfirmationQuestion('Press [ENTER] to continue or [q] to quit ', true);
|
||||
$answer = $this->all_yes ? false : $questionHelper->ask($this->input, $this->output, $question);
|
||||
if (!$answer) {
|
||||
break;
|
||||
}
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('');
|
||||
}
|
||||
}
|
||||
|
||||
$this->output->writeln('');
|
||||
|
||||
if ($installed && $updatable) {
|
||||
$this->output->writeln("You can update this package by typing:");
|
||||
$this->output->writeln(" <green>" . $this->argv . " update</green> <cyan>" . $foundPackage->slug . "</cyan>");
|
||||
$this->output->writeln('You can update this package by typing:');
|
||||
$this->output->writeln(" <green>{$this->argv} update</green> <cyan>{$foundPackage->slug}</cyan>");
|
||||
} else {
|
||||
$this->output->writeln("You can install this package by typing:");
|
||||
$this->output->writeln(" <green>" . $this->argv . " install</green> <cyan>" . $foundPackage->slug . "</cyan>");
|
||||
$this->output->writeln(" <green>{$this->argv} install</green> <cyan>{$foundPackage->slug}</cyan>");
|
||||
}
|
||||
|
||||
$this->output->writeln('');
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Gpm
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -13,7 +14,7 @@ use Grav\Common\GPM\GPM;
|
||||
use Grav\Common\GPM\Installer;
|
||||
use Grav\Common\GPM\Licenses;
|
||||
use Grav\Common\GPM\Response;
|
||||
use Grav\Common\GPM\Remote\Package as Package;
|
||||
use Grav\Common\GPM\Remote\Package;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
@@ -21,26 +22,26 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
define('GIT_REGEX', '/http[s]?:\/\/(?:.*@)?(github|bitbucket)(?:.org|.com)\/.*\/(.*)/');
|
||||
\define('GIT_REGEX', '/http[s]?:\/\/(?:.*@)?(github|bitbucket)(?:.org|.com)\/.*\/(.*)/');
|
||||
|
||||
class InstallCommand extends ConsoleCommand
|
||||
{
|
||||
/** @var */
|
||||
/** @var array */
|
||||
protected $data;
|
||||
|
||||
/** @var GPM */
|
||||
protected $gpm;
|
||||
|
||||
/** @var */
|
||||
/** @var string */
|
||||
protected $destination;
|
||||
|
||||
/** @var */
|
||||
/** @var string */
|
||||
protected $file;
|
||||
|
||||
/** @var */
|
||||
/** @var string */
|
||||
protected $tmp;
|
||||
|
||||
/** @var */
|
||||
/** @var array */
|
||||
protected $local_config;
|
||||
|
||||
/** @var bool */
|
||||
@@ -49,15 +50,13 @@ class InstallCommand extends ConsoleCommand
|
||||
/** @var array */
|
||||
protected $demo_processing = [];
|
||||
|
||||
/** @var string */
|
||||
protected $all_yes;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("install")
|
||||
->setName('install')
|
||||
->addOption(
|
||||
'force',
|
||||
'f',
|
||||
@@ -82,16 +81,16 @@ class InstallCommand extends ConsoleCommand
|
||||
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
|
||||
'Package(s) to install. Use "bin/gpm index" to list packages. Use "bin/gpm direct-install" to install a specific version'
|
||||
)
|
||||
->setDescription("Performs the installation of plugins and themes")
|
||||
->setDescription('Performs the installation of plugins and themes')
|
||||
->setHelp('The <info>install</info> command allows to install plugins and themes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to set the GPM object, used for testing the class
|
||||
*
|
||||
* @param $gpm
|
||||
* @param GPM $gpm
|
||||
*/
|
||||
public function setGpm($gpm)
|
||||
public function setGpm(GPM $gpm)
|
||||
{
|
||||
$this->gpm = $gpm;
|
||||
}
|
||||
@@ -117,28 +116,26 @@ class InstallCommand extends ConsoleCommand
|
||||
!Installer::isGravInstance($this->destination) ||
|
||||
!Installer::isValidDestination($this->destination, [Installer::EXISTS, Installer::IS_LINK])
|
||||
) {
|
||||
$this->output->writeln("<red>ERROR</red>: " . Installer::lastErrorMsg());
|
||||
$this->output->writeln('<red>ERROR</red>: ' . Installer::lastErrorMsg());
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->output->writeln('');
|
||||
|
||||
if (!$this->data['total']) {
|
||||
$this->output->writeln("Nothing to install.");
|
||||
$this->output->writeln('Nothing to install.');
|
||||
$this->output->writeln('');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($this->data['not_found'])) {
|
||||
$this->output->writeln("These packages were not found on Grav: <red>" . implode('</red>, <red>',
|
||||
array_keys($this->data['not_found'])) . "</red>");
|
||||
if (\count($this->data['not_found'])) {
|
||||
$this->output->writeln('These packages were not found on Grav: <red>' . implode('</red>, <red>',
|
||||
array_keys($this->data['not_found'])) . '</red>');
|
||||
}
|
||||
|
||||
unset($this->data['not_found']);
|
||||
unset($this->data['total']);
|
||||
unset($this->data['not_found'], $this->data['total']);
|
||||
|
||||
|
||||
if (isset($this->local_config)) {
|
||||
if (null !== $this->local_config) {
|
||||
// Symlinks available, ask if Grav should use them
|
||||
$this->use_symlinks = false;
|
||||
$helper = $this->getHelper('question');
|
||||
@@ -149,8 +146,6 @@ class InstallCommand extends ConsoleCommand
|
||||
if ($answer) {
|
||||
$this->use_symlinks = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$this->output->writeln('');
|
||||
@@ -160,22 +155,22 @@ class InstallCommand extends ConsoleCommand
|
||||
} catch (\Exception $e) {
|
||||
//Error out if there are incompatible packages requirements and tell which ones, and what to do
|
||||
//Error out if there is any error in parsing the dependencies and their versions, and tell which one is broken
|
||||
$this->output->writeln("<red>" . $e->getMessage() . "</red>");
|
||||
$this->output->writeln("<red>{$e->getMessage()}</red>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($dependencies) {
|
||||
try {
|
||||
$this->installDependencies($dependencies, 'install', "The following dependencies need to be installed...");
|
||||
$this->installDependencies($dependencies, 'update', "The following dependencies need to be updated...");
|
||||
$this->installDependencies($dependencies, 'install', 'The following dependencies need to be installed...');
|
||||
$this->installDependencies($dependencies, 'update', 'The following dependencies need to be updated...');
|
||||
$this->installDependencies($dependencies, 'ignore', "The following dependencies can be updated as there is a newer version, but it's not mandatory...", false);
|
||||
} catch (\Exception $e) {
|
||||
$this->output->writeln("<red>Installation aborted</red>");
|
||||
$this->output->writeln('<red>Installation aborted</red>');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->output->writeln("<green>Dependencies are OK</green>");
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('<green>Dependencies are OK</green>');
|
||||
$this->output->writeln('');
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +178,7 @@ class InstallCommand extends ConsoleCommand
|
||||
foreach ($this->data as $data) {
|
||||
foreach ($data as $package_name => $package) {
|
||||
if (array_key_exists($package_name, $dependencies)) {
|
||||
$this->output->writeln("<green>Package " . $package_name . " already installed as dependency</green>");
|
||||
$this->output->writeln("<green>Package {$package_name} already installed as dependency</green>");
|
||||
} else {
|
||||
$is_valid_destination = Installer::isValidDestination($this->destination . DS . $package->install_path);
|
||||
if ($is_valid_destination || Installer::lastErrorCode() == Installer::NOT_FOUND) {
|
||||
@@ -195,24 +190,24 @@ class InstallCommand extends ConsoleCommand
|
||||
$this->askConfirmationIfMajorVersionUpdated($package);
|
||||
$this->gpm->checkNoOtherPackageNeedsThisDependencyInALowerVersion($package->slug, $package->available, array_keys($data));
|
||||
} catch (\Exception $e) {
|
||||
$this->output->writeln("<red>" . $e->getMessage() . "</red>");
|
||||
$this->output->writeln("<red>{$e->getMessage()}</red>");
|
||||
return false;
|
||||
}
|
||||
|
||||
$helper = $this->getHelper('question');
|
||||
$question = new ConfirmationQuestion("The package <cyan>$package_name</cyan> is already installed, overwrite? [y|N] ", false);
|
||||
$question = new ConfirmationQuestion("The package <cyan>{$package_name}</cyan> is already installed, overwrite? [y|N] ", false);
|
||||
$answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question);
|
||||
|
||||
if ($answer) {
|
||||
$is_update = true;
|
||||
$this->processPackage($package, $is_update);
|
||||
} else {
|
||||
$this->output->writeln("<yellow>Package " . $package_name . " not overwritten</yellow>");
|
||||
$this->output->writeln("<yellow>Package {$package_name} not overwritten</yellow>");
|
||||
}
|
||||
} else {
|
||||
if (Installer::lastErrorCode() == Installer::IS_LINK) {
|
||||
$this->output->writeln("<red>Cannot overwrite existing symlink for </red><cyan>$package_name</cyan>");
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln("<red>Cannot overwrite existing symlink for </red><cyan>{$package_name}</cyan>");
|
||||
$this->output->writeln('');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +215,7 @@ class InstallCommand extends ConsoleCommand
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->demo_processing) > 0) {
|
||||
if (\count($this->demo_processing) > 0) {
|
||||
foreach ($this->demo_processing as $package) {
|
||||
$this->installDemoContent($package);
|
||||
}
|
||||
@@ -235,27 +230,27 @@ class InstallCommand extends ConsoleCommand
|
||||
/**
|
||||
* If the package is updated from an older major release, show warning and ask confirmation
|
||||
*
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*/
|
||||
public function askConfirmationIfMajorVersionUpdated($package)
|
||||
{
|
||||
$helper = $this->getHelper('question');
|
||||
$package_name = $package->name;
|
||||
$new_version = $package->available ? $package->available : $this->gpm->getLatestVersionOfPackage($package->slug);
|
||||
$new_version = $package->available ?: $this->gpm->getLatestVersionOfPackage($package->slug);
|
||||
$old_version = $package->version;
|
||||
|
||||
$major_version_changed = explode('.', $new_version)[0] !== explode('.', $old_version)[0];
|
||||
|
||||
if ($major_version_changed) {
|
||||
if ($this->all_yes) {
|
||||
$this->output->writeln("The package <cyan>$package_name</cyan> will be updated to a new major version <green>$new_version</green>, from <magenta>$old_version</magenta>");
|
||||
$this->output->writeln("The package <cyan>{$package_name}</cyan> will be updated to a new major version <green>{$new_version}</green>, from <magenta>{$old_version}</magenta>");
|
||||
return;
|
||||
}
|
||||
|
||||
$question = new ConfirmationQuestion("The package <cyan>$package_name</cyan> will be updated to a new major version <green>$new_version</green>, from <magenta>$old_version</magenta>. Be sure to read what changed with the new major release. Continue? [y|N] ", false);
|
||||
$question = new ConfirmationQuestion("The package <cyan>{$package_name}</cyan> will be updated to a new major version <green>{$new_version}</green>, from <magenta>{$old_version}</magenta>. Be sure to read what changed with the new major release. Continue? [y|N] ", false);
|
||||
|
||||
if (!$helper->ask($this->input, $this->output, $question)) {
|
||||
$this->output->writeln("<yellow>Package " . $package_name . " not updated</yellow>");
|
||||
$this->output->writeln("<yellow>Package {$package_name} not updated</yellow>");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -276,42 +271,42 @@ class InstallCommand extends ConsoleCommand
|
||||
public function installDependencies($dependencies, $type, $message, $required = true)
|
||||
{
|
||||
$packages = array_filter($dependencies, function ($action) use ($type) { return $action === $type; });
|
||||
if (count($packages) > 0) {
|
||||
if (\count($packages) > 0) {
|
||||
$this->output->writeln($message);
|
||||
|
||||
foreach ($packages as $dependencyName => $dependencyVersion) {
|
||||
$this->output->writeln(" |- Package <cyan>" . $dependencyName . "</cyan>");
|
||||
$this->output->writeln(" |- Package <cyan>{$dependencyName}</cyan>");
|
||||
}
|
||||
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('');
|
||||
|
||||
$helper = $this->getHelper('question');
|
||||
|
||||
if ($type == 'install') {
|
||||
if ($type === 'install') {
|
||||
$questionAction = 'Install';
|
||||
} else {
|
||||
$questionAction = 'Update';
|
||||
}
|
||||
|
||||
if (count($packages) == 1) {
|
||||
if (\count($packages) === 1) {
|
||||
$questionArticle = 'this';
|
||||
} else {
|
||||
$questionArticle = 'these';
|
||||
}
|
||||
|
||||
if (count($packages) == 1) {
|
||||
if (\count($packages) === 1) {
|
||||
$questionNoun = 'package';
|
||||
} else {
|
||||
$questionNoun = 'packages';
|
||||
}
|
||||
|
||||
$question = new ConfirmationQuestion("$questionAction $questionArticle $questionNoun? [Y|n] ", true);
|
||||
$question = new ConfirmationQuestion("${questionAction} {$questionArticle} {$questionNoun}? [Y|n] ", true);
|
||||
$answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question);
|
||||
|
||||
if ($answer) {
|
||||
foreach ($packages as $dependencyName => $dependencyVersion) {
|
||||
$package = $this->gpm->findPackage($dependencyName);
|
||||
$this->processPackage($package, ($type == 'update') ? true : false);
|
||||
$this->processPackage($package, $type === 'update');
|
||||
}
|
||||
$this->output->writeln('');
|
||||
} else {
|
||||
@@ -323,20 +318,20 @@ class InstallCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param bool $is_update True if the package is an update
|
||||
* @param Package $package
|
||||
* @param bool $is_update True if the package is an update
|
||||
*/
|
||||
private function processPackage($package, $is_update = false)
|
||||
{
|
||||
if (!$package) {
|
||||
$this->output->writeln("<red>Package not found on the GPM!</red> ");
|
||||
$this->output->writeln('<red>Package not found on the GPM!</red>');
|
||||
$this->output->writeln('');
|
||||
return;
|
||||
}
|
||||
|
||||
$symlink = false;
|
||||
if ($this->use_symlinks) {
|
||||
if ($this->getSymlinkSource($package) || !isset($package->version)) {
|
||||
if (!isset($package->version) || $this->getSymlinkSource($package)) {
|
||||
$symlink = true;
|
||||
}
|
||||
}
|
||||
@@ -349,7 +344,7 @@ class InstallCommand extends ConsoleCommand
|
||||
/**
|
||||
* Add package to the queue to process the demo content, if demo content exists
|
||||
*
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*/
|
||||
private function processDemo($package)
|
||||
{
|
||||
@@ -362,7 +357,7 @@ class InstallCommand extends ConsoleCommand
|
||||
/**
|
||||
* Prompt to install the demo content of a package
|
||||
*
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*/
|
||||
private function installDemoContent($package)
|
||||
{
|
||||
@@ -373,11 +368,11 @@ class InstallCommand extends ConsoleCommand
|
||||
$pages_dir = $dest_dir . DS . 'pages';
|
||||
|
||||
// Demo content exists, prompt to install it.
|
||||
$this->output->writeln("<white>Attention: </white><cyan>" . $package->name . "</cyan> contains demo content");
|
||||
$this->output->writeln("<white>Attention: </white><cyan>{$package->name}</cyan> contains demo content");
|
||||
$helper = $this->getHelper('question');
|
||||
$question = new ConfirmationQuestion('Do you wish to install this demo content? [y|N] ', false);
|
||||
|
||||
$answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question);
|
||||
$answer = $helper->ask($this->input, $this->output, $question);
|
||||
|
||||
if (!$answer) {
|
||||
$this->output->writeln(" '- <red>Skipped!</red> ");
|
||||
@@ -402,15 +397,15 @@ class InstallCommand extends ConsoleCommand
|
||||
// backup current pages folder
|
||||
if (file_exists($dest_dir)) {
|
||||
if (rename($pages_dir, $dest_dir . DS . $pages_backup)) {
|
||||
$this->output->writeln(" |- Backing up pages... <green>ok</green>");
|
||||
$this->output->writeln(' |- Backing up pages... <green>ok</green>');
|
||||
} else {
|
||||
$this->output->writeln(" |- Backing up pages... <red>failed</red>");
|
||||
$this->output->writeln(' |- Backing up pages... <red>failed</red>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Confirmation received, copy over the data
|
||||
$this->output->writeln(" |- Installing demo content... <green>ok</green> ");
|
||||
$this->output->writeln(' |- Installing demo content... <green>ok</green> ');
|
||||
Folder::rcopy($demo_dir, $dest_dir);
|
||||
$this->output->writeln(" '- <green>Success!</green> ");
|
||||
$this->output->writeln('');
|
||||
@@ -418,7 +413,7 @@ class InstallCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
@@ -436,7 +431,7 @@ class InstallCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
@@ -465,7 +460,7 @@ class InstallCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*/
|
||||
private function processSymlink($package)
|
||||
{
|
||||
@@ -475,13 +470,13 @@ class InstallCommand extends ConsoleCommand
|
||||
$to = $this->destination . DS . $package->install_path;
|
||||
$from = $this->getSymlinkSource($package);
|
||||
|
||||
$this->output->writeln("Preparing to Symlink <cyan>" . $package->name . "</cyan>");
|
||||
$this->output->write(" |- Checking source... ");
|
||||
$this->output->writeln("Preparing to Symlink <cyan>{$package->name}</cyan>");
|
||||
$this->output->write(' |- Checking source... ');
|
||||
|
||||
if (file_exists($from)) {
|
||||
$this->output->writeln("<green>ok</green>");
|
||||
$this->output->writeln('<green>ok</green>');
|
||||
|
||||
$this->output->write(" |- Checking destination... ");
|
||||
$this->output->write(' |- Checking destination... ');
|
||||
$checks = $this->checkDestination($package);
|
||||
|
||||
if (!$checks) {
|
||||
@@ -495,7 +490,7 @@ class InstallCommand extends ConsoleCommand
|
||||
symlink($from, $to);
|
||||
|
||||
// extra white spaces to clear out the buffer properly
|
||||
$this->output->writeln(" |- Symlinking package... <green>ok</green> ");
|
||||
$this->output->writeln(' |- Symlinking package... <green>ok</green> ');
|
||||
$this->output->writeln(" '- <green>Success!</green> ");
|
||||
$this->output->writeln('');
|
||||
}
|
||||
@@ -504,13 +499,13 @@ class InstallCommand extends ConsoleCommand
|
||||
return;
|
||||
}
|
||||
|
||||
$this->output->writeln("<red>not found!</red>");
|
||||
$this->output->writeln('<red>not found!</red>');
|
||||
$this->output->writeln(" '- <red>Installation failed or aborted.</red>");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param bool $is_update
|
||||
* @param Package $package
|
||||
* @param bool $is_update
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -519,9 +514,9 @@ class InstallCommand extends ConsoleCommand
|
||||
$version = isset($package->available) ? $package->available : $package->version;
|
||||
$license = Licenses::get($package->slug);
|
||||
|
||||
$this->output->writeln("Preparing to install <cyan>" . $package->name . "</cyan> [v" . $version . "]");
|
||||
$this->output->writeln("Preparing to install <cyan>{$package->name}</cyan> [v{$version}]");
|
||||
|
||||
$this->output->write(" |- Downloading package... 0%");
|
||||
$this->output->write(' |- Downloading package... 0%');
|
||||
$this->file = $this->downloadPackage($package, $license);
|
||||
|
||||
if (!$this->file) {
|
||||
@@ -531,14 +526,14 @@ class InstallCommand extends ConsoleCommand
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->output->write(" |- Checking destination... ");
|
||||
$this->output->write(' |- Checking destination... ');
|
||||
$checks = $this->checkDestination($package);
|
||||
|
||||
if (!$checks) {
|
||||
$this->output->writeln(" '- <red>Installation failed or aborted.</red>");
|
||||
$this->output->writeln('');
|
||||
} else {
|
||||
$this->output->write(" |- Installing package... ");
|
||||
$this->output->write(' |- Installing package... ');
|
||||
$installation = $this->installPackage($package, $is_update);
|
||||
if (!$installation) {
|
||||
$this->output->writeln(" '- <red>Installation failed or aborted.</red>");
|
||||
@@ -566,10 +561,10 @@ class InstallCommand extends ConsoleCommand
|
||||
$tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
|
||||
$this->tmp = $tmp_dir . '/Grav-' . uniqid();
|
||||
$filename = $package->slug . basename($package->zipball_url);
|
||||
$filename = preg_replace('/[\\\\\/:"*?&<>|]+/mi', '-', $filename);
|
||||
$filename = preg_replace('/[\\\\\/:"*?&<>|]+/m', '-', $filename);
|
||||
$query = '';
|
||||
|
||||
if ($package->premium) {
|
||||
if (!empty($package->premium)) {
|
||||
$query = \json_encode(array_merge(
|
||||
$package->premium,
|
||||
[
|
||||
@@ -588,16 +583,16 @@ class InstallCommand extends ConsoleCommand
|
||||
$error = str_replace("\n", "\n | '- ", $e->getMessage());
|
||||
$this->output->write("\x0D");
|
||||
// extra white spaces to clear out the buffer properly
|
||||
$this->output->writeln(" |- Downloading package... <red>error</red> ");
|
||||
$this->output->writeln(' |- Downloading package... <red>error</red> ');
|
||||
$this->output->writeln(" | '- " . $error);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Folder::mkdir($this->tmp);
|
||||
Folder::create($this->tmp);
|
||||
|
||||
$this->output->write("\x0D");
|
||||
$this->output->write(" |- Downloading package... 100%");
|
||||
$this->output->write(' |- Downloading package... 100%');
|
||||
$this->output->writeln('');
|
||||
|
||||
file_put_contents($this->tmp . DS . $filename, $output);
|
||||
@@ -606,7 +601,7 @@ class InstallCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -618,7 +613,7 @@ class InstallCommand extends ConsoleCommand
|
||||
|
||||
if (Installer::lastErrorCode() == Installer::IS_LINK) {
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Checking destination... <yellow>symbolic link</yellow>");
|
||||
$this->output->writeln(' |- Checking destination... <yellow>symbolic link</yellow>');
|
||||
|
||||
if ($this->all_yes) {
|
||||
$this->output->writeln(" | '- <yellow>Skipped automatically.</yellow>");
|
||||
@@ -634,13 +629,13 @@ class InstallCommand extends ConsoleCommand
|
||||
$this->output->writeln(" | '- <red>You decided to not delete the symlink automatically.</red>");
|
||||
|
||||
return false;
|
||||
} else {
|
||||
unlink($this->destination . DS . $package->install_path);
|
||||
}
|
||||
|
||||
unlink($this->destination . DS . $package->install_path);
|
||||
}
|
||||
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Checking destination... <green>ok</green>");
|
||||
$this->output->writeln(' |- Checking destination... <green>ok</green>');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -657,14 +652,14 @@ class InstallCommand extends ConsoleCommand
|
||||
{
|
||||
$type = $package->package_type;
|
||||
|
||||
Installer::install($this->file, $this->destination, ['install_path' => $package->install_path, 'theme' => (($type == 'themes')), 'is_update' => $is_update]);
|
||||
Installer::install($this->file, $this->destination, ['install_path' => $package->install_path, 'theme' => $type === 'themes', 'is_update' => $is_update]);
|
||||
$error_code = Installer::lastErrorCode();
|
||||
Folder::delete($this->tmp);
|
||||
|
||||
if ($error_code) {
|
||||
$this->output->write("\x0D");
|
||||
// extra white spaces to clear out the buffer properly
|
||||
$this->output->writeln(" |- Installing package... <red>error</red> ");
|
||||
$this->output->writeln(' |- Installing package... <red>error</red> ');
|
||||
$this->output->writeln(" | '- " . Installer::lastErrorMsg());
|
||||
|
||||
return false;
|
||||
@@ -674,23 +669,23 @@ class InstallCommand extends ConsoleCommand
|
||||
if ($message) {
|
||||
$this->output->write("\x0D");
|
||||
// extra white spaces to clear out the buffer properly
|
||||
$this->output->writeln(" |- " . $message);
|
||||
$this->output->writeln(" |- {$message}");
|
||||
}
|
||||
|
||||
$this->output->write("\x0D");
|
||||
// extra white spaces to clear out the buffer properly
|
||||
$this->output->writeln(" |- Installing package... <green>ok</green> ");
|
||||
$this->output->writeln(' |- Installing package... <green>ok</green> ');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $progress
|
||||
* @param array $progress
|
||||
*/
|
||||
public function progress($progress)
|
||||
{
|
||||
$this->output->write("\x0D");
|
||||
$this->output->write(" |- Downloading package... " . str_pad($progress['percent'], 5, " ",
|
||||
$this->output->write(' |- Downloading package... ' . str_pad($progress['percent'], 5, ' ',
|
||||
STR_PAD_LEFT) . '%');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Gpm
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Console\Gpm;
|
||||
|
||||
use Grav\Common\Cache;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\GPM\Installer;
|
||||
use Grav\Common\GPM\Remote\Package;
|
||||
use Grav\Common\GPM\Response;
|
||||
use Grav\Common\GPM\Upgrader;
|
||||
use Grav\Common\Grav;
|
||||
@@ -20,45 +23,33 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
class SelfupgradeCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
/** @var array */
|
||||
protected $data;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
protected $extensions;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
protected $updatable;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
protected $file;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
/** @var array */
|
||||
protected $types = ['plugins', 'themes'];
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
private $tmp;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
private $upgrader;
|
||||
|
||||
/** @var string */
|
||||
protected $all_yes;
|
||||
|
||||
protected $overwrite;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("self-upgrade")
|
||||
->setName('self-upgrade')
|
||||
->setAliases(['selfupgrade', 'selfupdate'])
|
||||
->addOption(
|
||||
'force',
|
||||
@@ -78,13 +69,10 @@ class SelfupgradeCommand extends ConsoleCommand
|
||||
InputOption::VALUE_NONE,
|
||||
'Option to overwrite packages if they already exist'
|
||||
)
|
||||
->setDescription("Detects and performs an update of Grav itself when available")
|
||||
->setDescription('Detects and performs an update of Grav itself when available')
|
||||
->setHelp('The <info>update</info> command updates Grav itself when a new version is available');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$this->upgrader = new Upgrader($this->input->getOption('force'));
|
||||
@@ -100,26 +88,26 @@ class SelfupgradeCommand extends ConsoleCommand
|
||||
$release = strftime('%c', strtotime($this->upgrader->getReleaseDate()));
|
||||
|
||||
if (!$this->upgrader->meetsRequirements()) {
|
||||
$this->output->writeln("<red>ATTENTION:</red>");
|
||||
$this->output->writeln(" Grav has increased the minimum PHP requirement.");
|
||||
$this->output->writeln(" You are currently running PHP <red>" . phpversion() . "</red>, but PHP <green>" . $this->upgrader->minPHPVersion() . "</green> is required.");
|
||||
$this->output->writeln(" Additional information: <white>http://getgrav.org/blog/changing-php-requirements</white>");
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln("Selfupgrade aborted.");
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('<red>ATTENTION:</red>');
|
||||
$this->output->writeln(' Grav has increased the minimum PHP requirement.');
|
||||
$this->output->writeln(' You are currently running PHP <red>' . phpversion() . '</red>, but PHP <green>' . $this->upgrader->minPHPVersion() . '</green> is required.');
|
||||
$this->output->writeln(' Additional information: <white>http://getgrav.org/blog/changing-php-requirements</white>');
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln('Selfupgrade aborted.');
|
||||
$this->output->writeln('');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$this->overwrite && !$this->upgrader->isUpgradable()) {
|
||||
$this->output->writeln("You are already running the latest version of Grav (v" . $local . ") released on " . $release);
|
||||
$this->output->writeln("You are already running the latest version of Grav (v{$local}) released on {$release}");
|
||||
exit;
|
||||
}
|
||||
|
||||
Installer::isValidDestination(GRAV_ROOT . '/system');
|
||||
if (Installer::IS_LINK === Installer::lastErrorCode()) {
|
||||
$this->output->writeln("<red>ATTENTION:</red> Grav is symlinked, cannot upgrade, aborting...");
|
||||
$this->output->writeln('<red>ATTENTION:</red> Grav is symlinked, cannot upgrade, aborting...');
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("You are currently running a symbolically linked Grav v" . $local . ". Latest available is v". $remote . ".");
|
||||
$this->output->writeln("You are currently running a symbolically linked Grav v{$local}. Latest available is v{$remote}.");
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -129,51 +117,51 @@ class SelfupgradeCommand extends ConsoleCommand
|
||||
$questionHelper = $this->getHelper('question');
|
||||
|
||||
|
||||
$this->output->writeln("Grav v<cyan>$remote</cyan> is now available [release date: $release].");
|
||||
$this->output->writeln("You are currently using v<cyan>" . GRAV_VERSION . "</cyan>.");
|
||||
$this->output->writeln("Grav v<cyan>{$remote}</cyan> is now available [release date: {$release}].");
|
||||
$this->output->writeln('You are currently using v<cyan>' . GRAV_VERSION . '</cyan>.');
|
||||
|
||||
if (!$this->all_yes) {
|
||||
$question = new ConfirmationQuestion("Would you like to read the changelog before proceeding? [y|N] ",
|
||||
$question = new ConfirmationQuestion('Would you like to read the changelog before proceeding? [y|N] ',
|
||||
false);
|
||||
$answer = $questionHelper->ask($this->input, $this->output, $question);
|
||||
|
||||
if ($answer) {
|
||||
$changelog = $this->upgrader->getChangelog(GRAV_VERSION);
|
||||
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('');
|
||||
foreach ($changelog as $version => $log) {
|
||||
$title = $version . ' [' . $log['date'] . ']';
|
||||
$content = preg_replace_callback('/\d\.\s\[\]\(#(.*)\)/', function ($match) {
|
||||
return "\n" . ucfirst($match[1]) . ":";
|
||||
return "\n" . ucfirst($match[1]) . ':';
|
||||
}, $log['content']);
|
||||
|
||||
$this->output->writeln($title);
|
||||
$this->output->writeln(str_repeat('-', strlen($title)));
|
||||
$this->output->writeln(str_repeat('-', \strlen($title)));
|
||||
$this->output->writeln($content);
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('');
|
||||
}
|
||||
|
||||
$question = new ConfirmationQuestion("Press [ENTER] to continue.", true);
|
||||
$question = new ConfirmationQuestion('Press [ENTER] to continue.', true);
|
||||
$questionHelper->ask($this->input, $this->output, $question);
|
||||
}
|
||||
|
||||
$question = new ConfirmationQuestion("Would you like to upgrade now? [y|N] ", false);
|
||||
$question = new ConfirmationQuestion('Would you like to upgrade now? [y|N] ', false);
|
||||
$answer = $questionHelper->ask($this->input, $this->output, $question);
|
||||
|
||||
if (!$answer) {
|
||||
$this->output->writeln("Aborting...");
|
||||
$this->output->writeln('Aborting...');
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln("Preparing to upgrade to v<cyan>$remote</cyan>..");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("Preparing to upgrade to v<cyan>{$remote}</cyan>..");
|
||||
|
||||
$this->output->write(" |- Downloading upgrade [" . $this->formatBytes($update['size']) . "]... 0%");
|
||||
$this->output->write(" |- Downloading upgrade [{$this->formatBytes($update['size'])}]... 0%");
|
||||
$this->file = $this->download($update);
|
||||
|
||||
$this->output->write(" |- Installing upgrade... ");
|
||||
$this->output->write(' |- Installing upgrade... ');
|
||||
$installation = $this->upgrade();
|
||||
|
||||
if (!$installation) {
|
||||
@@ -189,20 +177,20 @@ class SelfupgradeCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $package
|
||||
* @param Package $package
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function download($package)
|
||||
{
|
||||
$tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
|
||||
$this->tmp = $tmp_dir . '/Grav-' . uniqid();
|
||||
$this->tmp = $tmp_dir . '/Grav-' . uniqid('', false);
|
||||
$output = Response::get($package['download'], [], [$this, 'progress']);
|
||||
|
||||
Folder::mkdir($this->tmp);
|
||||
Folder::create($this->tmp);
|
||||
|
||||
$this->output->write("\x0D");
|
||||
$this->output->write(" |- Downloading upgrade [" . $this->formatBytes($package['size']) . "]... 100%");
|
||||
$this->output->write(" |- Downloading upgrade [{$this->formatBytes($package['size'])}]... 100%");
|
||||
$this->output->writeln('');
|
||||
|
||||
file_put_contents($this->tmp . DS . $package['name'], $output);
|
||||
@@ -215,15 +203,24 @@ class SelfupgradeCommand extends ConsoleCommand
|
||||
*/
|
||||
private function upgrade()
|
||||
{
|
||||
Installer::install($this->file, GRAV_ROOT,
|
||||
['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true]);
|
||||
if ($this->file) {
|
||||
$folder = Installer::unZip($this->file, $this->tmp . '/zip');
|
||||
} else {
|
||||
$folder = false;
|
||||
}
|
||||
|
||||
static::upgradeGrav($this->file, $folder);
|
||||
|
||||
$errorCode = Installer::lastErrorCode();
|
||||
Folder::delete($this->tmp);
|
||||
|
||||
if ($this->tmp) {
|
||||
Folder::delete($this->tmp);
|
||||
}
|
||||
|
||||
if ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) {
|
||||
$this->output->write("\x0D");
|
||||
// extra white spaces to clear out the buffer properly
|
||||
$this->output->writeln(" |- Installing upgrade... <red>error</red> ");
|
||||
$this->output->writeln(' |- Installing upgrade... <red>error</red> ');
|
||||
$this->output->writeln(" | '- " . Installer::lastErrorMsg());
|
||||
|
||||
return false;
|
||||
@@ -231,23 +228,23 @@ class SelfupgradeCommand extends ConsoleCommand
|
||||
|
||||
$this->output->write("\x0D");
|
||||
// extra white spaces to clear out the buffer properly
|
||||
$this->output->writeln(" |- Installing upgrade... <green>ok</green> ");
|
||||
$this->output->writeln(' |- Installing upgrade... <green>ok</green> ');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $progress
|
||||
* @param array $progress
|
||||
*/
|
||||
public function progress($progress)
|
||||
{
|
||||
$this->output->write("\x0D");
|
||||
$this->output->write(" |- Downloading upgrade [" . $this->formatBytes($progress["filesize"]) . "]... " . str_pad($progress['percent'],
|
||||
5, " ", STR_PAD_LEFT) . '%');
|
||||
$this->output->write(" |- Downloading upgrade [{$this->formatBytes($progress['filesize']) }]... " . str_pad($progress['percent'],
|
||||
5, ' ', STR_PAD_LEFT) . '%');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $size
|
||||
* @param int|float $size
|
||||
* @param int $precision
|
||||
*
|
||||
* @return string
|
||||
@@ -257,6 +254,44 @@ class SelfupgradeCommand extends ConsoleCommand
|
||||
$base = log($size) / log(1024);
|
||||
$suffixes = array('', 'k', 'M', 'G', 'T');
|
||||
|
||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[(int)floor($base)];
|
||||
return round(1024 ** ($base - floor($base)), $precision) . $suffixes[(int)floor($base)];
|
||||
}
|
||||
|
||||
private function upgradeGrav($zip, $folder, $keepFolder = false)
|
||||
{
|
||||
static $ignores = [
|
||||
'backup',
|
||||
'cache',
|
||||
'images',
|
||||
'logs',
|
||||
'tmp',
|
||||
'user',
|
||||
'.htaccess',
|
||||
'robots.txt'
|
||||
];
|
||||
|
||||
if (!is_dir($folder)) {
|
||||
Installer::setError('Invalid source folder');
|
||||
}
|
||||
|
||||
try {
|
||||
$script = $folder . '/system/install.php';
|
||||
/** Install $installer */
|
||||
if ((file_exists($script) && $install = include $script) && is_callable($install)) {
|
||||
$install($zip);
|
||||
} else {
|
||||
Installer::install(
|
||||
$zip,
|
||||
GRAV_ROOT,
|
||||
['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true, 'ignores' => $ignores],
|
||||
$folder,
|
||||
$keepFolder
|
||||
);
|
||||
|
||||
Cache::clearCache();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Installer::setError($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Gpm
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -10,6 +11,7 @@ namespace Grav\Console\Gpm;
|
||||
|
||||
use Grav\Common\GPM\GPM;
|
||||
use Grav\Common\GPM\Installer;
|
||||
use Grav\Common\GPM\Remote\Package;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Console\ConsoleCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
@@ -18,38 +20,31 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
class UninstallCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
/** @var array */
|
||||
protected $data;
|
||||
|
||||
/** @var GPM */
|
||||
protected $gpm;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
/** @var string */
|
||||
protected $destination;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
protected $file;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
protected $tmp;
|
||||
|
||||
protected $dependencies= [];
|
||||
/** @var array */
|
||||
protected $dependencies = [];
|
||||
|
||||
/** @var string */
|
||||
protected $all_yes;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("uninstall")
|
||||
->setName('uninstall')
|
||||
->addOption(
|
||||
'all-yes',
|
||||
'y',
|
||||
@@ -61,13 +56,10 @@ class UninstallCommand extends ConsoleCommand
|
||||
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
|
||||
'The package(s) that are desired to be removed. Use the "index" command for a list of packages'
|
||||
)
|
||||
->setDescription("Performs the uninstallation of plugins and themes")
|
||||
->setDescription('Performs the uninstallation of plugins and themes')
|
||||
->setHelp('The <info>uninstall</info> command allows to uninstall plugins and themes');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$this->gpm = new GPM();
|
||||
@@ -77,37 +69,38 @@ class UninstallCommand extends ConsoleCommand
|
||||
$packages = array_map('strtolower', $this->input->getArgument('package'));
|
||||
$this->data = ['total' => 0, 'not_found' => []];
|
||||
|
||||
$total = 0;
|
||||
foreach ($packages as $package) {
|
||||
$plugin = $this->gpm->getInstalledPlugin($package);
|
||||
$theme = $this->gpm->getInstalledTheme($package);
|
||||
if ($plugin || $theme) {
|
||||
$this->data[strtolower($package)] = $plugin ?: $theme;
|
||||
$this->data['total']++;
|
||||
$total++;
|
||||
} else {
|
||||
$this->data['not_found'][] = $package;
|
||||
}
|
||||
}
|
||||
$this->data['total'] = $total;
|
||||
|
||||
$this->output->writeln('');
|
||||
|
||||
if (!$this->data['total']) {
|
||||
$this->output->writeln("Nothing to uninstall.");
|
||||
$this->output->writeln('Nothing to uninstall.');
|
||||
$this->output->writeln('');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($this->data['not_found'])) {
|
||||
$this->output->writeln("These packages were not found installed: <red>" . implode('</red>, <red>',
|
||||
$this->data['not_found']) . "</red>");
|
||||
$this->output->writeln('These packages were not found installed: <red>' . implode('</red>, <red>',
|
||||
$this->data['not_found']) . '</red>');
|
||||
}
|
||||
|
||||
unset($this->data['not_found']);
|
||||
unset($this->data['total']);
|
||||
unset($this->data['not_found'], $this->data['total']);
|
||||
|
||||
foreach ($this->data as $slug => $package) {
|
||||
$this->output->writeln("Preparing to uninstall <cyan>" . $package->name . "</cyan> [v" . $package->version . "]");
|
||||
$this->output->writeln("Preparing to uninstall <cyan>{$package->name}</cyan> [v{$package->version}]");
|
||||
|
||||
$this->output->write(" |- Checking destination... ");
|
||||
$this->output->write(' |- Checking destination... ');
|
||||
$checks = $this->checkDestination($slug, $package);
|
||||
|
||||
if (!$checks) {
|
||||
@@ -131,8 +124,8 @@ class UninstallCommand extends ConsoleCommand
|
||||
|
||||
|
||||
/**
|
||||
* @param $slug
|
||||
* @param $package
|
||||
* @param string $slug
|
||||
* @param Package $package
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -147,12 +140,12 @@ class UninstallCommand extends ConsoleCommand
|
||||
if (count($dependent_packages) > ($is_dependency ? 1 : 0)) {
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("<red>Uninstallation failed.</red>");
|
||||
$this->output->writeln('<red>Uninstallation failed.</red>');
|
||||
$this->output->writeln('');
|
||||
if (count($dependent_packages) > ($is_dependency ? 2 : 1)) {
|
||||
$this->output->writeln("The installed packages <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove those first.");
|
||||
if (\count($dependent_packages) > ($is_dependency ? 2 : 1)) {
|
||||
$this->output->writeln('The installed packages <cyan>' . implode('</cyan>, <cyan>', $dependent_packages) . '</cyan> depends on this package. Please remove those first.');
|
||||
} else {
|
||||
$this->output->writeln("The installed package <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove it first.");
|
||||
$this->output->writeln('The installed package <cyan>' . implode('</cyan>, <cyan>', $dependent_packages) . '</cyan> depends on this package. Please remove it first.');
|
||||
}
|
||||
|
||||
$this->output->writeln('');
|
||||
@@ -165,12 +158,12 @@ class UninstallCommand extends ConsoleCommand
|
||||
|
||||
if ($is_dependency) {
|
||||
foreach ($dependencies as $key => $dependency) {
|
||||
if (in_array($dependency['name'], $this->dependencies)) {
|
||||
if (\in_array($dependency['name'], $this->dependencies, true)) {
|
||||
unset($dependencies[$key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (count($dependencies) > 0) {
|
||||
if (\count($dependencies) > 0) {
|
||||
$this->output->writeln(' `- Dependencies found...');
|
||||
$this->output->writeln('');
|
||||
}
|
||||
@@ -182,7 +175,7 @@ class UninstallCommand extends ConsoleCommand
|
||||
|
||||
$this->dependencies[] = $dependency['name'];
|
||||
|
||||
if (is_array($dependency)) {
|
||||
if (\is_array($dependency)) {
|
||||
$dependency = $dependency['name'];
|
||||
}
|
||||
if ($dependency === 'grav' || $dependency === 'php') {
|
||||
@@ -194,9 +187,9 @@ class UninstallCommand extends ConsoleCommand
|
||||
$dependency_exists = $this->packageExists($dependency, $dependencyPackage);
|
||||
|
||||
if ($dependency_exists == Installer::EXISTS) {
|
||||
$this->output->writeln("A dependency on <cyan>" . $dependencyPackage->name . "</cyan> [v" . $dependencyPackage->version . "] was found");
|
||||
$this->output->writeln("A dependency on <cyan>{$dependencyPackage->name}</cyan> [v{$dependencyPackage->version}] was found");
|
||||
|
||||
$question = new ConfirmationQuestion(" |- Uninstall <cyan>" . $dependencyPackage->name . "</cyan>? [y|N] ", false);
|
||||
$question = new ConfirmationQuestion(" |- Uninstall <cyan>{$dependencyPackage->name}</cyan>? [y|N] ", false);
|
||||
$answer = $this->all_yes ? true : $questionHelper->ask($this->input, $this->output, $question);
|
||||
|
||||
if ($answer) {
|
||||
@@ -210,7 +203,7 @@ class UninstallCommand extends ConsoleCommand
|
||||
}
|
||||
$this->output->writeln('');
|
||||
} else {
|
||||
$this->output->writeln(" '- <yellow>You decided not to uninstall " . $dependencyPackage->name . ".</yellow>");
|
||||
$this->output->writeln(" '- <yellow>You decided not to uninstall {$dependencyPackage->name}.</yellow>");
|
||||
$this->output->writeln('');
|
||||
}
|
||||
}
|
||||
@@ -225,21 +218,21 @@ class UninstallCommand extends ConsoleCommand
|
||||
$errorCode = Installer::lastErrorCode();
|
||||
|
||||
if ($errorCode && $errorCode !== Installer::IS_LINK && $errorCode !== Installer::EXISTS) {
|
||||
$this->output->writeln(" |- Uninstalling " . $package->name . " package... <red>error</red> ");
|
||||
$this->output->writeln(" | '- <yellow>" . Installer::lastErrorMsg()."</yellow>");
|
||||
$this->output->writeln(" |- Uninstalling {$package->name} package... <red>error</red> ");
|
||||
$this->output->writeln(" | '- <yellow>" . Installer::lastErrorMsg() . '</yellow>');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$message = Installer::getMessage();
|
||||
if ($message) {
|
||||
$this->output->writeln(" |- " . $message);
|
||||
$this->output->writeln(" |- {$message}");
|
||||
}
|
||||
|
||||
if (!$is_dependency && $this->dependencies) {
|
||||
$this->output->writeln("Finishing up uninstalling <cyan>" . $package->name . "</cyan>");
|
||||
$this->output->writeln("Finishing up uninstalling <cyan>{$package->name}</cyan>");
|
||||
}
|
||||
$this->output->writeln(" |- Uninstalling " . $package->name . " package... <green>ok</green> ");
|
||||
$this->output->writeln(" |- Uninstalling {$package->name} package... <green>ok</green> ");
|
||||
|
||||
|
||||
|
||||
@@ -247,8 +240,8 @@ class UninstallCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $slug
|
||||
* @param $package
|
||||
* @param string $slug
|
||||
* @param Package $package
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -261,7 +254,7 @@ class UninstallCommand extends ConsoleCommand
|
||||
|
||||
if ($exists == Installer::IS_LINK) {
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Checking destination... <yellow>symbolic link</yellow>");
|
||||
$this->output->writeln(' |- Checking destination... <yellow>symbolic link</yellow>');
|
||||
|
||||
if ($this->all_yes) {
|
||||
$this->output->writeln(" | '- <yellow>Skipped automatically.</yellow>");
|
||||
@@ -281,7 +274,7 @@ class UninstallCommand extends ConsoleCommand
|
||||
}
|
||||
|
||||
$this->output->write("\x0D");
|
||||
$this->output->writeln(" |- Checking destination... <green>ok</green>");
|
||||
$this->output->writeln(' |- Checking destination... <green>ok</green>');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -289,8 +282,8 @@ class UninstallCommand extends ConsoleCommand
|
||||
/**
|
||||
* Check if package exists
|
||||
*
|
||||
* @param $slug
|
||||
* @param $package
|
||||
* @param string $slug
|
||||
* @param Package $package
|
||||
* @return int
|
||||
*/
|
||||
private function packageExists($slug, $package)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Gpm
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -19,51 +20,37 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
class UpdateCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
/** @var array */
|
||||
protected $data;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
protected $extensions;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
protected $updatable;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
protected $destination;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
protected $file;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
/** @var array */
|
||||
protected $types = ['plugins', 'themes'];
|
||||
/**
|
||||
* @var GPM $gpm
|
||||
*/
|
||||
|
||||
/** @var GPM */
|
||||
protected $gpm;
|
||||
|
||||
/** @var string */
|
||||
protected $all_yes;
|
||||
|
||||
protected $overwrite;
|
||||
|
||||
/**
|
||||
* @var Upgrader
|
||||
*/
|
||||
/** @var Upgrader */
|
||||
protected $upgrader;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("update")
|
||||
->setName('update')
|
||||
->addOption(
|
||||
'force',
|
||||
'f',
|
||||
@@ -106,27 +93,24 @@ class UpdateCommand extends ConsoleCommand
|
||||
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
|
||||
'The package or packages that is desired to update. By default all available updates will be applied.'
|
||||
)
|
||||
->setDescription("Detects and performs an update of plugins and themes when available")
|
||||
->setDescription('Detects and performs an update of plugins and themes when available')
|
||||
->setHelp('The <info>update</info> command updates plugins and themes when a new version is available');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|void
|
||||
*/
|
||||
protected function serve()
|
||||
{
|
||||
$this->upgrader = new Upgrader($this->input->getOption('force'));
|
||||
$local = $this->upgrader->getLocalVersion();
|
||||
$remote = $this->upgrader->getRemoteVersion();
|
||||
if ($local !== $remote) {
|
||||
$this->output->writeln("<yellow>WARNING</yellow>: A new version of Grav is available. You should update Grav before updating plugins and themes. If you continue without updating Grav, some plugins or themes may stop working.");
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('<yellow>WARNING</yellow>: A new version of Grav is available. You should update Grav before updating plugins and themes. If you continue without updating Grav, some plugins or themes may stop working.');
|
||||
$this->output->writeln('');
|
||||
$questionHelper = $this->getHelper('question');
|
||||
$question = new ConfirmationQuestion("Continue with the update process? [Y|n] ", true);
|
||||
$question = new ConfirmationQuestion('Continue with the update process? [Y|n] ', true);
|
||||
$answer = $questionHelper->ask($this->input, $this->output, $question);
|
||||
|
||||
if (!$answer) {
|
||||
$this->output->writeln("<red>Update aborted. Exiting...</red>");
|
||||
$this->output->writeln('<red>Update aborted. Exiting...</red>');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -141,7 +125,7 @@ class UpdateCommand extends ConsoleCommand
|
||||
$this->destination = realpath($this->input->getOption('destination'));
|
||||
|
||||
if (!Installer::isGravInstance($this->destination)) {
|
||||
$this->output->writeln("<red>ERROR</red>: " . Installer::lastErrorMsg());
|
||||
$this->output->writeln('<red>ERROR</red>: ' . Installer::lastErrorMsg());
|
||||
exit;
|
||||
}
|
||||
if ($this->input->getOption('plugins') === false && $this->input->getOption('themes') === false) {
|
||||
@@ -153,27 +137,26 @@ class UpdateCommand extends ConsoleCommand
|
||||
|
||||
if ($this->overwrite) {
|
||||
$this->data = $this->gpm->getInstallable($list_type);
|
||||
$description = " can be overwritten";
|
||||
$description = ' can be overwritten';
|
||||
} else {
|
||||
$this->data = $this->gpm->getUpdatable($list_type);
|
||||
$description = " need updating";
|
||||
$description = ' need updating';
|
||||
}
|
||||
|
||||
$only_packages = array_map('strtolower', $this->input->getArgument('package'));
|
||||
|
||||
if (!$this->overwrite && !$this->data['total']) {
|
||||
$this->output->writeln("Nothing to update.");
|
||||
$this->output->writeln('Nothing to update.');
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->output->write("Found <green>" . $this->gpm->countInstalled() . "</green> packages installed of which <magenta>" . $this->data['total'] . "</magenta>" . $description);
|
||||
$this->output->write("Found <green>{$this->gpm->countInstalled()}</green> packages installed of which <magenta>{$this->data['total']}</magenta>{$description}");
|
||||
|
||||
$limit_to = $this->userInputPackages($only_packages);
|
||||
|
||||
$this->output->writeln('');
|
||||
|
||||
unset($this->data['total']);
|
||||
unset($limit_to['total']);
|
||||
unset($this->data['total'], $limit_to['total']);
|
||||
|
||||
|
||||
// updates review
|
||||
@@ -182,7 +165,7 @@ class UpdateCommand extends ConsoleCommand
|
||||
$index = 0;
|
||||
foreach ($this->data as $packages) {
|
||||
foreach ($packages as $slug => $package) {
|
||||
if (count($only_packages) && !array_key_exists($slug, $limit_to)) {
|
||||
if (!array_key_exists($slug, $limit_to) && \count($only_packages)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -192,11 +175,11 @@ class UpdateCommand extends ConsoleCommand
|
||||
|
||||
$this->output->writeln(
|
||||
// index
|
||||
str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . ". " .
|
||||
str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . '. ' .
|
||||
// name
|
||||
"<cyan>" . str_pad($package->name, 15) . "</cyan> " .
|
||||
'<cyan>' . str_pad($package->name, 15) . '</cyan> ' .
|
||||
// version
|
||||
"[v<magenta>" . $package->version . "</magenta> -> v<green>" . $package->available . "</green>]"
|
||||
"[v<magenta>{$package->version}</magenta> -> v<green>{$package->available}</green>]"
|
||||
);
|
||||
$slugs[] = $slug;
|
||||
}
|
||||
@@ -204,13 +187,13 @@ class UpdateCommand extends ConsoleCommand
|
||||
|
||||
if (!$this->all_yes) {
|
||||
// prompt to continue
|
||||
$this->output->writeln("");
|
||||
$this->output->writeln('');
|
||||
$questionHelper = $this->getHelper('question');
|
||||
$question = new ConfirmationQuestion("Continue with the update process? [Y|n] ", true);
|
||||
$question = new ConfirmationQuestion('Continue with the update process? [Y|n] ', true);
|
||||
$answer = $questionHelper->ask($this->input, $this->output, $question);
|
||||
|
||||
if (!$answer) {
|
||||
$this->output->writeln("<red>Update aborted. Exiting...</red>");
|
||||
$this->output->writeln('<red>Update aborted. Exiting...</red>');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -228,13 +211,13 @@ class UpdateCommand extends ConsoleCommand
|
||||
$command_exec = $install_command->run($args, $this->output);
|
||||
|
||||
if ($command_exec != 0) {
|
||||
$this->output->writeln("<red>Error:</red> An error occurred while trying to install the packages");
|
||||
$this->output->writeln('<red>Error:</red> An error occurred while trying to install the packages');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $only_packages
|
||||
* @param array $only_packages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -243,14 +226,14 @@ class UpdateCommand extends ConsoleCommand
|
||||
$found = ['total' => 0];
|
||||
$ignore = [];
|
||||
|
||||
if (!count($only_packages)) {
|
||||
if (!\count($only_packages)) {
|
||||
$this->output->writeln('');
|
||||
} else {
|
||||
foreach ($only_packages as $only_package) {
|
||||
$find = $this->gpm->findPackage($only_package);
|
||||
|
||||
if (!$find || (!$this->overwrite && !$this->gpm->isUpdatable($find->slug))) {
|
||||
$name = isset($find->slug) ? $find->slug : $only_package;
|
||||
$name = $find->slug ?? $only_package;
|
||||
$ignore[$name] = $name;
|
||||
} else {
|
||||
$found[$find->slug] = $find;
|
||||
@@ -264,18 +247,18 @@ class UpdateCommand extends ConsoleCommand
|
||||
$list = array_keys($list);
|
||||
|
||||
if ($found['total'] !== $this->data['total']) {
|
||||
$this->output->write(", only <magenta>" . $found['total'] . "</magenta> will be updated");
|
||||
$this->output->write(", only <magenta>{$found['total']}</magenta> will be updated");
|
||||
}
|
||||
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("Limiting updates for only <cyan>" . implode('</cyan>, <cyan>',
|
||||
$list) . "</cyan>");
|
||||
$this->output->writeln('Limiting updates for only <cyan>' . implode('</cyan>, <cyan>',
|
||||
$list) . '</cyan>');
|
||||
}
|
||||
|
||||
if (count($ignore)) {
|
||||
if (\count($ignore)) {
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("Packages not found or not requiring updates: <red>" . implode('</red>, <red>',
|
||||
$ignore) . "</red>");
|
||||
$this->output->writeln('Packages not found or not requiring updates: <red>' . implode('</red>, <red>',
|
||||
$ignore) . '</red>');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\Gpm
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
@@ -17,18 +18,13 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class VersionCommand extends ConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var GPM
|
||||
*/
|
||||
/** @var GPM */
|
||||
protected $gpm;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("version")
|
||||
->setName('version')
|
||||
->addOption(
|
||||
'force',
|
||||
'f',
|
||||
@@ -40,7 +36,7 @@ class VersionCommand extends ConsoleCommand
|
||||
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
|
||||
'The package or packages that is desired to know the version of. By default and if not specified this would be grav'
|
||||
)
|
||||
->setDescription("Shows the version of an installed package. If available also shows pending updates.")
|
||||
->setDescription('Shows the version of an installed package. If available also shows pending updates.')
|
||||
->setHelp('The <info>version</info> command displays the current version of a package installed and, if available, the available version of pending updates');
|
||||
}
|
||||
|
||||
@@ -64,13 +60,13 @@ class VersionCommand extends ConsoleCommand
|
||||
$version = null;
|
||||
$updatable = false;
|
||||
|
||||
if ($package == 'grav') {
|
||||
if ($package === 'grav') {
|
||||
$name = 'Grav';
|
||||
$version = GRAV_VERSION;
|
||||
$upgrader = new Upgrader();
|
||||
|
||||
if ($upgrader->isUpgradable()) {
|
||||
$updatable = ' [upgradable: v<green>' . $upgrader->getRemoteVersion() . '</green>]';
|
||||
$updatable = " [upgradable: v<green>{$upgrader->getRemoteVersion()}</green>]";
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -99,17 +95,17 @@ class VersionCommand extends ConsoleCommand
|
||||
$name = $installed->name;
|
||||
|
||||
if ($this->gpm->isUpdatable($package)) {
|
||||
$updatable = ' [updatable: v<green>' . $installed->available . '</green>]';
|
||||
$updatable = " [updatable: v<green>{$installed->available}</green>]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$updatable = $updatable ?: '';
|
||||
|
||||
if ($installed || $package == 'grav') {
|
||||
$this->output->writeln('You are running <white>' . $name . '</white> v<cyan>' . $version . '</cyan>' . $updatable);
|
||||
if ($installed || $package === 'grav') {
|
||||
$this->output->writeln("You are running <white>{$name}</white> v<cyan>{$version}</cyan>{$updatable}");
|
||||
} else {
|
||||
$this->output->writeln('Package <red>' . $package . '</red> not found');
|
||||
$this->output->writeln("Package <red>{$package}</red> not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav.Console
|
||||
* @package Grav\Console\TerminalObjects
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user