Skip to content

Commit

Permalink
fix: allow config or cache files to not be saved in any storage to en…
Browse files Browse the repository at this point in the history
…sure a least that the html page will load
  • Loading branch information
theus77 committed Aug 23, 2024
1 parent d2d1e1e commit 5cd496c
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions EMS/common-bundle/src/Storage/StorageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,34 +139,40 @@ public function saveContents(string $contents, string $filename, string $mimetyp
{
$hash = $this->computeStringHash($contents);
$count = 0;

foreach ($this->adapters as $adapter) {
if (!$this->isUsageSupported($adapter, $usageType)) {
continue;
}
try {
if (!$this->isUsageSupported($adapter, $usageType)) {
continue;
}

if ($adapter->head($hash)) {
++$count;
continue;
}
if ($adapter->head($hash)) {
++$count;
continue;
}

if (!$adapter->initUpload($hash, \strlen($contents), $filename, $mimetype)) {
continue;
}
if (!$adapter->initUpload($hash, \strlen($contents), $filename, $mimetype)) {
continue;
}

if (!$adapter->addChunk($hash, $contents)) {
continue;
}
if (!$adapter->addChunk($hash, $contents)) {
continue;
}

$adapter->initFinalize($hash);
$adapter->initFinalize($hash);

if ($adapter->finalizeUpload($hash)) {
++$count;
if ($adapter->finalizeUpload($hash)) {
++$count;
}
} catch (\Throwable $e) {
$this->logger->error(\sprintf('Not able to save %s in %s with message: %s', $hash, $adapter->__toString(), $e->getMessage()));
}
}

if (0 === $count) {
throw new NotSavedException($hash);
$this->logger->error(\sprintf('The config %s was not able to be saved', $hash));
if ($usageType >= StorageInterface::STORAGE_USAGE_ASSET) {
throw new NotSavedException($hash);
}
}

return $hash;
Expand Down

0 comments on commit 5cd496c

Please sign in to comment.