Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Importer.php
Go to the documentation of this file.
1 <?php
7 
18 
28 class Importer implements ImporterInterface
29 {
33  const FLAG_CODE = 'system_config_snapshot';
34 
40  private $flagManager;
41 
47  private $arrayUtils;
48 
54  private $scopeConfig;
55 
61  private $state;
62 
68  private $scope;
69 
75  private $saveProcessor;
76 
85  public function __construct(
86  FlagManager $flagManager,
87  ArrayUtils $arrayUtils,
88  SaveProcessor $saveProcessor,
89  ScopeConfigInterface $scopeConfig,
90  State $state,
91  ScopeInterface $scope
92  ) {
93  $this->flagManager = $flagManager;
94  $this->arrayUtils = $arrayUtils;
95  $this->saveProcessor = $saveProcessor;
96  $this->scopeConfig = $scopeConfig;
97  $this->state = $state;
98  $this->scope = $scope;
99  }
100 
108  public function import(array $data)
109  {
110  $currentScope = $this->scope->getCurrentScope();
111 
112  try {
113  $savedFlag = $this->flagManager->getFlagData(static::FLAG_CODE) ?: [];
114  $changedData = array_replace_recursive(
115  $this->arrayUtils->recursiveDiff($savedFlag, $data),
116  $this->arrayUtils->recursiveDiff($data, $savedFlag)
117  );
118 
123  if ($this->scopeConfig instanceof Config) {
124  $this->scopeConfig->clean();
125  }
126 
127  $this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use ($changedData) {
128  $this->scope->setCurrentScope(Area::AREA_ADMINHTML);
129 
130  // Invoke saving of new values.
131  $this->saveProcessor->process($changedData);
132  });
133 
134  $this->scope->setCurrentScope($currentScope);
135  $this->flagManager->saveFlag(static::FLAG_CODE, $data);
136  } catch (\Exception $e) {
137  throw new InvalidTransitionException(__('%1', $e->getMessage()), $e);
138  } finally {
139  $this->scope->setCurrentScope($currentScope);
140  }
141 
142  return ['System config was processed'];
143  }
144 
150  public function getWarningMessages(array $data)
151  {
152  return [];
153  }
154 }
__()
Definition: __.php:13
__construct(FlagManager $flagManager, ArrayUtils $arrayUtils, SaveProcessor $saveProcessor, ScopeConfigInterface $scopeConfig, State $state, ScopeInterface $scope)
Definition: Importer.php:85