Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobDbRollback.php
Go to the documentation of this file.
1 <?php
7 
11 use Symfony\Component\Console\Input\ArrayInput;
12 use Symfony\Component\Console\Output\OutputInterface;
13 
18 {
22  private $backupRollbackFactory;
23 
33  public function __construct(
34  BackupRollbackFactory $backupRollbackFactory,
35  OutputInterface $output,
37  ObjectManagerProvider $objectManagerProvider,
38  $name,
39  $params = []
40  ) {
41  $this->backupRollbackFactory = $backupRollbackFactory;
42  parent::__construct($output, $status, $objectManagerProvider, $name, $params);
43  }
44 
51  public function execute()
52  {
53  try {
54  $rollbackHandler = $this->backupRollbackFactory->create($this->output);
55  $dbBackupFile = $this->params['backup_file_name'];
56  if (!empty($dbBackupFile)) {
57  $this->setAreaCode();
58  $rollbackHandler->dbRollback(basename($dbBackupFile));
59  } else {
60  $this->status->add(
61  'No available DB backup file found. Please refer to documentation specified '
62  . 'in <a href=""> doc link </a> to rollback database to a previous version to ',
63  \Psr\Log\LogLevel::INFO
64  );
65  }
66  } catch (\Exception $e) {
67  $this->status->toggleUpdateError(true);
68  throw new \RuntimeException(
69  sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()),
70  $e->getCode(),
71  $e
72  );
73  }
74  }
75 
81  private function setAreaCode()
82  {
83  $areaCode = 'adminhtml';
85  $appState = $this->objectManager->get(\Magento\Framework\App\State::class);
86  $appState->setAreaCode($areaCode);
88  $configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
89  $this->objectManager->configure($configLoader->load($areaCode));
90  }
91 }
output($string, $level=INFO, $label='')
__construct(BackupRollbackFactory $backupRollbackFactory, OutputInterface $output, Status $status, ObjectManagerProvider $objectManagerProvider, $name, $params=[])