Esempio n. 1
0
    /**
     * Gets a relative filesystem path based on the repository path, AND
     * creates the file on the filesystem if it's in the repository
     * and not yet on the filesystem.
     * The repository path points to a nt-resource node, whose title
     * should be the filename, and which has a child+property
     * jcr:content/jcr:data where the file data is stored.
     *
     * @param string $path path to the nt-resource node.
     * @return string with a path to the file, relative to the web directory.
     */
    public function getUrl(NodeInterface $node)
    {

        $hasData = false;
        if ($node->hasNode('jcr:content')) {
            $contentNode = $node->getNode('jcr:content');
            if ($contentNode->hasProperty('jcr:data')) {
                $hasData = true;
            }
        }
        if (!$hasData) {
            //TODO: notfound exception is not appropriate ... how to best do this?
            //throw new NotFoundHttpException('no picture found at ' . $node->getPath());
            return 'notfound';
        }

        $path = $node->getPath();
        $relativePath = $this->pathMapper->getUrl($path);
        $fullPath = $this->fileBasePath . $relativePath . $this->getExtension($contentNode);

        if (!file_exists($fullPath)) {
            try {
                $this->saveData($contentNode, $fullPath);
            } catch (Imagine\Exception\Exception $e) {
                //TODO: notfound exception is not appropriate ... how to best do this?
                //throw new NotFoundHttpException('image save to filesystem failed: ' . $e->getMessage());
                return 'notfound';
            }
        }

        return $this->webRelativePath . $relativePath . $this->getExtension($contentNode);
    }
Esempio n. 2
0
 public function setUp()
 {
     $this->dm = $this->createDocumentManager(array(__DIR__));
     $repository = $this->dm->getPhpcrSession()->getRepository();
     if (!$repository->getDescriptor('node.type.management.orderable.child.nodes.supported')) {
         $this->markTestSkipped('PHPCR repository doesn\'t support orderable child nodes');
     }
     $this->node = $this->resetFunctionalNode($this->dm);
     $parent = $this->dm->find(null, $this->node->getPath());
     $node1 = new Generic();
     $node1->setParentDocument($parent);
     $node1->setNodename('source');
     $this->dm->persist($node1);
     $this->childrenNames = array('first', 'second', 'third', 'fourth');
     foreach ($this->childrenNames as $childName) {
         $child = new Generic();
         $child->setNodename($childName);
         $child->setParentDocument($node1);
         $this->dm->persist($child);
     }
     $node2 = new Generic();
     $node2->setNodename('target');
     $node2->setParentDocument($parent);
     $this->dm->persist($node2);
     $this->dm->flush();
     $this->dm->clear();
 }
 protected function toJsonLD(NodeInterface $node)
 {
     $data = $node->getPropertiesValues(null, false);
     $data['@'] = $node->getPath();
     $data['a'] = $node->getPrimaryNodeType();
     return $data;
 }
 /**
  * Traverse the node
  *
  * @param NodeInterface|null $node  The node to traverse, if it exists yet
  * @param array $segments  The element => token stack
  * @param array $result  The result
  *
  * @return null
  */
 private function traverse(array $segments, &$result = array(), $node = null)
 {
     $path = array();
     if (null !== $node) {
         $path = explode('/', substr($node->getPath(), 1));
     }
     do {
         list($element, $bitmask) = array_shift($segments);
         if ($bitmask & SelectorParser::T_STATIC) {
             $path[] = $element;
             if ($bitmask & SelectorParser::T_LAST) {
                 if ($node = $this->getNode($path)) {
                     $result[] = $node;
                     break;
                 }
             }
         }
         if ($bitmask & SelectorParser::T_PATTERN) {
             if (null === ($parentNode = $this->getNode($path))) {
                 return;
             }
             $children = $this->getChildren($parentNode, $element);
             foreach ($children as $child) {
                 if ($bitmask & SelectorParser::T_LAST) {
                     $result[] = $child;
                 } else {
                     $this->traverse($segments, $result, $child);
                 }
             }
             return;
         }
     } while ($segments);
 }
 public function setUp()
 {
     $this->typeReference = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\Versioning\\ReferenceTestObj';
     $this->dm = $this->createDocumentManager();
     // Check that the repository supports versioning
     $repository = $this->dm->getPhpcrSession()->getRepository();
     if (!$repository->getDescriptor('option.versioning.supported')) {
         $this->markTestSkipped('PHPCR repository does not support versioning');
     }
     $this->node = $this->resetFunctionalNode($this->dm);
     $versionNode = $this->node->addNode('versionTestObj');
     $versionNode->setProperty('username', 'lsmith');
     $versionNode->setProperty('numbers', array(3, 1, 2));
     $versionNode->setProperty('phpcr:class', $this->typeVersion);
     $versionNode->addMixin("mix:versionable");
     $referenceNode = $this->node->addNode('referenceTestObj');
     $referenceNode->setProperty('content', 'reference test');
     $referenceNode->setProperty('phpcr:class', $this->typeReference);
     $referenceNode->addMixin("mix:referenceable");
     $this->dm->getPhpcrSession()->save();
     $versionNodeWithReference = $this->node->addNode('versionTestObjWithReference');
     $versionNodeWithReference->setProperty('username', 'laupifrpar');
     $versionNodeWithReference->setProperty('numbers', array(6, 4, 5));
     $versionNodeWithReference->setProperty('reference', $referenceNode);
     $versionNodeWithReference->addMixin("mix:versionable");
     $this->dm->getPhpcrSession()->save();
     $this->dm = $this->createDocumentManager();
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey)
 {
     // if exist remove property of node
     if ($node->hasProperty($property->getName())) {
         $node->getProperty($property->getName())->remove();
     }
 }
 /**
  * @param JsonSerializationVisitor $visitor
  * @param NodeInterface            $nodeInterface
  * @param array                    $type
  * @param Context                  $context
  */
 public function serializePhpcrNode(JsonSerializationVisitor $visitor, NodeInterface $node, array $type, Context $context)
 {
     $res = array();
     foreach ($node->getProperties() as $name => $property) {
         $res[$name] = $property->getValue();
     }
     return $res;
 }
 /**
  * {@inheritdoc}
  */
 protected function initialize()
 {
     if (true === $this->initialized) {
         return;
     }
     $this->documents = $this->parentNode->getNodes();
     $this->initialized = true;
 }
 /**
  *
  *
  * @param NodeInterface $contentNode
  * @param string $filesystemPath
  * @return Boolean
  */
 protected function saveData($contentNode, $filesystemPath)
 {
     $data = $contentNode->getProperty('jcr:data')->getString();
     $dirname = dirname($filesystemPath);
     if (!file_exists($dirname)) {
         mkdir($dirname, 0755, true);
     }
     return file_put_contents($filesystemPath, $data);
 }
