Exemplo n.º 1
0
 public function __construct(ManagerRegistry $registry, $basepath, $dataDir)
 {
     $this->dm = $registry->getManager();
     $this->session = $registry->getConnection();
     $this->basepath = $basepath;
     $this->dataDir = $dataDir;
 }
Exemplo n.º 2
0
 public function testBuildForm()
 {
     $test = $this;
     $this->reg->expects($this->once())->method('getManager')->with(null)->will($this->returnValue($this->dm));
     $this->builder->expects($this->once())->method('addModelTransformer')->will($this->returnCallback(function ($transformer) use($test) {
         $test->assertInstanceOf('Doctrine\\Bundle\\PHPCRBundle\\Form\\DataTransformer\\DocumentToPathTransformer', $transformer);
         return;
     }));
     $this->type->buildForm($this->builder, array('manager_name' => null));
 }
Exemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function init(ManagerRegistry $registry)
 {
     $session = $registry->getConnection();
     if ($this->cnd) {
         $this->registerCnd($session, $this->cnd);
     }
     if (count($this->basePaths)) {
         $this->createBasePaths($session, $this->basePaths);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function init(ManagerRegistry $registry)
 {
     /** @var SessionInterface $session */
     $session = $registry->getConnection();
     /** @var Query $tenantsQuery */
     $tenantsQuery = $this->tenantProvider->getAvailableTenants();
     /** @var Collection $tenants */
     $tenants = $tenantsQuery->getResult();
     $this->generateBasePaths($session, $tenants->toArray());
 }
 /**
  * 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);
 }
 /**
  * @param ManagerRegistry $registry
  */
 public function init(ManagerRegistry $registry)
 {
     $documentManager = $registry->getManager();
     if ($documentManager->find(null, $this->basePath)) {
         return;
     }
     $homepage = new Homepage();
     $homepage->setName($this->basePath);
     $documentManager->persist($homepage);
     $documentManager->flush();
     $session = $registry->getConnection();
     // Create Fixtures
     NodeHelper::createPath($session, $this->basePath . '/fixtures/routes');
     $session->save();
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function guessValues(UrlInformation $urlInformation, $object, $sitemap)
 {
     if (null !== $urlInformation->getDepth()) {
         return;
     }
     $manager = $this->managerRegistry->getManagerForClass(ClassUtils::getRealClass(get_class($object)));
     if (!$manager instanceof DocumentManager) {
         return;
     }
     $node = $manager->getNodeForDocument($object);
     if (null === $node) {
         return;
     }
     $urlInformation->setDepth($node->getDepth() - $this->offset);
 }
 /**
  * {@inheritDoc}
  */
 public function init(ManagerRegistry $registry)
 {
     /** @var $dm DocumentManager */
     $dm = $registry->getManagerForClass('Symfony\\Cmf\\Bundle\\SimpleCmsBundle\\Doctrine\\Phpcr\\Page');
     if ($dm->find(null, $this->basePath)) {
         return;
     }
     $session = $dm->getPhpcrSession();
     NodeHelper::createPath($session, PathHelper::getParentPath($this->basePath));
     $page = new $this->documentClass();
     $page->setId($this->basePath);
     $page->setLabel('Home');
     $page->setTitle('Homepage');
     $page->setBody('Autocreated Homepage');
     $dm->persist($page);
     $dm->flush();
 }
Exemplo n.º 9
0
 public function init(ManagerRegistry $registry)
 {
     $dm = $registry->getManager();
     if ($dm->find(null, $this->basePath)) {
         return;
     }
     $site = new Site();
     $site->setId($this->basePath);
     $dm->persist($site);
     $dm->flush();
     $session = $registry->getConnection();
     // create the 'cms', 'pages', and 'posts' nodes
     NodeHelper::createPath($session, $this->basePath . '/pages');
     NodeHelper::createPath($session, $this->basePath . '/posts');
     NodeHelper::createPath($session, $this->basePath . '/routes');
     $session->save();
 }
Exemplo n.º 10
0
 /**
  * This method should be used to establish the requisite
  * structure needed by the application or bundle of the
  * content repository.
  *
  * @param ManagerRegistry $registry
  */
 public function init(ManagerRegistry $registry)
 {
     $documentManager = $registry->getManager();
     if ($documentManager->find(null, $this->basePath)) {
         return;
     }
     $site = new Site();
     $site->setId($this->basePath);
     $documentManager->persist($site);
     $documentManager->flush();
     $session = $registry->getConnection();
     NodeHelper::createPath($session, $this->basePath . '/articles');
     NodeHelper::createPath($session, $this->basePath . '/events');
     NodeHelper::createPath($session, $this->basePath . '/pages');
     NodeHelper::createPath($session, $this->basePath . '/posts');
     NodeHelper::createPath($session, $this->basePath . '/routes');
     $session->save();
 }
Exemplo n.º 11
0
 public function testRootEdgeCase()
 {
     $this->buildMocks('/');
     $this->managerRegistry->expects($this->any())->method('getManagerForClass')->with(get_class($this->object))->will($this->returnValue($this->documentManager));
     $this->documentManager->expects($this->any())->method('getNodeForDocument')->with($this->object)->willReturn($this->node);
     $this->node->expects($this->any())->method('getDepth')->will($this->returnValue(4));
     $urlInformation = new UrlInformation();
     $this->guesser->guessValues($urlInformation, $this->object, 'default');
     $this->assertEquals(3, $urlInformation->getDepth());
 }
 /**
  * {@inheritdoc}
  */
 public function init(ManagerRegistry $registry)
 {
     /** @var $dm DocumentManager */
     $dm = $registry->getManagerForClass('AppBundle\\Document\\SeoPage');
     if ($dm->find(null, $this->basePath)) {
         return;
     }
     $session = $dm->getPhpcrSession();
     NodeHelper::createPath($session, PathHelper::getParentPath($this->basePath));
     /** @var \AppBundle\Document\SeoPage $page */
     $page = new $this->documentClass();
     $page->setId($this->basePath);
     $page->setLabel('Home');
     $page->setTitle('Homepage');
     $page->setBody('Autocreated Homepage');
     $page->setIsVisibleForSitemap(true);
     $dm->persist($page);
     $dm->flush();
 }
 /**
  * @param string $class
  *
  * @return mixed
  */
 protected function getMetadata($class)
 {
     if (array_key_exists($class, $this->cache)) {
         return $this->cache[$class];
     }
     $this->cache[$class] = null;
     foreach ($this->registry->getManagers() as $dm) {
         try {
             return $this->cache[$class] = $dm->getClassMetadata($class);
         } catch (MappingException $e) {
             // not an entity or mapped super class
         }
     }
 }
Exemplo n.º 14
0
 /**
  * This method should be used to establish the requisite
  * structure needed by the application or bundle of the
  * content repository.
  *
  * @param ManagerRegistry $registry
  */
 public function init(ManagerRegistry $registry)
 {
     $className = self::MENU_DOCUMENT_CLASS_NAME;
     /** @var DocumentManager $dm */
     $dm = $registry->getManagerForClass($className);
     /** @var Generic $parent */
     $menuRoot = $this->menuProvider->getMenuRoot();
     $parent = $dm->find(null, $menuRoot);
     if (!$parent) {
         throw new \InvalidArgumentException("Cannot find menu base path '{$this->menuProvider}'.");
     }
     foreach ($this->menus as $menuName => $menuLabel) {
         /** @var Menu $menu */
         $menu = $dm->find($className, $menuRoot . '/' . $menuName);
         if (!$menu) {
             $menu = new $className();
         }
         $menu->setName($menuName);
         $menu->setLabel($menuLabel);
         $menu->setParentDocument($parent);
         $dm->persist($menu);
     }
     $dm->flush();
 }
Exemplo n.º 15
0
 public function __construct(ManagerRegistry $manager, $sessionName)
 {
     $this->session = $manager->getConnection($sessionName);
 }