mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-15 19:24:57 +00:00
This commit adds a history saving feature to the StoredObject entity, which allows saving versions of the object's changes over time. This is achieved by implementing a saveHistory method that captures data attributes like filename, IV, key information, and type. The corresponding Automated tests were also created. Furthermore, adjustments were made to the StoredObject test to align with the new feature.
76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\DocStoreBundle\Form\DataMapper;
|
|
|
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
|
use Symfony\Component\Form\DataMapperInterface;
|
|
use Symfony\Component\Form\Exception;
|
|
use Symfony\Component\Form\FormInterface;
|
|
|
|
class StoredObjectDataMapper implements DataMapperInterface
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
|
|
*/
|
|
public function mapDataToForms($viewData, $forms)
|
|
{
|
|
if (null === $viewData) {
|
|
return;
|
|
}
|
|
|
|
if (!$viewData instanceof StoredObject) {
|
|
throw new Exception\UnexpectedTypeException($viewData, StoredObject::class);
|
|
}
|
|
|
|
$forms = iterator_to_array($forms);
|
|
if (array_key_exists('title', $forms)) {
|
|
$forms['title']->setData($viewData->getTitle());
|
|
}
|
|
$forms['stored_object']->setData($viewData);
|
|
}
|
|
|
|
/**
|
|
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
|
|
*/
|
|
public function mapFormsToData($forms, &$viewData)
|
|
{
|
|
$forms = iterator_to_array($forms);
|
|
|
|
if (!(null === $viewData || $viewData instanceof StoredObject)) {
|
|
throw new Exception\UnexpectedTypeException($viewData, StoredObject::class);
|
|
}
|
|
|
|
if (null === $forms['stored_object']->getData()) {
|
|
return;
|
|
}
|
|
|
|
/** @var StoredObject $viewData */
|
|
if ($viewData->getFilename() !== $forms['stored_object']->getData()['filename']) {
|
|
// we want to keep the previous history
|
|
$viewData->saveHistory();
|
|
}
|
|
|
|
$viewData->setFilename($forms['stored_object']->getData()['filename']);
|
|
$viewData->setIv($forms['stored_object']->getData()['iv']);
|
|
$viewData->setKeyInfos($forms['stored_object']->getData()['keyInfos']);
|
|
$viewData->setType($forms['stored_object']->getData()['type']);
|
|
|
|
if (array_key_exists('title', $forms)) {
|
|
$viewData->setTitle($forms['title']->getData());
|
|
}
|
|
}
|
|
}
|