private function doUpdate(ClassMetadataFactory $metadataFactory, PhpcrMetadata $odmMetadata, CtMetadata $ctMetadata, $document)
{
$documentId = $odmMetadata->getIdentifierValue($document);
foreach ($odmMetadata->childrenMappings as $childrenField) {
// if the children field is not managed by the CT component,
// continue
if (!isset($ctMetadata->propertyMetadata[$childrenField])) {
continue;
}
$children = $odmMetadata->getFieldValue($document, $childrenField);
// note that we do not preserve array keys. PHPCR ODM will return a
// children collection using the PHPCR property names as keys, so
// we currently have no control over how these keys populated.
$index = 0;
foreach ($children as $child) {
$childMetadata = $metadataFactory->getMetadataFor(ClassUtils::getRealClass(get_class($child)));
$newId = sprintf('%s/%s', $documentId, $this->encoder->encode($childrenField, $index++));
$childMetadata->setIdentifierValue($child, $newId);
}
}
}