public function isChanged($value, $originalData, $valueFieldMapping)
{
// EmbedMany case
if ('many' == $valueFieldMapping['embedded'] && (is_array($value) || $value instanceof \Doctrine\Common\Collections\ArrayCollection)) {
if (count($originalData) != count($value)) {
return true;
}
foreach ($value as $key => $valueElement) {
if (!isset($originalData[$key]) || $this->isChanged($valueElement, $originalData[$key], $valueFieldMapping)) {
return true;
}
}
return false;
}
// EmbedOne case, or one instance of and EmbedMany
if ($this->metadataResolver->canMapDocument($originalData) && get_class($value) !== $this->metadataResolver->getDocumentType($originalData)) {
return true;
}
$class = $this->metadataFactory->getMetadataFor(get_class($value));
foreach ($class->reflFields as $fieldName => $fieldValue) {
$fieldMapping = $class->fieldMappings[$fieldName];
$originalDataValue = isset($originalData[$fieldMapping['jsonName']]) ? $originalData[$fieldMapping['jsonName']] : null;
$currentValue = $class->getFieldValue($value, $fieldMapping['fieldName']);
if ($originalDataValue === null && $currentValue === null) {
continue;
} else {
if ($originalDataValue === null || $currentValue === null) {
return true;
}
}
if (!isset($fieldMapping['embedded'])) {
// simple property comparison
// TODO this conversion could be avoided if we store the php value in the original data
// as with the simple property mapping in UOW.
$originalValue = Type::getType($fieldMapping['type'])->convertToPHPValue($originalDataValue);
if ($originalValue != $currentValue) {
return true;
}
} else {
if ('many' == $fieldMapping['embedded']) {
if (count($originalDataValue) != count($currentValue)) {
return true;
}
foreach ($currentValue as $currentKey => $currentElem) {
if (!isset($originalDataValue[$currentKey])) {
return true;
}
if ($this->isChanged($currentElem, $originalDataValue[$currentKey], $fieldMapping)) {
return true;
}
}
} else {
// embedOne
if ($this->isChanged($currentValue, $originalDataValue, $fieldMapping)) {
return true;
}
}
}
}
return false;
}