/**
* Flush for update
*
* @param object $entity
* @param \Doctrine\ORM\EntityManager $entityManager
* @param \Doctrine\ORM\UnitOfWork $unitOfWork
*/
protected function onFlushForUpdates(&$entity, EntityManager &$entityManager, UnitOfWork &$unitOfWork)
{
$className = get_class($entity);
$this->initializeAnnotationsForEntity($className);
if (count(self::$storedProperties[$className]['annotations']) > 0) {
foreach (self::$storedProperties[$className]['annotations'] as $propertyName => &$annotations) {
/* @var $annotation Traceable */
foreach ($annotations as $annotation) {
$run = $annotation->on === 'update';
if ($annotation->on === 'change') {
$changeSet = $unitOfWork->getEntityChangeSet($entity);
if (isset($changeSet[$annotation->field])) {
$type = $this->getPropertyType($className, $annotation->field);
$values = $annotation->getFieldValues($type, $entity);
$run = count($values) === 0 || in_array($changeSet[$annotation->field][1], $values);
}
}
if ($run) {
list($oldValue, $value) = $this->updateEntityPropertyValue($entity, $className, $propertyName, $annotation);
$entityManager->persist($entity);
$unitOfWork->propertyChanged($entity, $propertyName, $oldValue, $value);
$unitOfWork->scheduleExtraUpdate($entity, array($propertyName => array($oldValue, $value)));
break;
}
}
}
}
}