Skip to content

Commit

Permalink
Add new commands to process features. (#3021)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel303 authored and jmolivas committed Dec 17, 2016
1 parent 259019c commit d5da57d
Show file tree
Hide file tree
Showing 4 changed files with 415 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/services/drupal-console/feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
feature_debug:
class: Drupal\Console\Command\Features\DebugCommand
tags:
- { name: drupal.command }
feature_import:
class: Drupal\Console\Command\Features\ImportCommand
tags:
- { name: drupal.command }
77 changes: 77 additions & 0 deletions src/Command/Features/DebugCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/**
* @file
* Contains \Drupal\Console\Command\Features\DebugCommand.
*/

namespace Drupal\Console\Command\Features;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Command\Shared\FeatureTrait;
use Drupal\Console\Command\Shared\CommandTrait;
use Drupal\Console\Style\DrupalStyle;
use Drupal\Console\Annotations\DrupalCommand;
use Symfony\Component\Console\Command\Command;


/**
* @DrupalCommand(
* extension = "features",
* extensionType = "module"
* )
*/

class DebugCommand extends Command
{
use CommandTrait;
use FeatureTrait;



public function __construct()
{
parent::__construct();
}

protected function configure()
{
$this
->setName('features:debug')
->setDescription($this->trans('commands.features.debug.description'))
->addArgument(
'bundle',
InputArgument::OPTIONAL,
$this->trans('commands.features.debug.arguments.bundle')
);

}

protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$bundle= $input->getArgument('bundle');

$tableHeader = [
$this->trans('commands.features.debug.messages.bundle'),
$this->trans('commands.features.debug.messages.name'),
$this->trans('commands.features.debug.messages.machine_name'),
$this->trans('commands.features.debug.messages.status'),
$this->trans('commands.features.debug.messages.state'),
];

$tableRows = [];

$features = $this->getFeatureList($bundle);

foreach ($features as $feature) {
$tableRows[] = [$feature['bundle_name'],$feature['name'], $feature['machine_name'], $feature['status'],$feature['state']];
}

$io->table($tableHeader, $tableRows, 'compact');
}


}
88 changes: 88 additions & 0 deletions src/Command/Features/ImportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/**
* @file
* Contains \Drupal\Console\Command\Features\ImportCommand.
*/

namespace Drupal\Console\Command\Features;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Command\Shared\FeatureTrait;
use Drupal\Console\Command\Shared\CommandTrait;
use Drupal\Console\Style\DrupalStyle;
use Drupal\Console\Annotations\DrupalCommand;
use Symfony\Component\Console\Command\Command;


/**
* @DrupalCommand(
* extension = "features_ui",
* extensionType = "module"
* )
*/

class ImportCommand extends Command
{
use CommandTrait;
use FeatureTrait;



public function __construct()
{
parent::__construct();
}

protected function configure()
{
$this
->setName('features:import')
->setDescription($this->trans('commands.features.import.description'))
->addOption(
'bundle',
'',
InputOption::VALUE_OPTIONAL,
$this->trans('commands.features.import.options.packages')
)
->addArgument('packages',InputArgument::IS_ARRAY,$this->trans('commands.features.import.arguments.packages'));


}

protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$packages = $input->getArgument('packages');
$bundle = $input->getOption('bundle');

if ($bundle) {
$packages = $this->getPackagesByBundle($bundle);
}

$this->getAssigner($bundle);
$this->importFeature($io,$packages);

}
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$packages = $input->getArgument('packages');
$bundle = $input->getOption('bundle');

if (!$packages && !$bundle) {
// @see Drupal\Console\Command\Shared\FeatureTrait::packageQuestion
$bundle = $this->packageQuestion($io);
$input->setArgument('packages', $bundle);
}
}

}
Loading

0 comments on commit d5da57d

Please sign in to comment.