You can iterate over the nodes children because it is an IteratorAggregate
Inheritance: extends Item, implements IteratorAggregat\IteratorAggregate, implements PHPCR\NodeInterface
 /**
  * @param Node $node
  */
 private function clearNodeCache(Node $node)
 {
     $cacheKey = "nodes: {$node->getPath()}, " . $this->workspaceName;
     $this->caches['node']->delete($cacheKey);
     // actually in the DBAL all nodes have a uuid ..
     if ($node->isNodeType('mix:referenceable')) {
         $uuid = $node->getIdentifier();
         $cacheKey = "nodes by uuid: {$uuid}, " . $this->workspaceName;
         $this->caches['node']->delete($cacheKey);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function reorderChildren(Node $node)
 {
     $this->assertLoggedIn();
     $values[':absPath'] = $node->getPath();
     $sql = "UPDATE phpcr_nodes SET sort_order = CASE CONCAT(\n          namespace,\n          (CASE namespace WHEN '' THEN '' ELSE ':' END),\n          local_name\n        )";
     $i = 0;
     foreach ($node->getNodeNames() as $name) {
         $values[':name' . $i] = $name;
         $values[':order' . $i] = $i;
         // use our counter to avoid gaps
         $sql .= " WHEN :name" . $i . " THEN :order" . $i;
         $i++;
     }
     $sql .= " ELSE sort_order END WHERE parent = :absPath";
     try {
         $this->getConnection()->executeUpdate($sql, $values);
     } catch (DBALException $e) {
         throw new RepositoryException('Unexpected exception while reordering nodes', $e->getCode(), $e);
     }
     return true;
 }
Beispiel #3
0
    /**
     * TODO: we should move that into the common Jackalope BaseTransport or as new method of NodeType
     * it will be helpful for other implementations.
     *
     * Validate this node with the nodetype and generate not yet existing
     * autogenerated properties as necessary.
     *
     * @param Node     $node
     * @param NodeType $def
     */
    private function validateNodeWithType(Node $node, NodeType $def)
    {
        foreach ($def->getDeclaredChildNodeDefinitions() as $childDef) {
            /* @var $childDef NodeDefinitionInterface */
            if (!$node->hasNode($childDef->getName())) {
                if ('*' === $childDef->getName()) {
                    continue;
                }

                if ($childDef->isMandatory() && !$childDef->isAutoCreated()) {
                    throw new RepositoryException(
                        "Child " . $childDef->getName() . " is mandatory, but is not present while ".
                            "saving " . $def->getName() . " at " . $node->getPath()
                    );
                }

                if ($childDef->isAutoCreated()) {
                    $requiredPrimaryTypeNames = $childDef->getRequiredPrimaryTypeNames();
                    $primaryType = count($requiredPrimaryTypeNames) ? current($requiredPrimaryTypeNames) : null;
                    $newNode = $node->addNode($childDef->getName(), $primaryType);
                    $absPath = $node->getPath() . '/' . $childDef->getName();
                    $operation = new AddNodeOperation($absPath, $newNode);
                    $this->additionalNodeAddOperations[] = $operation;
                }
            }
        }

        foreach ($def->getDeclaredPropertyDefinitions() as $propertyDef) {
            /* @var $propertyDef PropertyDefinitionInterface */
            if ('*' == $propertyDef->getName()) {
                continue;
            }

            if (!$node->hasProperty($propertyDef->getName())) {
                if ($propertyDef->isMandatory() && !$propertyDef->isAutoCreated()) {
                    throw new RepositoryException(
                        "Property " . $propertyDef->getName() . " is mandatory, but is not present while ".
                            "saving " . $def->getName() . " at " . $node->getPath()
                    );
                }
                if ($propertyDef->isAutoCreated()) {
                    switch ($propertyDef->getName()) {
                        case 'jcr:uuid':
                            $value = $this->generateUuid();
                            break;
                        case 'jcr:createdBy':
                        case 'jcr:lastModifiedBy':
                            $value = $this->credentials->getUserID();
                            break;
                        case 'jcr:created':
                        case 'jcr:lastModified':
                            $value = new \DateTime();
                            break;
                        case 'jcr:etag':
                            // TODO: http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.7.12.1%20mix:etag
                            $value = 'TODO: generate from binary properties of this node';
                            break;

                        default:
                            $defaultValues = $propertyDef->getDefaultValues();
                            if ($propertyDef->isMultiple()) {
                                $value = $defaultValues;
                            } elseif (isset($defaultValues[0])) {
                                $value = $defaultValues[0];
                            } else {
                                // When implementing versionable or activity, we need to handle more properties explicitly
                                throw new RepositoryException('No default value for autocreated property '.
                                    $propertyDef->getName(). ' at '.$node->getPath());
                            }
                    }

                    $node->setProperty(
                        $propertyDef->getName(),
                        $value,
                        $propertyDef->getRequiredType()
                    );
                }
            } elseif ($propertyDef->isAutoCreated()) {
                $prop = $node->getProperty($propertyDef->getName());
                if (!$prop->isModified() && !$prop->isNew()) {
                    switch($propertyDef->getName()) {
                        case 'jcr:lastModified':
                            if ($this->getAutoLastModified()) {
                                $prop->setValue(new \DateTime());
                            }
                            break;
                        case 'jcr:lastModifiedBy':
                            if ($this->getAutoLastModified()) {
                                $prop->setValue($this->credentials->getUserID());
                            }
                            break;
                        case 'jcr:etag':
                            // TODO: update etag if needed
                            break;
                    }

                }
            }
        }

        foreach ($def->getDeclaredSupertypes() as $superType) {
            $this->validateNodeWithType($node, $superType);
        }

        foreach ($node->getProperties() as $property) {
            $this->assertValidProperty($property);
        }
    }
Beispiel #4
0
 private function getResponsibleNodeTypes(Node $node)
 {
     // This is very slow i believe :-(
     $nodeDef = $node->getPrimaryNodeType();
     $nodeTypes = $node->getMixinNodeTypes();
     array_unshift($nodeTypes, $nodeDef);
     return $nodeTypes;
 }
Beispiel #5
0
 private function phpcrNodeToNode(\Jackalope\Node $node)
 {
     if ($node->isDeleted()) {
         $properties = $node->getPropertiesForStoreDeletedNode();
     } else {
         $this->nodeProcessor->process($node);
         $properties = $node->getProperties();
     }
     $node = new Node();
     $node->fromPhpcrProperties($properties);
     return $node;
 }
 /**
  * Update the lastModified fields if they where not set manually.
  *
  * Note that we can drop this if this jackrabbit issue ever gets
  * implemented https://issues.apache.org/jira/browse/JCR-2233
  *
  * @param Node $node
  */
 protected function updateLastModified(Node $node)
 {
     if (!$this->getAutoLastModified() || !$node->isNodeType('mix:lastModified')) {
         return;
     }
     if ($node->hasProperty('jcr:lastModified') && !$node->getProperty('jcr:lastModified')->isModified() && !$node->getProperty('jcr:lastModified')->isNew()) {
         $node->setProperty('jcr:lastModified', new \DateTime());
     }
     if ($node->hasProperty('jcr:lastModifiedBy') && !$node->getProperty('jcr:lastModifiedBy')->isModified() && !$node->getProperty('jcr:lastModifiedBy')->isNew()) {
         $node->setProperty('jcr:lastModifiedBy', $this->credentials->getUserID());
     }
 }
 /**
  * @dataProvider provideTestOutOfRangeCharacters
  */
 public function testOutOfRangeCharacterOccurrence($string, $isValid)
 {
     if (false === $isValid) {
         $this->setExpectedException('PHPCR\\ValueFormatException', 'Invalid character found in property "test". Are you passing a valid string?');
     }
     $t = $this->getTransportMock();
     $factory = new Factory();
     $session = $this->getMockBuilder('Jackalope\\Session')->disableOriginalConstructor()->getMock();
     $workspace = $this->getMockBuilder('Jackalope\\Workspace')->disableOriginalConstructor()->getMock();
     $session->expects($this->any())->method('getWorkspace')->with()->will($this->returnValue($workspace));
     $repository = $this->getMockBuilder('Jackalope\\Repository')->disableOriginalConstructor()->getMock();
     $session->expects($this->any())->method('getRepository')->with()->will($this->returnValue($repository));
     $ntm = $this->getMockBuilder('Jackalope\\NodeType\\NodeTypeManager')->disableOriginalConstructor()->getMock();
     $workspace->expects($this->any())->method('getNodeTypeManager')->with()->will($this->returnValue($ntm));
     $nt = $this->getMockBuilder('Jackalope\\NodeType\\NodeType')->disableOriginalConstructor()->getMock();
     $ntm->expects($this->any())->method('getNodeType')->with()->will($this->returnValue($nt));
     $objectManager = $this->getMockBuilder('Jackalope\\ObjectManager')->disableOriginalConstructor()->getMock();
     $article = new Node($factory, array(), '/jcr:root', $session, $objectManager, true);
     $article->setProperty('test', $string);
     $t->updateProperties($article);
 }
Beispiel #8
0
 public function __construct($factory, $rawData, $path, $session, $objectManager, $new = false)
 {
     $this->objectmanager = $objectManager;
     parent::__construct($factory, $rawData, $path, $session, $objectManager, $new);
 }