mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Refactor and simplify document management functionality to adapt to StoredObject versioning
This commit includes several updates to the document management functionality within ChillWopiBundle and ChillDocGeneratorBundle, refactoring for simplicity and improved readability.
This commit is contained in:
parent
3978ea9a47
commit
e21db73b84
@ -54,12 +54,15 @@ class LoadDocGeneratorTemplate extends AbstractFixture
|
||||
];
|
||||
|
||||
foreach ($templates as $template) {
|
||||
$newStoredObj = (new StoredObject())
|
||||
->setFilename($template['file']['filename'])
|
||||
->setKeyInfos(json_decode($template['file']['key'], true))
|
||||
->setIv(json_decode($template['file']['iv'], true))
|
||||
$newStoredObj = (new StoredObject());
|
||||
|
||||
$newStoredObj
|
||||
->setCreatedAt(new \DateTime('today'))
|
||||
->setType($template['file']['type']);
|
||||
->registerVersion(
|
||||
json_decode($template['file']['key'], true),
|
||||
json_decode($template['file']['iv'], true),
|
||||
$template['file']['type'],
|
||||
);
|
||||
|
||||
$manager->persist($newStoredObj);
|
||||
|
||||
|
@ -134,13 +134,11 @@ class Generator implements GeneratorInterface
|
||||
$content = Yaml::dump($data, 6);
|
||||
/* @var StoredObject $destinationStoredObject */
|
||||
$destinationStoredObject
|
||||
->setType('application/yaml')
|
||||
->setFilename(sprintf('%s_yaml', uniqid('doc_', true)))
|
||||
->setStatus(StoredObject::STATUS_READY)
|
||||
;
|
||||
|
||||
try {
|
||||
$this->storedObjectManager->write($destinationStoredObject, $content);
|
||||
$this->storedObjectManager->write($destinationStoredObject, $content, 'application/yaml');
|
||||
} catch (StoredObjectManagerException $e) {
|
||||
$destinationStoredObject->addGenerationErrors($e->getMessage());
|
||||
|
||||
@ -174,13 +172,11 @@ class Generator implements GeneratorInterface
|
||||
|
||||
/* @var StoredObject $destinationStoredObject */
|
||||
$destinationStoredObject
|
||||
->setType($template->getFile()->getType())
|
||||
->setFilename(sprintf('%s_odt', uniqid('doc_', true)))
|
||||
->setStatus(StoredObject::STATUS_READY)
|
||||
;
|
||||
|
||||
try {
|
||||
$this->storedObjectManager->write($destinationStoredObject, $generatedResource);
|
||||
$this->storedObjectManager->write($destinationStoredObject, $generatedResource, $template->getFile()->getType());
|
||||
} catch (StoredObjectManagerException $e) {
|
||||
$destinationStoredObject->addGenerationErrors($e->getMessage());
|
||||
|
||||
|
@ -50,17 +50,15 @@ final readonly class ChillDocumentManager implements DocumentManagerInterface
|
||||
|
||||
// Mime types / extension handling.
|
||||
$mimeTypes = new MimeTypes();
|
||||
$mimeTypes->getMimeTypes($data['extension']);
|
||||
$document->setType(reset($mimeTypes));
|
||||
|
||||
$document->setFilename($data['name']);
|
||||
$types = $mimeTypes->getMimeTypes($data['extension']);
|
||||
$mimeType = array_values($types)[0] ?? '';
|
||||
|
||||
$this->entityManager->persist($document);
|
||||
$this->entityManager->flush();
|
||||
|
||||
// TODO : Ask proper mapping.
|
||||
// Available: basename, name, extension, content, size
|
||||
$this->setContent($document, $data['content']);
|
||||
$this->storedObjectManager->write($document, $data['content'], $mimeType);
|
||||
|
||||
return $document;
|
||||
}
|
||||
@ -194,5 +192,7 @@ final readonly class ChillDocumentManager implements DocumentManagerInterface
|
||||
private function setContent(StoredObject $storedObject, string $content): void
|
||||
{
|
||||
$this->storedObjectManager->write($storedObject, $content);
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user