$versionId =
$versionId ?? Uuid::
randomHex();
$versionData =
['id' =>
$versionId];
if ($name) { $versionData['name'
] =
$name;
} $context->
scope(Context::SYSTEM_SCOPE,
function D
$context) use ($versionData): void
{ $this->entityWriter->
upsert($this->versionDefinition,
[$versionData],
$context);
});
$affected =
$this->
cloneEntity($definition,
$id,
$id,
$versionId,
$context,
new CloneBehavior());
$versionContext =
$context->
createWithVersionId($versionId);
$event = EntityWrittenContainerEvent::
createWithWrittenEvents($affected,
$versionContext->
getContext(),
[]);
$this->eventDispatcher->
dispatch($event);
$this->
writeAuditLog($affected,
$context,
$versionId, true
);
return $versionId;
}