synchronized) { return; } $driver = (string)$backend->getFieldsetDataValue('driver'); if (!in_array($driver, ['file', 'aws-s3'], true)) { throw new LocalizedException(__('Unsupported media storage driver.')); } if (!$this->deploymentConfigWriter->checkIfWritable()) { throw new LocalizedException(__('app/etc/env.php is not writable by the PHP process.')); } $remoteStorage = ['driver' => $driver]; if ($driver === 'aws-s3') { $bucket = trim((string)$backend->getFieldsetDataValue('bucket')); $region = trim((string)$backend->getFieldsetDataValue('region')); if ($bucket === '' || $region === '') { throw new LocalizedException(__('S3 Bucket and AWS Region are required.')); } $current = (array)$this->deploymentConfig->get('remote_storage', []); $currentCredentials = (array)($current['config']['credentials'] ?? []); $accessKey = $this->resolveSecret( (string)$backend->getFieldsetDataValue('access_key'), (string)($currentCredentials['key'] ?? '') ); $secretKey = $this->resolveSecret( (string)$backend->getFieldsetDataValue('secret_key'), (string)($currentCredentials['secret'] ?? '') ); $remoteStorage['prefix'] = trim((string)$backend->getFieldsetDataValue('prefix'), '/ '); $remoteStorage['config'] = [ 'bucket' => $bucket, 'region' => $region, 'path_style' => (int)$backend->getFieldsetDataValue('path_style'), 'credentials' => [ 'key' => $accessKey, 'secret' => $secretKey, ], ]; $endpoint = trim((string)$backend->getFieldsetDataValue('endpoint')); if ($endpoint !== '') { $remoteStorage['config']['endpoint'] = $endpoint; } } $this->deploymentConfigWriter->saveConfig( [ConfigFilePool::APP_ENV => ['remote_storage' => $remoteStorage]], true, null, [], true ); $this->cacheTypeList->cleanType(ConfigCache::TYPE_IDENTIFIER); $this->synchronized = true; } private function resolveSecret(string $postedValue, string $currentValue): string { if (preg_match('/^\*+$/', $postedValue)) { return $currentValue; } if ($postedValue === '') { return ''; } return $postedValue; } }