Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobFactory.php
Go to the documentation of this file.
1 <?php
7 
14 use Zend\ServiceManager\ServiceLocatorInterface;
17 
24 {
28  const JOB_UPGRADE = 'setup:upgrade';
29  const JOB_DB_ROLLBACK = 'setup:rollback';
30  const JOB_COMPONENT_UNINSTALL = 'setup:component:uninstall';
31  const JOB_MODULE_ENABLE = 'setup:module:enable';
32  const JOB_MODULE_DISABLE = 'setup:module:disable';
33  const JOB_STATIC_REGENERATE = 'setup:static:regenerate';
34  const JOB_ENABLE_CACHE = 'setup:cache:enable';
35  const JOB_DISABLE_CACHE = 'setup:cache:disable';
36  const JOB_MAINTENANCE_MODE_ENABLE = 'setup:maintenance:enable';
37  const JOB_MAINTENANCE_MODE_DISABLE = 'setup:maintenance:disable';
38 
42  private $serviceLocator;
43 
49  public function __construct(ServiceLocatorInterface $serviceLocator)
50  {
51  $this->serviceLocator = $serviceLocator;
52  }
53 
64  public function create($name, array $params = [])
65  {
66  $cronStatus = $this->serviceLocator->get(\Magento\Setup\Model\Cron\Status::class);
67  $statusStream = fopen($cronStatus->getStatusFilePath(), 'a+');
68  $logStream = fopen($cronStatus->getLogFilePath(), 'a+');
69  $streamOutput = new MultipleStreamOutput([$statusStream, $logStream]);
70  $objectManagerProvider = $this->serviceLocator->get(\Magento\Setup\Model\ObjectManagerProvider::class);
72  $objectManager = $objectManagerProvider->get();
73  switch ($name) {
74  case self::JOB_UPGRADE:
75  return new JobUpgrade(
76  $this->serviceLocator->get(UpgradeCommand::class),
77  $objectManagerProvider,
78  $streamOutput,
79  $this->serviceLocator->get(\Magento\Setup\Model\Cron\Queue::class),
80  $cronStatus,
81  $name,
82  $params
83  );
84  break;
86  return new JobDbRollback(
87  $objectManager->get(\Magento\Framework\Setup\BackupRollbackFactory::class),
88  $streamOutput,
89  $cronStatus,
90  $objectManagerProvider,
91  $name,
92  $params
93  );
94  break;
96  return new JobStaticRegenerate(
97  $objectManagerProvider,
98  $streamOutput,
99  $cronStatus,
100  $name,
101  $params
102  );
103  break;
105  $moduleUninstall = new Helper\ModuleUninstall(
106  $this->serviceLocator->get(\Magento\Setup\Model\ModuleUninstaller::class),
107  $this->serviceLocator->get(\Magento\Setup\Model\ModuleRegistryUninstaller::class),
108  $objectManager->get(\Magento\Framework\Module\PackageInfoFactory::class)
109  );
110  $themeUninstall = new Helper\ThemeUninstall(
111  $objectManager->get(\Magento\Theme\Model\Theme\ThemeUninstaller::class),
112  $objectManager->get(\Magento\Theme\Model\Theme\ThemePackageInfo::class)
113  );
114  return new JobComponentUninstall(
115  $objectManager->get(\Magento\Framework\Composer\ComposerInformation::class),
116  $moduleUninstall,
117  $themeUninstall,
118  $objectManagerProvider,
119  $streamOutput,
120  $this->serviceLocator->get(\Magento\Setup\Model\Cron\Queue::class),
121  $cronStatus,
122  $this->serviceLocator->get(\Magento\Setup\Model\Updater::class),
123  $name,
124  $params
125  );
126  break;
128  return new JobModule(
129  $this->serviceLocator->get(ModuleEnableCommand::class),
130  $objectManagerProvider,
131  $streamOutput,
132  $cronStatus,
133  $name,
134  $params
135  );
136  break;
138  return new JobModule(
139  $this->serviceLocator->get(ModuleDisableCommand::class),
140  $objectManagerProvider,
141  $streamOutput,
142  $cronStatus,
143  $name,
144  $params
145  );
146  break;
148  return new JobSetCache(
149  $objectManager->get(CacheEnableCommand::class),
150  $objectManagerProvider,
151  $streamOutput,
152  $cronStatus,
153  $name,
154  $params
155  );
156  break;
158  return new JobSetCache(
159  $objectManager->get(CacheDisableCommand::class),
160  $objectManagerProvider,
161  $streamOutput,
162  $cronStatus,
163  $name
164  );
165  break;
167  return new JobSetMaintenanceMode(
168  $this->serviceLocator->get(MaintenanceEnableCommand::class),
169  $objectManagerProvider,
170  $streamOutput,
171  $cronStatus,
172  $name,
173  $params
174  );
175  break;
177  return new JobSetMaintenanceMode(
178  $this->serviceLocator->get(MaintenanceDisableCommand::class),
179  $objectManagerProvider,
180  $streamOutput,
181  $cronStatus,
182  $name,
183  $params
184  );
185  break;
186  default:
187  throw new \RuntimeException(sprintf('"%s" job is not supported.', $name));
188  break;
189  }
190  }
191 }
$objectManager
Definition: bootstrap.php:17
__construct(ServiceLocatorInterface $serviceLocator)
Definition: JobFactory.php:49
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
if(!isset($_GET['name'])) $name
Definition: log.php:14