Esempio n. 10
0
 /**
  * Removes non translated properties.
  *
  * @param NodeInterface $node
  */
 private function upgradeNode(NodeInterface $node)
 {
     foreach ($node->getProperties('i18n:-*') as $property) {
         $property->remove();
     }
     foreach ($node->getNodes() as $childNode) {
         $this->upgradeNode($childNode);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function writeMetadata(DocumentManagerInterface $dm, NodeInterface $node, $className)
 {
     $className = $this->expandClassName($dm, $className);
     if ('Doctrine\\ODM\\PHPCR\\Document\\Generic' !== $className) {
         $node->setProperty('phpcr:class', $className, PropertyType::STRING);
         $class = $dm->getClassMetadata($className);
         $node->setProperty('phpcr:classparents', $class->getParentClasses(), PropertyType::STRING);
     }
 }
Esempio n. 12
0
 /**
  * {@inheritdoc}
  */
 public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey)
 {
     $value = $property->getValue();
     if ($value !== null) {
         $node->setProperty($property->getName(), $this->removeValidation($this->removeIllegalCharacters($value)));
     } else {
         $this->remove($node, $property, $webspaceKey, $languageCode, $segmentKey);
     }
 }
Esempio n. 13
0
 /**
  * {@inheritdoc}
  */
 public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey)
 {
     $value = $property->getValue();
     if ($value !== null && $value !== false && $value !== 'false' && $value !== '') {
         $node->setProperty($property->getName(), true);
     } else {
         $node->setProperty($property->getName(), false);
     }
 }
Esempio n. 14
0
 protected function createNodes(NodeInterface $parentNode, $number, $properties = array(), $offset = 0)
 {
     $number = $number + $offset;
     for ($i = $offset; $i < $number; $i++) {
         $node = $parentNode->addNode('node-' . $i);
         foreach ($properties as $property => $value) {
             $node->setProperty($property, $value);
         }
     }
 }
