/** * @param EventArgs $args * @return mixed|void */ public function onFlush(EventArgs $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); } } } } } } }
/** * @covers PageHelper::getPageRoutePath() */ public function testGetPageRoutePath() { $this->assertEquals('/', PageHelper::getPageRoutePath(''), 'empty route is "/"'); $this->assertEquals('/hallo', PageHelper::getPageRoutePath('hallo'), 'slash at the beginning'); $this->assertEquals('/some/tree/', PageHelper::getPageRoutePath('/some-2/tree-20/'), 'remove -numbers in path'); }