Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobSetCache.php
Go to the documentation of this file.
1 <?php
7 
9 use Symfony\Component\Console\Input\ArrayInput;
10 use Symfony\Component\Console\Input\InputDefinition;
11 use Symfony\Component\Console\Input\InputArgument;
12 
13 class JobSetCache extends AbstractJob
14 {
18  protected $command;
19 
23  protected $output;
24 
28  protected $status;
29 
38  public function __construct(
39  \Magento\Backend\Console\Command\AbstractCacheSetCommand $command,
40  \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider,
41  \Symfony\Component\Console\Output\OutputInterface $output,
43  $name,
44  $params = []
45  ) {
46  $this->command = $command;
47  parent::__construct($output, $status, $objectManagerProvider, $name, $params);
48  }
49 
55  public function execute()
56  {
57  try {
58  $arguments = [];
59  if ($this->getName() === 'setup:cache:enable') {
60  if (!empty($this->params)) {
61  $arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]);
62  }
63  $arguments['command'] = 'cache:enable';
64  $inputDefinition = [];
65  if ($this->command->getDefinition()->hasArgument('command')) {
66  $inputDefinition[] = new InputArgument('command', InputArgument::REQUIRED);
67  }
68  if ($this->command->getDefinition()->hasArgument(AbstractCacheManageCommand::INPUT_KEY_TYPES)) {
69  $inputDefinition[] = new InputArgument(
71  InputArgument::REQUIRED
72  );
73  }
74  if (!empty($inputDefinition)) {
75  $definition = new InputDefinition($inputDefinition);
76  $this->command->setDefinition($definition);
77  }
78  } else {
79  $arguments['command'] = 'cache:disable';
80  }
81  $this->command->run(new ArrayInput($arguments), $this->output);
82  } catch (\Exception $e) {
83  $this->status->toggleUpdateError(true);
84  throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
85  }
86  }
87 }
output($string, $level=INFO, $label='')
$arguments
__construct(\Magento\Backend\Console\Command\AbstractCacheSetCommand $command, \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider, \Symfony\Component\Console\Output\OutputInterface $output, \Magento\Setup\Model\Cron\Status $status, $name, $params=[])
Definition: JobSetCache.php:38