Esempio n. 15
0
 private function traverse(NodeInterface $node)
 {
     $i = 10;
     foreach ($node->getNodes() as $childNode) {
         $childNode->setProperty(NodeOrderSubscriber::SULU_ORDER, $i);
         $this->context->getOutput()->writeln(sprintf('<info>[+]</info> Setting order "<comment>%s</comment>" on <comment>%s</comment>', $i, $childNode->getPath()));
         $this->traverse($childNode);
         $i += 10;
     }
 }
 /**
  * Transform a node into a uuid
  *
  * @param \PHPCR\NodeInterface|null $node
  *
  * @return string|null the uuid to the node or null if $node is null
  *
  * @throws UnexpectedTypeException if given value is not a PHPCR\NodeInterface
  */
 public function transform($node)
 {
     if (null === $node) {
         return null;
     }
     if (!$node instanceof NodeInterface) {
         throw new UnexpectedTypeException($node, 'PHPCR\\NodeInterface');
     }
     return $node->getIdentifier();
 }
Esempio n. 17
0
 protected function getTranslationNode(NodeInterface $parentNode, $locale)
 {
     $name = Translation::LOCALE_NAMESPACE . ":{$locale}";
     if (!$parentNode->hasNode($name)) {
         $node = $parentNode->addNode($name);
     } else {
         $node = $parentNode->getNode($name);
     }
     return $node;
 }
Esempio n. 18
0
 public function setUp()
 {
     $this->type = 'Doctrine\\Tests\\Models\\CMS\\CmsUser';
     $this->dm = $this->createDocumentManager(array(__DIR__));
     $this->node = $this->resetFunctionalNode($this->dm);
     $user = $this->node->addNode('lsmith');
     $user->setProperty('username', 'lsmith');
     $user->setProperty('numbers', array(3, 1, 2));
     $user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
     $this->dm->getPhpcrSession()->save();
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey)
 {
     $value = '';
     if ($node->hasProperty($property->getName())) {
         /** @var \DateTime $propertyValue */
         $propertyValue = $node->getPropertyValue($property->getName());
         $value = $propertyValue->format('Y-m-d');
     }
     $property->setValue($value);
     return $value;
 }
