Skip to content

Commit

Permalink
[debug:update:composer] Add new command (#4105)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjuarez20 authored and enzolutions committed Jun 27, 2019
1 parent 05d4f8f commit 79c425e
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 4 deletions.
71 changes: 71 additions & 0 deletions src/Command/Debug/UpdateComposerCommand.php
Original file line number Diff line number Diff line change
@@ -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'));
}
}
}
46 changes: 42 additions & 4 deletions src/Command/Shared/UpdateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
trait UpdateTrait
{
/**
* @param $updates
* @param $messageKey
* @param array $updates
* @param string $messageKey
* @return mixed
*/
public function showUpdateTable($updates, $messageKey)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions uninstall.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 79c425e

Please sign in to comment.