Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DisabledInventoryConfiguration.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Composer\IO\IOInterface;
13 
15 {
19  private $deploymentConfig;
20 
24  private $deploymentConfigWriter;
25 
29  private $io;
30 
31  public function __construct(
32  DeploymentConfig $deploymentConfig,
33  DeploymentConfig\Writer $deploymentConfigWriter,
34  IOInterface $io
35  ) {
36  $this->deploymentConfig = $deploymentConfig;
37  $this->deploymentConfigWriter = $deploymentConfigWriter;
38  $this->io = $io;
39  }
40 
41  public function configure(string $moduleName): void
42  {
43  if ($this->isModuleAlreadyConfigured($moduleName)) {
44  $this->doNotChangeConfiguredValue($moduleName);
45  return;
46  }
47 
48  $this->disableModule($moduleName);
49  }
50 
51  private function isModuleAlreadyConfigured(string $moduleName): bool
52  {
53  $configValue = $this->getModuleConfigurationValue($moduleName);
54  return null !== $configValue;
55  }
56 
57  private function doNotChangeConfiguredValue($moduleName): void
58  {
59  $configValue = $this->getModuleConfigurationValue($moduleName);
60  if (null === $configValue) {
61  $moduleStatus = 'undefined';
62  } elseif ($configValue) {
63  $moduleStatus = 'enabled';
64  } else {
65  $moduleStatus = 'disabled';
66  }
67 
68  $this->io->writeError(sprintf(
69  ' ...Keep %s module %s as in current configuration',
70  $moduleName,
71  $moduleStatus
72  ), true);
73  }
74 
75  private function disableModule($moduleName): void
76  {
77  $this->io->writeError(sprintf(
78  ' ...Disabling %s module for backward compatibility',
79  $moduleName
80  ), true);
81 
82  $this->deploymentConfigWriter->saveConfig([
84  'modules' => [
85  $moduleName => 0,
86  ]
87  ]
88  ]);
89  }
90 
91  private function getModuleConfigurationValue(string $moduleName): ?bool
92  {
93  $configKey = 'modules/' . $moduleName;
94  $configValue = $this->deploymentConfig->get($configKey);
95  return isset($configValue) ? (bool)$configValue : null;
96  }
97 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$deploymentConfig
__construct(DeploymentConfig $deploymentConfig, DeploymentConfig\Writer $deploymentConfigWriter, IOInterface $io)