public function preBuild(Fixture $fixture) { $properties = $fixture->getProperties(); if (!isset($properties['folder'])) { throw new \Exception('There is no folder specified for media fixture ' . $fixture->getName()); } $this->folder = $this->em->getRepository('KunstmaanMediaBundle:Folder')->findOneBy(array('rel' => $properties['folder'])); if (!$this->folder instanceof Folder) { throw new \Exception('Could not find the specified folder for media fixture ' . $fixture->getName()); } }
public function postFlushBuild(Fixture $fixture) { $params = $fixture->getParameters(); $translations = $fixture->getTranslations(); $original = $fixture->getEntity(); if (!isset($params['page']) || empty($translations)) { throw new \Exception('No page reference and/or translations detected for pagepart fixture ' . $fixture->getName() . ' (' . $fixture->getClass() . ')'); } $pageFixture = $params['page']; if (!$pageFixture instanceof Fixture) { throw new \Exception('Could not find a reference "' . $params['page'] . '"" for fixture ' . $fixture->getName() . ' (' . $fixture->getClass() . ')'); } $additionalEntities = $pageFixture->getAdditionalEntities(); $pp = $original; $first = null; foreach ($translations as $language => $data) { $key = $pageFixture->getName() . '_' . $language; if (!isset($additionalEntities[$key])) { continue; } if ($first !== null) { $pp = clone $original; } $page = $additionalEntities[$key]; $this->populator->populate($pp, $data); $this->em->persist($pp); $this->em->flush($pp); // Find latest position. $position = array_key_exists('position', $params) ? $params['position'] : null; $context = isset($params['context']) ? $params['context'] : 'main'; if (is_null($position)) { $pageParts = $this->pagePartRepo->getPagePartRefs($page, $context); $position = count($pageParts) + 1; } $this->pagePartRepo->addPagePart($page, $pp, $position, $context); $first = false; } }
public function postFlushBuild(Fixture $fixture) { $entities = $fixture->getAdditionalEntities(); $fixtureParams = $fixture->getParameters(); foreach ($fixture->getTranslations() as $language => $data) { /** @var HasNodeInterface $page */ $page = $entities[$fixture->getName() . '_' . $language]; /** @var NodeTranslation $translationNode */ $translationNode = $entities['translationNode_' . $language]; $pagecreator = array_key_exists('creator', $fixtureParams) ? $fixtureParams['creator'] : 'pagecreator'; $creator = $this->userRepo->findOneBy(array('username' => $pagecreator)); $nodeVersion = new NodeVersion(); $nodeVersion->setNodeTranslation($translationNode); $nodeVersion->setType('public'); $nodeVersion->setOwner($creator); $nodeVersion->setRef($page); $translationNode->setPublicNodeVersion($nodeVersion); if (isset($fixtureParams['template'])) { $pageTemplateConfiguration = new PageTemplateConfiguration(); $pageTemplateConfiguration->setPageId($page->getId()); $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page)); $pageTemplateConfiguration->setPageTemplate($fixtureParams['template']); $this->manager->persist($pageTemplateConfiguration); } $this->manager->persist($nodeVersion); $this->manager->persist($translationNode); } $this->manager->flush(); }