Skip to content
Permalink
Browse files

[debug:update:composer] Add new command (#4105)

  • Loading branch information...
harold20 authored and enzolutions committed Jun 27, 2019
1 parent 05d4f8f commit 79c425e89ddeefe132dbdcfdb56b04ae4ed8f43b
Showing with 118 additions and 4 deletions.
  1. +71 −0 src/Command/Debug/UpdateComposerCommand.php
  2. +42 −4 src/Command/Shared/UpdateTrait.php
  3. +5 −0 uninstall.services.yml
@@ -0,0 +1,71 @@
<?php
/**
* @file
* Contains \Drupal\Console\Command\Debug\UpdateComposerCommand.
*/
namespace Drupal\Console\Command\Debug;
use Drupal\Console\Command\Shared\UpdateTrait;
use Drupal\Console\Core\Utils\DrupalFinder;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
use Symfony\Component\Process\Process;
class UpdateComposerCommand extends Command
{
use UpdateTrait;
/**
* @var DrupalFinder
*/
protected $drupalFinder;
/**
* DebugComposerCommand constructor.
*
* @param DrupalFinder $drupalFinder
*/
public function __construct(DrupalFinder $drupalFinder) {
$this->drupalFinder = $drupalFinder;
parent::__construct();
}
/**
* @inheritdoc
*/
protected function configure()
{
$this
->setName('debug:update:composer')
->setDescription($this->trans('commands.debug.update.composer.description'))
->addOption(
'only-drupal',
null,
InputOption::VALUE_NONE,
$this->trans('commands.debug.update.composer.options.only-drupal')
)
->setAliases(['duc']);
}
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$onlyDrupal = $input->getOption('only-drupal');
$process = new Process("composer show --outdated --format=json");
$process->setTimeout(null);
$process->setWorkingDirectory($this->drupalFinder->getComposerRoot());
$process->run();
if($process->isSuccessful()){
$jsonData = json_decode($process->getOutput());
$this->showComposerUpdateTable($jsonData->installed, $onlyDrupal, $this->trans('commands.debug.update.composer.messages.composer-list'));
}
}
}
@@ -10,8 +10,8 @@
trait UpdateTrait
{
/**
* @param $updates
* @param $messageKey
* @param array $updates
* @param string $messageKey
* @return mixed
*/
public function showUpdateTable($updates, $messageKey)
@@ -41,8 +41,8 @@ public function showUpdateTable($updates, $messageKey)
}
/**
* @param $postUpdates
* @param $messageKey
* @param array $postUpdates
* @param string $messageKey
* @return mixed
*/
public function showPostUpdateTable($postUpdates, $messageKey)
@@ -70,4 +70,42 @@ public function showPostUpdateTable($postUpdates, $messageKey)
}
$this->getIo()->table($tableHeader, $tableRows);
}
/**
* @param array $composerUpdates
* @param boolean $onlyDrupal
* @param string $messageKey
* @return mixed
*/
public function showComposerUpdateTable($composerUpdates, $onlyDrupal, $messageKey)
{
if(!$composerUpdates) {
return 1;
}
$this->getIo()->info($messageKey);
$tableHeader = [
$this->trans('commands.debug.update.composer.messages.name'),
$this->trans('commands.debug.update.composer.messages.current-version'),
$this->trans('commands.debug.update.composer.messages.latest-version'),
$this->trans('commands.debug.update.composer.messages.description')
];
$tableRows = [];
foreach ($composerUpdates as $key => $values) {
if($onlyDrupal){
if(strpos($values->name, 'drupal/') === false ){
continue;
}
}
$tableRows[] = [
$values->name,
$values->version,
$values->latest,
$values->description,
];
}
$this->getIo()->table($tableHeader, $tableRows);
}
}
@@ -49,6 +49,11 @@ services:
arguments: ['@console.docker_init_generator']
tags:
- { name: drupal.command }
console.composer_update_debug:
class: Drupal\Console\Command\Debug\UpdateComposerCommand
arguments: ['@console.drupal_finder']
tags:
- { name: drupal.command }
# Generators
console.dotenv_init_generator:
class: Drupal\Console\Generator\DotenvInitGenerator

0 comments on commit 79c425e

Please sign in to comment.
You can’t perform that action at this time.