![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/inventory-composer-installer/src/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\InventoryComposerInstaller; use Composer\IO\IOInterface; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\File\ConfigFilePool; class DisabledInventoryConfiguration implements InventoryConfiguratorInterface { /** * @var DeploymentConfig */ private $deploymentConfig; /** * @var DeploymentConfig\Writer */ private $deploymentConfigWriter; /** * @var IOInterface */ private $io; public function __construct( DeploymentConfig $deploymentConfig, DeploymentConfig\Writer $deploymentConfigWriter, IOInterface $io ) { $this->deploymentConfig = $deploymentConfig; $this->deploymentConfigWriter = $deploymentConfigWriter; $this->io = $io; } public function configure(string $moduleName): void { if ($this->isModuleAlreadyConfigured($moduleName)) { $this->doNotChangeConfiguredValue($moduleName); return; } $this->disableModule($moduleName); } private function isModuleAlreadyConfigured(string $moduleName): bool { $configValue = $this->getModuleConfigurationValue($moduleName); return null !== $configValue; } private function doNotChangeConfiguredValue($moduleName): void { $configValue = $this->getModuleConfigurationValue($moduleName); if (null === $configValue) { $moduleStatus = 'undefined'; } elseif ($configValue) { $moduleStatus = 'enabled'; } else { $moduleStatus = 'disabled'; } $this->io->writeError(sprintf( ' ...Keep %s module %s as in current configuration', $moduleName, $moduleStatus ), true); } private function disableModule($moduleName): void { $this->io->writeError(sprintf( ' ...Disabling %s module for backward compatibility', $moduleName ), true); $this->deploymentConfigWriter->saveConfig([ ConfigFilePool::APP_CONFIG => [ 'modules' => [ $moduleName => 0, ] ] ]); } private function getModuleConfigurationValue(string $moduleName): ?bool { $configKey = 'modules/' . $moduleName; $configValue = $this->deploymentConfig->get($configKey); return isset($configValue) ? (bool)$configValue : null; } }