Esempio n. 20
0
 public function it_should_provide_a_method_to_determine_if_a_node_is_versionable(NodeInterface $nodeVersionable, NodeInterface $nodeNotVersionable, NodeTypeInterface $mixin1, NodeTypeInterface $mixin2)
 {
     $nodeVersionable->getMixinNodeTypes()->willReturn(array($mixin1, $mixin2));
     $nodeNotVersionable->getMixinNodeTypes()->willReturn(array($mixin2));
     $nodeNotVersionable->getPath()->willReturn('foobar');
     $mixin1->getName()->willReturn('mix:versionable');
     $this->assertNodeIsVersionable($nodeVersionable)->shouldReturn(null);
     try {
         $this->assertNodeIsVersionable($nodeNotVersionable);
     } catch (\OutOfBoundsException $e) {
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getLocalesFor($document, NodeInterface $node, ClassMetadata $metadata)
 {
     $locales = array();
     foreach ($node->getProperties("*{$this->prefix}*") as $prop) {
         $matches = null;
         if (preg_match('/' . $this->prefix . ':(..)-[^-]*/', $prop->getName(), $matches)) {
             if (is_array($matches) && count($matches) > 1 && !in_array($matches[1], $locales)) {
                 $locales[] = $matches[1];
             }
         }
     }
     return $locales;
 }
Esempio n. 22
0
 public function loadFixtures()
 {
     $contentMapperRequest = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('en')->setUserId(1)->setData(['title' => 'ElePHPant'])->setState(StructureInterface::STATE_PUBLISHED);
     $this->snippet1 = $this->contentMapper->saveRequest($contentMapperRequest);
     $contentMapperRequest = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('de')->setUserId(1)->setData(['title' => 'Penguin'])->setState(StructureInterface::STATE_PUBLISHED);
     $this->snippet2 = $this->contentMapper->saveRequest($contentMapperRequest);
     $this->snippet1Node = $this->session->getNodeByIdentifier($this->snippet1->getUuid());
     $this->snippet1OriginalPath = $this->snippet1Node->getPath();
     $contentMapperRequest = ContentMapperRequest::create()->setUuid($this->snippet1->getUuid())->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('de')->setUserId(1)->setData(['title' => 'English ElePHPant'])->setState(StructureInterface::STATE_PUBLISHED);
     $this->contentMapper->saveRequest($contentMapperRequest);
     $contentMapperRequest = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('en')->setUserId(1)->setData(['title' => 'Some other animal'])->setState(StructureInterface::STATE_PUBLISHED);
     $this->contentMapper->saveRequest($contentMapperRequest);
 }
Esempio n. 23
0
 /**
  * {@inheritdoc}
  */
 public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey)
 {
     $value = $this->defaultValue;
     if ($node->hasProperty($property->getName())) {
         $value = $node->getPropertyValue($property->getName());
     }
     // the RedirectType subscriber sets the internal link as a reference
     if ($value instanceof NodeInterface) {
         $value = $value->getIdentifier();
     }
     $property->setValue($value);
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 public function resolveMetadataForNode(NodeInterface $node)
 {
     if (false === $node->hasProperty('jcr:mixinTypes')) {
         return;
     }
     $mixinTypes = (array) $node->getPropertyValue('jcr:mixinTypes');
     foreach ($mixinTypes as $mixinType) {
         if (true == $this->metadataFactory->hasMetadataForPhpcrType($mixinType)) {
             return $this->metadataFactory->getMetadataForPhpcrType($mixinType);
         }
     }
     return;
 }
Esempio n. 25
0
 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'));
 }
Esempio n. 26
0
 private function traverse(NodeInterface $node, $readProperties = false)
 {
     if ($readProperties) {
         foreach ($node->getProperties() as $property) {
             try {
                 $property->getValue();
             } catch (\PHPCR\RepositoryException $e) {
             }
         }
     }
     foreach ($node->getNodes() as $child) {
         $this->traverse($child, $readProperties);
     }
 }
Esempio n. 27
0
 public function it_can_normalize_a_node_to_an_array(NodeInterface $node, PropertyInterface $p1, PropertyInterface $p2, PropertyInterface $p3)
 {
     $node->getProperties()->willReturn([$p1, $p2, $p3]);
     $p1->getName()->willReturn('my:property.1');
     $p1->getType()->willReturn(PropertyType::STRING);
     $p1->getValue()->willReturn('P1 Val');
     $p2->getName()->willReturn('my:property.2');
     $p2->getType()->willReturn(PropertyType::DOUBLE);
     $p2->getValue()->willReturn('P2 Val');
     $p3->getName()->willReturn('my:property.3');
     $p3->getType()->willReturn(PropertyType::STRING);
     $p3->getValue()->willReturn('P3 Val');
     $this->normalize($node)->shouldReturn(['my:property.1' => ['type' => 'String', 'value' => 'P1 Val'], 'my:property.2' => ['type' => 'Double', 'value' => 'P2 Val'], 'my:property.3' => ['type' => 'String', 'value' => 'P3 Val']]);
 }
 public function setUp()
 {
     $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\TypeUser';
     $this->dm = $this->createDocumentManager(array(__DIR__));
     $this->node = $this->resetFunctionalNode($this->dm);
     $user = $this->node->addNode('user');
     $user->setProperty('username', 'lsmith');
     $user->setProperty('note', 'test');
     $user->setProperty('numbers', array(3, 1, 2));
     $user->setProperty('parameters', array('bar', 'dong'));
     $user->setProperty('parameterKey', array('foo', 'ding'));
     $user->setProperty('phpcr:class', $this->type, PropertyType::STRING);
     $this->dm->getPhpcrSession()->save();
 }
Esempio n. 29
0
 public function testLoadWithoutData()
 {
     $content = [];
     $this->node->getPropertyValueWithDefault(Argument::any(), Argument::any())->will(function ($arguments) use(&$content) {
         if (isset($content[$arguments[0]])) {
             return $content[$arguments[0]];
         } else {
             return $arguments[1];
         }
     });
     $this->extension->setLanguageCode('de', 'i18n', null);
     $result = $this->extension->load($this->node->reveal(), 'default', 'de');
     $this->assertEquals(['title' => '', 'description' => '', 'keywords' => '', 'canonicalUrl' => '', 'noIndex' => false, 'noFollow' => false, 'hideInSitemap' => false], $result);
 }
Esempio n. 30
0
 private function walkNode(NodeBuilder $builder, NodeInterface $parentNode)
 {
     for ($i = $builder->getRangeStart(); $i <= $builder->getRangeEnd(); $i++) {
         $name = str_replace(NodeBuilder::ITERATION_TOKEN, $i, $builder->getName());
         $this->count++;
         $node = $parentNode->addNode($name, $builder->getNodeTypeName());
         foreach ($builder->getProperties() as $property) {
             list($name, $value, $type) = $property;
             $node->setProperty($name, $value, PropertyType::valueFromName($type));
         }
         foreach ($builder->getNodes() as $childNodeBuilder) {
             $this->walkNode($childNodeBuilder, $node);
         }
     }
 }