namespace Drupal\Console\Command\Module;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
use Drupal\Console\Extension\Manager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\Command;
use Drupal\Console\Command\Shared\ProjectDownloadTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Utils\Site;
-use Drupal\Core\ProxyClass\Extension\ModuleInstaller;
+use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Console\Core\Utils\ChainQueue;
-use Drupal\Core\Config\ConfigFactory;
+use Drupal\Core\Config\ConfigFactoryInterface;
class UninstallCommand extends Command
{
- use CommandTrait;
use ProjectDownloadTrait;
/**
*/
public function __construct(
Site $site,
- ModuleInstaller $moduleInstaller,
+ ModuleInstallerInterface $moduleInstaller,
ChainQueue $chainQueue,
- ConfigFactory $configFactory,
+ ConfigFactoryInterface $configFactory,
Manager $extensionManager
) {
$this->site = $site;
null,
InputOption::VALUE_NONE,
$this->trans('commands.module.uninstall.options.composer')
- );
+ )
+ ->setAliases(['mou']);
}
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
$module = $input->getArgument('module');
if (!$module) {
- $module = $this->modulesUninstallQuestion($io);
+ $module = $this->modulesUninstallQuestion();
$input->setArgument('module', $module);
}
}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
$composer = $input->getOption('composer');
$module = $input->getArgument('module');
$shellProcess = $this->get('shell_process');
if ($shellProcess->exec($command)) {
- $io->success(
+ $this->getIo()->success(
sprintf(
$this->trans('commands.module.uninstall.messages.composer-success'),
$moduleItem
}
if ($missingModules = array_diff_key($moduleList, $moduleData)) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.module.uninstall.messages.missing'),
implode(', ', $module),
$installedModules = $coreExtension->get('module') ?: [];
if (!$moduleList = array_intersect_key($moduleList, $installedModules)) {
- $io->info($this->trans('commands.module.uninstall.messages.nothing'));
+ $this->getIo()->info($this->trans('commands.module.uninstall.messages.nothing'));
return 0;
}
if (!$force = $input->getOption('force')) {
+
+ // Get a list of installed profiles that will be excluded when calculating
+ // the dependency tree.
+ if (\Drupal::hasService('profile_handler')) {
+ // #1356276 adds the profile_handler service but it hasn't been committed
+ // to core yet so we need to check if it exists.
+ $profiles = \Drupal::service('profile_handler')->getProfileInheritance();
+ } else {
+ $profiles[drupal_get_profile()] = [];
+ }
+
$dependencies = [];
while (list($module) = each($moduleList)) {
foreach (array_keys($moduleData[$module]->required_by) as $dependency) {
- if (isset($installedModules[$dependency]) && !isset($moduleList[$dependency]) && $dependency != $profile) {
+ if (isset($installedModules[$dependency]) && !isset($moduleList[$dependency]) && (!array_key_exists($dependency, $profiles))) {
$dependencies[] = $dependency;
}
}
}
if (!empty($dependencies)) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.module.uninstall.messages.dependents'),
implode('", "', $moduleList),
try {
$this->moduleInstaller->uninstall($moduleList);
- $io->info(
+ $this->getIo()->info(
sprintf(
$this->trans('commands.module.uninstall.messages.success'),
implode(', ', $moduleList)
)
);
- $io->comment(
+ $this->getIo()->comment(
sprintf(
$this->trans('commands.module.uninstall.messages.composer-success'),
implode(', ', $moduleList),
)
);
} catch (\Exception $e) {
- $io->error($e->getMessage());
+ $this->getIo()->error($e->getMessage());
return 1;
}