Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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