Skip to content

Commit 01dacc4

Browse files
committed
B2B-1785: Cannot enable remote storage with install command when modules are not enabled
1 parent fee45bc commit 01dacc4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,12 @@ public function install($request)
391391
foreach ($script as $item) {
392392
list($message, $method, $params) = $item;
393393
$this->log->log($message);
394-
// phpcs:ignore Magento2.Functions.DiscouragedFunction
395-
call_user_func_array([$this, $method], $params);
394+
try {
395+
$this->$method(...$params);
396+
} catch (RuntimeException $e) {
397+
$this->revertRemoteStorageConfiguration();
398+
throw $e;
399+
}
396400
$this->logProgress();
397401
}
398402
$this->log->logSuccess('Magento installation complete.');
@@ -1218,6 +1222,7 @@ public function validateRemoteStorageConfiguration(array $data)
12181222
$validationErrors = $remoteStorageValidator->validate($data, $this->deploymentConfig);
12191223

12201224
if (!empty($validationErrors)) {
1225+
$this->revertRemoteStorageConfiguration();
12211226
throw new ValidationException(__(implode(PHP_EOL, $validationErrors)));
12221227
}
12231228
}
@@ -1787,4 +1792,19 @@ private function getDisabledCacheTypes(array $cacheTypesToCheck): array
17871792

17881793
return $disabledCaches;
17891794
}
1795+
1796+
/**
1797+
* Revert remote storage configuration back to local file driver
1798+
*/
1799+
private function revertRemoteStorageConfiguration()
1800+
{
1801+
if (!$this->deploymentConfigWriter->checkIfWritable()) {
1802+
return;
1803+
}
1804+
1805+
$remoteStorageData = new ConfigData(ConfigFilePool::APP_ENV);
1806+
$remoteStorageData->set('remote_storage', ['driver' => 'file']);
1807+
$configData = [$remoteStorageData->getFileKey() => $remoteStorageData->getData()];
1808+
$this->deploymentConfigWriter->saveConfig($configData, true);
1809+
}
17901810
}

0 commit comments

Comments
 (0)