Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobModule.php
Go to the documentation of this file.
1 <?php
7 
10 use Symfony\Component\Console\Input\ArrayInput;
11 use Symfony\Component\Console\Output\OutputInterface;
12 
16 class JobModule extends AbstractJob
17 {
21  protected $cmdString;
22 
33  public function __construct(
35  ObjectManagerProvider $objectManagerProvider,
36  OutputInterface $output,
38  $name,
39  $params = []
40  ) {
41  $this->command = $command;
42  parent::__construct($output, $status, $objectManagerProvider, $name, $params);
43 
44  // map name to command string
45  $this->setCommandString($name);
46  }
47 
54  private function setCommandString($name)
55  {
56  if ($name == 'setup:module:enable') {
57  $this->cmdString = 'module:enable';
58  } else {
59  $this->cmdString = 'module:disable';
60  }
61  }
62 
69  public function execute()
70  {
71  try {
72  foreach ($this->params['components'] as $compObj) {
73  if (isset($compObj['name']) && (!empty($compObj['name']))) {
74  $moduleNames[] = $compObj['name'];
75  } else {
76  throw new \RuntimeException('component name is not set.');
77  }
78  }
79 
80  // prepare the arguments to invoke Symfony run()
81  $arguments['command'] = $this->cmdString;
82  $arguments['module'] = $moduleNames;
83 
84  $statusCode = $this->command->run(new ArrayInput($arguments), $this->output);
85 
86  // check for return statusCode to catch any Symfony errors
87  if ($statusCode != 0) {
88  throw new \RuntimeException('Symfony run() returned StatusCode: ' . $statusCode);
89  }
90 
91  //perform the generated file cleanup
92  $this->performCleanup();
93  } catch (\Exception $e) {
94  $this->status->toggleUpdateError(true);
95  throw new \RuntimeException(
96  sprintf('Could not complete %s successfully: %s', $this->cmdString, $e->getMessage())
97  );
98  }
99  }
100 }
output($string, $level=INFO, $label='')
__construct(AbstractSetupCommand $command, ObjectManagerProvider $objectManagerProvider, OutputInterface $output, Status $status, $name, $params=[])
Definition: JobModule.php:33
$arguments