filesystem = $filesystem; $this->sampleDataDependency = $sampleDataDependency; $this->arrayInputFactory = $arrayInputFactory; $this->applicationFactory = $applicationFactory; parent::__construct(); } /** * {@inheritdoc} */ protected function configure() { $this->setName('sampledata:remove') ->setDescription('Remove all sample data packages from composer.json'); $this->addOption( self::OPTION_NO_UPDATE, null, InputOption::VALUE_NONE, 'Update composer.json without executing composer update' ); parent::configure(); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages(); if (!empty($sampleDataPackages)) { $baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath(); $commonArgs = ['--working-dir' => $baseDir, '--no-interaction' => 1, '--no-progress' => 1]; if ($input->getOption(self::OPTION_NO_UPDATE)) { $commonArgs['--no-update'] = 1; } $packages = array_keys($sampleDataPackages); $arguments = array_merge(['command' => 'remove', 'packages' => $packages], $commonArgs); $commandInput = new ArrayInput($arguments); /** @var Application $application */ $application = $this->applicationFactory->create(); $application->setAutoExit(false); $result = $application->run($commandInput, $output); if ($result !== 0) { $output->writeln('' . 'There is an error during remove sample data.' . ''); } } else { $output->writeln('' . 'There is no sample data for current set of modules.' . ''); } } }