|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * |
| 4 | + * Copyright © Magento, Inc. All rights reserved. |
| 5 | + * See COPYING.txt for license details. |
| 6 | + */ |
| 7 | +namespace Magento\Downloadable\Console\Command; |
| 8 | + |
| 9 | +use Symfony\Component\Console\Command\Command; |
| 10 | +use Symfony\Component\Console\Output\OutputInterface; |
| 11 | +use Symfony\Component\Console\Input\InputInterface; |
| 12 | +use Symfony\Component\Console\Input\InputArgument; |
| 13 | +use Magento\Downloadable\Api\DomainManagerInterface as DomainManager; |
| 14 | + |
| 15 | +/** |
| 16 | + * Class DomainsRemoveCommand |
| 17 | + * |
| 18 | + * Command for removing downloadable domain from the whitelist |
| 19 | + */ |
| 20 | +class DomainsRemoveCommand extends Command |
| 21 | +{ |
| 22 | + /** |
| 23 | + * Name of domains input argument |
| 24 | + */ |
| 25 | + const INPUT_KEY_DOMAINS = 'domains'; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var DomainManager |
| 29 | + */ |
| 30 | + private $domainManager; |
| 31 | + |
| 32 | + /** |
| 33 | + * DomainsRemoveCommand constructor. |
| 34 | + * |
| 35 | + * @param DomainManager $domainManager |
| 36 | + */ |
| 37 | + public function __construct( |
| 38 | + DomainManager $domainManager |
| 39 | + ) { |
| 40 | + $this->domainManager = $domainManager; |
| 41 | + parent::__construct(); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @inheritdoc |
| 46 | + */ |
| 47 | + protected function configure() |
| 48 | + { |
| 49 | + $description = 'Remove domains from the downloadable domains whitelist'; |
| 50 | + |
| 51 | + $this->setName('downloadable:domains:remove') |
| 52 | + ->setDescription($description) |
| 53 | + ->setDefinition( |
| 54 | + [ |
| 55 | + new InputArgument( |
| 56 | + self::INPUT_KEY_DOMAINS, |
| 57 | + InputArgument::IS_ARRAY, |
| 58 | + 'Domain names' |
| 59 | + ) |
| 60 | + ] |
| 61 | + ); |
| 62 | + parent::configure(); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @inheritdoc |
| 67 | + */ |
| 68 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 69 | + { |
| 70 | + try { |
| 71 | + if ($input->getArgument(self::INPUT_KEY_DOMAINS)) { |
| 72 | + $whitelistBefore = $this->domainManager->getDomains(); |
| 73 | + $removeDomains = $input->getArgument(self::INPUT_KEY_DOMAINS); |
| 74 | + $removeDomains = array_filter(array_map('trim', $removeDomains), 'strlen'); |
| 75 | + $this->domainManager->removeDomains($removeDomains); |
| 76 | + |
| 77 | + foreach (array_diff($whitelistBefore, $this->domainManager->getDomains()) as $removedHost) { |
| 78 | + $output->writeln( |
| 79 | + $removedHost . ' was removed from the whitelist.' |
| 80 | + ); |
| 81 | + } |
| 82 | + } |
| 83 | + } catch (\Exception $e) { |
| 84 | + $output->writeln('<error>' . $e->getMessage() . '</error>'); |
| 85 | + if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
| 86 | + $output->writeln($e->getTraceAsString()); |
| 87 | + } |
| 88 | + return; |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments