Skip to content

Commit 8ca0724

Browse files
MC-38424: Support for Remote Storage
1 parent bad3b7b commit 8ca0724

File tree

1 file changed

+49
-42
lines changed

1 file changed

+49
-42
lines changed

src/Step/Deploy/RemoteStorage.php

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -77,56 +77,63 @@ public function execute(): void
7777
throw new StepException($exception->getMessage(), $exception->getCode(), $exception);
7878
}
7979

80-
$driver = $this->config->getDriver();
81-
82-
if ($driver) {
83-
$config = $this->config->getConfig();
80+
if ($driver = $this->config->getDriver()) {
81+
$this->updateConfig($driver);
82+
} else {
83+
$this->magentoShell->execute('setup:config:set --remote-storage-driver=file -n');
84+
}
85+
}
8486

85-
if (empty($config['bucket']) || empty($config['region'])) {
86-
throw new StepException('Bucket and region are required configurations');
87-
}
87+
/**
88+
* Update configuration.
89+
*
90+
* @param string $driver
91+
* @throws StepException
92+
*/
93+
private function updateConfig(string $driver): void
94+
{
95+
$config = $this->config->getConfig();
8896

89-
$options = [
90-
'--remote-storage-driver=' . $driver,
91-
'--remote-storage-bucket=' . $config['bucket'],
92-
'--remote-storage-region=' . $config['region']
93-
];
97+
if (empty($config['bucket']) || empty($config['region'])) {
98+
throw new StepException('Bucket and region are required configurations');
99+
}
94100

95-
if ($prefix = $this->config->getPrefix()) {
96-
$options[] = '--remote-storage-prefix=' . $prefix;
97-
}
101+
$options = [
102+
'--remote-storage-driver=' . $driver,
103+
'--remote-storage-bucket=' . $config['bucket'],
104+
'--remote-storage-region=' . $config['region']
105+
];
98106

99-
if (isset($config['key'], $config['secret'])) {
100-
$options[] = '--remote-storage-key=' . $config['key'];
101-
$options[] = '--remote-storage-secret=' . $config['secret'];
102-
}
107+
if ($prefix = $this->config->getPrefix()) {
108+
$options[] = '--remote-storage-prefix=' . $prefix;
109+
}
103110

104-
try {
105-
$this->magentoShell->execute(sprintf(
106-
'setup:config:set %s -n',
107-
implode(' ', $options)
108-
));
109-
} catch (ShellException $exception) {
110-
$this->logger->critical(
111-
$exception->getMessage(),
112-
['errorCode' => Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED]
113-
);
114-
115-
throw new StepException(
116-
$exception->getMessage(),
117-
Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED,
118-
$exception
119-
);
120-
}
111+
if (isset($config['key'], $config['secret'])) {
112+
$options[] = '--remote-storage-key=' . $config['key'];
113+
$options[] = '--remote-storage-secret=' . $config['secret'];
114+
}
121115

122-
$this->logger->info(sprintf(
123-
'Remote storage with driver "%s" was enabled',
124-
$driver
116+
try {
117+
$this->magentoShell->execute(sprintf(
118+
'setup:config:set %s -n',
119+
implode(' ', $options)
125120
));
126-
127-
return;
121+
} catch (ShellException $exception) {
122+
$this->logger->critical(
123+
$exception->getMessage(),
124+
['errorCode' => Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED]
125+
);
126+
127+
throw new StepException(
128+
$exception->getMessage(),
129+
Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED,
130+
$exception
131+
);
128132
}
129133

130-
$this->magentoShell->execute('setup:config:set --remote-storage-driver=file -n');
134+
$this->logger->info(sprintf(
135+
'Remote storage with driver "%s" was enabled',
136+
$driver
137+
));
131138
}
132139
}

0 commit comments

Comments
 (0)