mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
Enhance behaviour of duplicating storedObject to keep only the last "kept before conversion" version if any
Enhance the duplication service to selectively handle versions tagged with "KEEP_BEFORE_CONVERSION". Modify StoredObject to support retrieval and checking of such versions. Add relevant test cases to validate this behavior.
This commit is contained in:
@@ -22,9 +22,18 @@ class StoredObjectDuplicate
|
||||
{
|
||||
public function __construct(private readonly StoredObjectManagerInterface $storedObjectManager, private readonly LoggerInterface $logger) {}
|
||||
|
||||
public function duplicate(StoredObject|StoredObjectVersion $from): StoredObject
|
||||
public function duplicate(StoredObject|StoredObjectVersion $from, bool $onlyLastKeptBeforeConversionVersion = true): StoredObject
|
||||
{
|
||||
$fromVersion = $from instanceof StoredObjectVersion ? $from : $from->getCurrentVersion();
|
||||
$storedObject = $from instanceof StoredObjectVersion ? $from->getStoredObject() : $from;
|
||||
|
||||
$fromVersion = match ($storedObject->hasKeptBeforeConversionVersion() && $onlyLastKeptBeforeConversionVersion) {
|
||||
true => $from->getLastKeptBeforeConversionVersion(),
|
||||
false => $storedObject->getCurrentVersion(),
|
||||
};
|
||||
|
||||
if (null === $fromVersion) {
|
||||
throw new \UnexpectedValueException('could not find a version to restore');
|
||||
}
|
||||
|
||||
$oldContent = $this->storedObjectManager->read($fromVersion);
|
||||
|
||||
|
Reference in New Issue
Block a user