/** * {@inheritdoc}. */ public function load($sitemap) { // todo rewrite query when https://github.com/symfony-cmf/CoreBundle/issues/126 is ready $documentsCollection = $this->manager->createQuery('SELECT * FROM [nt:unstructured] WHERE (visible_for_sitemap = true)', QueryInterface::JCR_SQL2)->execute(); $documents = array(); // the chain provider does not like collections as we array_merge in there foreach ($documentsCollection as $document) { $documents[] = $document; } return $documents; }
public function createAction() { // bind form to page model $page = new Page(); $this->form->bind($this->request, $page); if ($this->form->isValid()) { try { // path for page $parent = $this->form->get('parent')->getData(); $path = $parent . '/' . $page->name; // save page $this->dm->persist($page, $path); $this->dm->flush(); // redirect with message $this->request->getSession()->setFlash('notice', 'Page created!'); return $this->redirect($this->generateUrl('admin')); } catch (HTTPErrorException $e) { $path = new PropertyPath('name'); $this->form->addError(new DataError('Name already in use.'), $path->getIterator()); } } return $this->render('SandboxAdminBundle:Admin:create.html.twig', array('form' => $this->form)); }
/** * Load meta object by provided type and parameters. * * @MetaLoaderDoc( * description="Article Loader loads articles from Content Repository", * parameters={ * contentPath="SINGLE|required content path", * slug="SINGLE|required content slug", * pageName="COLLECTiON|name of Page for required articles" * } * ) * * @param string $type object type * @param array $parameters parameters needed to load required object type * @param int $responseType response type: single meta (LoaderInterface::SINGLE) or collection of metas (LoaderInterface::COLLECTION) * * @return Meta|Meta[]|bool false if meta cannot be loaded, a Meta instance otherwise */ public function load($type, $parameters, $responseType = LoaderInterface::SINGLE) { $article = null; if (empty($parameters)) { $parameters = []; } if ($responseType === LoaderInterface::SINGLE) { if (array_key_exists('contentPath', $parameters)) { $article = $this->dm->find('SWP\\ContentBundle\\Document\\Article', $parameters['contentPath']); } elseif (array_key_exists('slug', $parameters)) { $article = $this->dm->getRepository('SWP\\ContentBundle\\Document\\Article')->findOneBy(array('slug' => $parameters['slug'])); } if (!is_null($article)) { return new Meta($this->rootDir . '/Resources/meta/article.yml', $article); } } elseif ($responseType === LoaderInterface::COLLECTION) { if (array_key_exists('pageName', $parameters)) { $page = $this->em->getRepository('SWP\\ContentBundle\\Model\\Page')->getByName($parameters['pageName'])->getOneOrNullResult(); if ($page) { $articlePages = $this->em->getRepository('SWP\\ContentBundle\\Model\\PageContent')->getForPage($page)->getResult(); $articles = []; foreach ($articlePages as $articlePage) { $article = $this->dm->find('SWP\\ContentBundle\\Document\\Article', $articlePage->getContentPath()); if (!is_null($article)) { $articles[] = new Meta($this->rootDir . '/Resources/meta/article.yml', $article); } } return $articles; } } } return false; }
/** * @return a Navigation instance with the specified information */ protected function createMenuNode(DocumentManager $dm, $parent, $name, $label, $content, $uri = null, $route = null) { if (!$parent instanceof MenuNode && !$parent instanceof Menu) { $menuNode = new Menu(); } else { $menuNode = new MenuNode(); } $menuNode->setParent($parent); $menuNode->setName($name); $dm->persist($menuNode); // do persist before binding translation if (null !== $content) { $menuNode->setContent($content); } else { if (null !== $uri) { $menuNode->setUri($uri); } else { if (null !== $route) { $menuNode->setRoute($route); } } } if (is_array($label)) { foreach ($label as $locale => $l) { $menuNode->setLabel($l); $dm->bindTranslation($menuNode, $locale); } } else { $menuNode->setLabel($label); } return $menuNode; }
/** * Constructor * * @param SessionInterface $session * @param DocumentManager $dm */ public function __construct(SessionInterface $session = null, DocumentManager $dm = null) { if (!$session && $dm) { $session = $dm->getPhpcrSession(); } parent::__construct($session); $this->dm = $dm; }
public function testGetByIdsFilter() { $qb = $this->dm->getRepository('Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument')->createQueryBuilder('e'); $qb->where()->eq()->field('e.text')->literal('thiswillnotmatch'); $loader = new PhpcrOdmQueryBuilderLoader($qb, $this->dm); $documents = $loader->getEntitiesByIds('id', array('/test/doc')); $this->assertCount(0, $documents); }
public function setUp() { $this->dm = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock(); $this->dm->expects($this->once())->method('find')->will($this->returnValue(new \stdClass())); $this->defaultModelManager = $this->getMockBuilder('Sonata\\DoctrinePHPCRAdminBundle\\Model\\ModelManager')->disableOriginalConstructor()->getMock(); $this->translator = $this->getMockBuilder('Symfony\\Component\\Translation\\TranslatorInterface')->disableOriginalConstructor()->getMock(); $this->assetHelper = $this->getMockBuilder('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')->disableOriginalConstructor()->getMock(); $this->pool = $this->getMockBuilder('Sonata\\AdminBundle\\Admin\\Pool')->disableOriginalConstructor()->getMock(); }
/** * @param DocumentManager * @param object $document * @param string $className * @throws \InvalidArgumentException */ public function validateClassName(DocumentManager $dm, $document, $className) { if (!$document instanceof $className) { $class = $dm->getClassMetadata(get_class($document)); $path = $class->getIdentifierValue($document); $msg = "Doctrine metadata mismatch! Requested type '{$className}' type does not match type '" . get_class($document) . "' stored in the metadata at path '{$path}'"; throw new \InvalidArgumentException($msg); } }
public function testFiltered() { $qb = $this->dm->getRepository('Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument')->createQueryBuilder('e'); $qb->where()->eq()->field('e.text')->literal('thiswillnotmatch'); $formBuilder = $this->createFormBuilder($this->referrer); $formBuilder->add('single', $this->legacy ? 'phpcr_document' : 'Doctrine\\Bundle\\PHPCRBundle\\Form\\Type\\DocumentType', array('class' => 'Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument', 'query_builder' => $qb)); $html = $this->renderForm($formBuilder); $this->assertContains('<select id="form_single" name="form[single]"', $html); $this->assertNotContains('<option', $html); }
/** * Create a new repository instance for a document class. * * @param DocumentManager $documentManager The DocumentManager instance. * @param string $documentName The name of the document. * * @return \Doctrine\Common\Persistence\ObjectRepository */ protected function createRepository(DocumentManager $documentManager, $documentName) { $metadata = $documentManager->getClassMetadata($documentName); $repositoryClassName = $metadata->customRepositoryClassName; if ($repositoryClassName === null) { $configuration = $documentManager->getConfiguration(); $repositoryClassName = $configuration->getDefaultRepositoryClassName(); } return new $repositoryClassName($documentManager, $metadata); }
/** * @param \ServerGrove\KbBundle\Document\Article $article * @param string $locale * @return string */ public function renderArticleLocale(Article $article, $locale) { try { $active = $this->manager->findTranslation(get_class($article), $article->getId(), $locale, false)->getIsActive(); } catch (\InvalidArgumentException $e) { $active = false; } $this->manager->refresh($article); return $this->twig->renderBlock('article_locale', array('active' => $active, 'locale' => $locale, 'locale_name' => Locale::getDisplayLanguage($locale))); }
/** * @return Page instance with the specified information */ protected function createPage(DocumentManager $manager, $parent, $name, $label, $title, $body) { $page = new Page(); $page->setPosition($parent, $name); $page->setLabel($label); $page->setTitle($title); $page->setBody($body); $manager->persist($page); return $page; }
public function testReferenceOneDifferentTargetDocuments() { $ref1 = new RefType1TestObj(); $ref1->id = '/functional/ref1'; $ref1->name = 'Ref1'; $ref2 = new RefType2TestObj(); $ref2->id = '/functional/ref2'; $ref2->name = 'Ref2'; $this->dm->persist($ref1); $this->dm->persist($ref2); $referer1 = new ReferenceOneObj(); $referer1->id = '/functional/referer1'; $referer1->reference = $ref1; $this->dm->persist($referer1); $referer2 = new ReferenceOneObj(); $referer2->id = '/functional/referer2'; $referer2->reference = $ref2; $this->dm->persist($referer2); $this->dm->flush(); $this->dm->clear(); $referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer1'); $this->assertTrue($referer->reference instanceof RefType1TestObj); $referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer2'); $this->assertTrue($referer->reference instanceof RefType2TestObj); }
/** * {@inheritdoc} */ public function reverseTransform($id) { if ($id === null) { return; } $document = $this->manager->find(null, $id); if ($document === null) { throw new TransformationFailedException(sprintf("An document with id: %s does not exist", $id)); } return $document; }
public function setUp() { $this->legacy = !method_exists('Symfony\\Component\\Form\\AbstractType', 'getBlockPrefix'); $this->entryTypeOption = $this->legacy ? 'type' : 'entry_type'; $this->db('PHPCR')->loadFixtures(array('Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\DataFixtures\\PHPCR\\LoadData')); $this->dm = $this->db('PHPCR')->getOm(); $this->document = $this->dm->find(null, '/test/doc'); $this->assertNotNull($this->document, 'fixture loading not working'); $this->referrer = $this->dm->find(null, '/test/ref'); $this->assertNotNull($this->referrer, 'fixture loading not working'); }
/** * {@inheritDoc} */ public function getContentId($content) { if (!is_object($content)) { return null; } try { return $this->documentManager->getUnitOfWork()->getDocumentId($content); } catch (\Exception $e) { return null; } }
public function testMigrator() { $this->migrator->migrate('/test/page'); $this->migrator->migrate('/test/page/foo'); $res = $this->dm->find(null, '/test/page'); $this->assertNotNull($res); $this->assertEquals('Test', $res->getTitle()); $res = $this->dm->find(null, '/test/page/foo'); $this->assertNotNull($res); $this->assertEquals('Foobar', $res->getTitle()); }
/** * {@inheritdoc} */ public function load($sitemap) { $documentsCollection = $this->manager->getRepository('nvbooster\\StarterBundle\\Document\\SeoContent')->findAll(); $documents = array(); foreach ($documentsCollection as $document) { /* @var $document SeoContent */ if (count($document->getRoutes())) { $documents[] = $document; } } return $documents; }
/** * @param object $document * @param ClassMetadata $cm * @param DocumentManager $dm * @return string */ public function generate($document, ClassMetadata $cm, DocumentManager $dm) { $repository = $dm->getRepository($cm->name); if (!$repository instanceof RepositoryIdInterface) { throw new \RuntimeException("ID could not be determined. Make sure the that the Repository '" . get_class($repository) . "' implements RepositoryIdInterface"); } $id = $repository->generateId($document); if (!$id) { throw new \RuntimeException("ID could not be determined. Repository was unable to generate an ID"); } return $id; }
public function resetFunctionalNode(DocumentManager $dm) { $session = $dm->getPhpcrSession(); $root = $session->getNode('/'); if ($root->hasNode('functional')) { $root->getNode('functional')->remove(); $session->save(); } $node = $root->addNode('functional'); $session->save(); $dm->clear(); return $node; }
/** * @param DocumentManager $dm * @param $path * @param $name * * @return bool|Directory */ public static function mkdir(DocumentManager $dm, $path, $name) { $dirname = self::cleanPath($path, $name); if ($dm->find(null, $dirname)) { return false; } $dir = new Directory(); $dir->setName($name); $dir->setId($dirname); $dm->persist($dir); $dm->flush(); return $dir; }
/** * Create the guesser for this test. * * @return GuesserInterface */ protected function createGuesser() { $this->registry = $this->getMockBuilder('\\Doctrine\\Bundle\\PHPCRBundle\\ManagerRegistry')->disableOriginalConstructor()->getMock(); $this->manager = $this->getMockBuilder('\\Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock(); $this->metadata = $this->getMockBuilder('\\Doctrine\\ODM\\PHPCR\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->any())->method('getManagerForClass')->with($this->equalTo('Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Unit\\Sitemap\\LastModifiedGuesserTest'))->will($this->returnValue($this->manager)); $this->manager->expects($this->any())->method('getClassMetadata')->with($this->equalTo('Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Unit\\Sitemap\\LastModifiedGuesserTest'))->will($this->returnValue($this->metadata)); $this->metadata->expects($this->any())->method('getMixins')->will($this->returnValue(array('mix:lastModified'))); $this->metadata->expects($this->any())->method('getFieldNames')->will($this->returnValue(array('lastModified'))); $this->metadata->expects($this->any())->method('getFieldMapping')->with($this->equalTo('lastModified'))->will($this->returnValue(array('property' => 'jcr:lastModified'))); $this->metadata->expects($this->any())->method('getFieldValue')->with($this->equalTo($this), $this->equalTo('lastModified'))->will($this->returnValue(new \DateTime('2016-07-06', new \DateTimeZone('Europe/Berlin')))); return new LastModifiedGuesser($this->registry); }
public function testCreateCascade() { $folder = new Folder(); $folder->setId('/functional/folder'); $file = new File(); $file->setFileContent(self::FILE_CONTENT); $file->setNodename('file'); $folder->addChild($file); $this->dm->persist($folder); $this->dm->flush(); $this->dm->clear(); $this->assertFolderAndFile($this->node); }
protected function buildName($document, ClassMetadata $class, DocumentManager $dm, $parent, $name) { // get the id of the parent document $id = $dm->getUnitOfWork()->getDocumentId($parent); if (!$id) { throw IdException::parentIdCouldNotBeDetermined($document, $class->parentMapping, $parent); } // edge case parent is root if ('/' === $id) { $id = ''; } return $id . '/' . $name; }
public function testCreatedDate() { $parent = new FileTestObj(); $parent->file = new File(); $parent->id = '/functional/filetest'; $parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt'); $this->dm->persist($parent); $this->dm->flush(); $this->dm->clear(); $file = $this->dm->find('Doctrine\\ODM\\PHPCR\\Document\\File', '/functional/filetest/file'); $this->assertNotNull($file); $this->assertNotNull($file->getCreated()); }
public function testCreateFromFile() { $parent = new FixPHPCR1TestObj(); $parent->id = '/functional/filetest'; $this->dm->persist($parent); $parent->file = new File(); $parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt'); $this->dm->flush(); $this->dm->clear(); $this->assertTrue($this->node->getNode('filetest')->hasNode('file')); $this->assertTrue($this->node->getNode('filetest')->getNode('file')->hasNode('jcr:content')); $this->assertTrue($this->node->getNode('filetest')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data')); }
public function setUp() { $this->db('PHPCR')->createTestNode(); $this->dm = $this->db('PHPCR')->getOm(); $this->base = $this->dm->find(null, '/test'); $this->db('PHPCR')->loadFixtures(array('Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\DataFixtures\\Phpcr\\LoadSitemapData')); $this->logger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->presentation = $this->getMockBuilder('\\Symfony\\Cmf\\Bundle\\SeoBundle\\SeoPresentation')->disableOriginalConstructor()->getMock(); $this->provider = new SitemapUrlInformationProvider($this->dm, $this->getContainer()->get('router'), 'always', $this->logger, $this->presentation, $this->getContainer()->get('cmf_core.publish_workflow.checker')); $this->alternateLocaleProvider = $this->getMock('\\Symfony\\Cmf\\Bundle\\SeoBundle\\AlternateLocaleProviderInterface'); $this->provider->setAlternateLocaleProvider($this->alternateLocaleProvider); $alternateLocale = new AlternateLocale('test', 'de'); $this->alternateLocaleProvider->expects($this->any())->method('createForContent')->will($this->returnValue(new ArrayCollection(array($alternateLocale)))); }
public function testResetEvents() { $page = new CmsPage(); $page->title = "my-page"; $pageContent = new CmsPageContent(); $pageContent->id = 1; $pageContent->content = "long story"; $pageContent->formatter = "plaintext"; $page->content = $pageContent; $this->dm->persist($page); $this->assertEquals(serialize(array('id' => $pageContent->id)), $page->content); $this->dm->flush(); $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content); // This is required as the originalData in the UnitOfWork doesn’t set the node of the Document $this->dm->clear(); $pageLoaded = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsPage')->find($page->id); $pageLoaded->title = "my-page-changed"; $this->assertEquals('my-page-changed', $pageLoaded->title); $this->dm->flush(); $this->assertEquals('my-page', $pageLoaded->title); $pageLoaded->content = $pageContent; $this->dm->persist($pageLoaded); $this->dm->flush(); $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content); }
protected function setUp() { if (!interface_exists('Doctrine\\Common\\Persistence\\ManagerRegistry')) { $this->markTestSkipped('Doctrine Common is not present'); } if (!class_exists('Doctrine\\ODM\\PHPCR\\DocumentManager')) { $this->markTestSkipped('Doctrine PHPCR is not present'); } $this->registry = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock(); $this->manager = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->manager)); $this->repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository', array('customQueryBuilderCreator', 'createQueryBuilder', 'find', 'findAll', 'findBy', 'findOneBy', 'getClassName')); $this->manager->expects($this->any())->method('getRepository')->with($this->objectClass)->will($this->returnValue($this->repository)); }
public function testModificationWithProtectedProperty() { $object = new ProtectedPropertyTestObj(); $object->id = '/functional/pp'; try { $this->dm->persist($object); $this->dm->flush(); $object->changeme = 'changed'; $this->dm->flush(); $this->dm->clear(); } catch (\PHPCR\NodeType\ConstraintViolationException $e) { $this->fail(sprintf('A ConstraintViolationException has been thrown when persisting document ("%s").', $e->getMessage())); } $this->assertTrue(true); }