Merge branch 'improve-local-storage' into 'master'

Improve error handling when saving objects to local disk

See merge request Chill-Projet/chill-bundles!872
This commit is contained in:
2025-09-02 19:59:26 +00:00
2 changed files with 12 additions and 9 deletions

View File

@@ -0,0 +1,7 @@
kind: DX
body: |
Improve error message when a stored object cannot be written on local disk
time: 2025-09-02T21:51:27.248966834+02:00
custom:
Issue: ""
SchemaChange: No schema change

View File

@@ -18,6 +18,7 @@ use Chill\DocStoreBundle\Exception\StoredObjectManagerException;
use Chill\DocStoreBundle\Service\Cryptography\KeyGenerator;
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
@@ -147,16 +148,11 @@ class StoredObjectManager implements StoredObjectManagerInterface
public function writeContent(string $filename, string $encryptedContent): void
{
$fullPath = $this->buildPath($filename);
$dir = Path::getDirectory($fullPath);
if (!$this->filesystem->exists($dir)) {
$this->filesystem->mkdir($dir);
}
$result = file_put_contents($fullPath, $encryptedContent);
if (false === $result) {
throw StoredObjectManagerException::unableToStoreDocumentOnDisk();
try {
$this->filesystem->dumpFile($fullPath, $encryptedContent);
} catch (IOExceptionInterface $exception) {
throw StoredObjectManagerException::unableToStoreDocumentOnDisk($exception);
}
}