public function onFlush(OnFlushEventArgs $args)
{
$em = $args->getEntityManager();
$unitOfWork = $em->getUnitOfWork();
foreach ($unitOfWork->getScheduledEntityUpdates() as $entity) {
if ($entity instanceof PageInterface) {
if ($contentRoute = $entity->getContentRoute()) {
$contentRoute->setPath(PageHelper::getPageRoutePath($entity->getPath()));
$em->persist($contentRoute);
$unitOfWork->computeChangeSet($em->getClassMetadata(get_class($contentRoute)), $contentRoute);
foreach ($entity->getAllChildren() as $child) {
$contentRoute = $child->getContentRoute();
$contentRoute->setPath(PageHelper::getPageRoutePath($child->getPath()));
$em->persist($contentRoute);
$unitOfWork->computeChangeSet($em->getClassMetadata(get_class($contentRoute)), $contentRoute);
if ($entity->getStatus() == Page::STATUS_PUBLISHED) {
if ($childSnapshot = $child->getSnapshot()) {
$snapshotRoute = $childSnapshot->getContentRoute();
$newPath = PageHelper::getPageRoutePath($child->getPath());
$snapshotRoute->setPath($newPath);
$childSnapshot->setPath($newPath);
$em->persist($childSnapshot);
$em->persist($snapshotRoute);
$unitOfWork->computeChangeSet($em->getClassMetadata(get_class($childSnapshot)), $childSnapshot);
$unitOfWork->computeChangeSet($em->getClassMetadata(get_class($snapshotRoute)), $snapshotRoute);
}
}
}
}
}
}
}