Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 public function testFindByClass()
 {
     $user = $this->node->addNode('userWithAlias');
     $user->setProperty('username', 'dbu');
     $user->setProperty('numbers', array(3, 1, 2));
     $user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
     $this->dm->getPhpcrSession()->save();
     $userWithAlias = $this->dm->find(null, '/functional/userWithAlias');
     $this->assertEquals('dbu', $userWithAlias->username);
 }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
0
 public function setUp()
 {
     $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\Hierarchy\\NameDoc';
     $this->dm = $this->createDocumentManager();
     $this->node = $this->resetFunctionalNode($this->dm);
     $root = $this->dm->getPhpcrSession()->getNode('/');
     if ($root->hasNode('childOfRoot')) {
         $root->getNode('childOfRoot')->remove();
     }
     $user = $this->node->addNode('thename');
     $user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
     $this->dm->getPhpcrSession()->save();
 }
Ejemplo n.º 5
0
 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();
 }
Ejemplo n.º 6
0
 public function setUp()
 {
     $this->type = 'Doctrine\\Tests\\Models\\CMS\\CmsTeamUser';
     $this->dm = $this->createDocumentManager(array(__DIR__));
     $this->node = $this->resetFunctionalNode($this->dm);
     $user = $this->node->addNode('dbu');
     $user->setProperty('username', 'dbu');
     $user->setProperty('status', 'created');
     $user->setProperty('phpcr:class', $this->type, PropertyType::STRING);
     $user = $this->node->addNode('team');
     $user->setProperty('username', 'team');
     $user->setProperty('phpcr:class', $this->type, PropertyType::STRING);
     $this->dm->getPhpcrSession()->save();
 }
 public function setUp()
 {
     $this->type = 'Doctrine\\Tests\\Models\\Translation\\Article';
     $this->dm = $this->createDocumentManager();
     $this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('fr'), 'fr' => array('en')), 'en'));
     $this->node = $this->resetFunctionalNode($this->dm);
     $user = $this->node->addNode('thename');
     $user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:fr-topic', 'french', \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:fr-text', 'french text', \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:frnullfields', array('nullable'), \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:en-topic', 'english', \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:en-text', 'english text', \PHPCR\PropertyType::STRING);
     $user->setProperty('phpcr_locale:ennullfields', array('nullable'), \PHPCR\PropertyType::STRING);
     $this->dm->getPhpcrSession()->save();
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function createNodeForDocument($document, NodeInterface $parentNode, $name)
 {
     $metadata = $this->metadataFactory->getMetadataForClass(get_class($document));
     $node = $parentNode->addNode($name);
     $node->addMixin($metadata->getPhpcrType());
     $node->setProperty('jcr:uuid', UUIDHelper::generateUUID());
     return $node;
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
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);
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * No translation whatsoever is available. All translated fields have to be
  * null as we do not validate on loading.
  */
 public function testFindNullableFieldNone()
 {
     $node = $this->node->addNode('find');
     $node->setProperty('phpcr:class', 'Doctrine\\Tests\\Models\\Translation\\Article');
     $this->dm->getPhpcrSession()->save();
     $this->dm->clear();
     /** @var $doc Article */
     $doc = $this->dm->find(null, $this->node->getPath() . '/find');
     $this->assertEquals('en', $doc->locale);
     $this->assertNull($doc->topic);
     $this->assertNull($doc->text);
 }
Ejemplo n.º 12
0
 public function setUp()
 {
     $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\QuerySql2TestObj';
     $this->dm = $this->createDocumentManager();
     $this->node = $this->resetFunctionalNode($this->dm);
     $versionNode = $this->node->addNode('node1', 'nt:unstructured');
     $versionNode->setProperty('username', 'dbu');
     $versionNode->setProperty('numbers', array(3, 1, 2));
     $versionNode->setProperty('phpcr:class', $this->type);
     $versionNode = $this->node->addNode('node2', 'nt:unstructured');
     $versionNode->setProperty('username', 'johannes');
     $versionNode->setProperty('numbers', array(3, 1, 2));
     $versionNode->setProperty('phpcr:class', $this->type);
     $versionNode = $this->node->addNode('node3', 'nt:unstructured');
     $versionNode->setProperty('username', 'lsmith');
     $versionNode->setProperty('numbers', array(3, 1, 2));
     $versionNode->setProperty('phpcr:class', $this->type);
     $versionNode = $this->node->addNode('node4', 'nt:unstructured');
     $versionNode->setProperty('username', 'uwe');
     $versionNode->setProperty('numbers', array(3, 1, 2));
     $versionNode->setProperty('phpcr:class', $this->type);
     $versionNode = $this->node->addNode('node5', 'nt:unstructured');
     $versionNode->setProperty('numbers', array(3, 1, 2));
     $this->dm->getPhpcrSession()->save();
     $this->dm = $this->createDocumentManager();
 }
Ejemplo n.º 13
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);
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function addNode($relPath, $primaryNodeTypeName = null)
 {
     return $this->node->addNode($relPath, $primaryNodeTypeName);
 }
Ejemplo n.º 15
0
 /**
  * Validate this node with the nodetype and generate not yet existing
  * autogenerated properties as necessary.
  *
  * @param NodeInterface $node
  * @param NodeType      $nodeTypeDefinition
  *
  * @return AddNodeOperation[] Additional operations to handle autocreated nodes.
  *
  * @throws \InvalidArgumentException
  * @throws RepositoryException
  * @throws ItemExistsException
  * @throws LockException
  * @throws ConstraintViolationException
  * @throws PathNotFoundException
  * @throws VersionException
  * @throws ValueFormatException
  */
 private function processNodeWithType(NodeInterface $node, NodeType $nodeTypeDefinition)
 {
     $additionalOperations = array();
     foreach ($nodeTypeDefinition->getDeclaredChildNodeDefinitions() as $childDef) {
         /* @var $childDef NodeDefinitionInterface */
         if (!$node->hasNode($childDef->getName())) {
             if ('*' === $childDef->getName()) {
                 continue;
             }
             if ($childDef->isMandatory() && !$childDef->isAutoCreated()) {
                 throw new RepositoryException(sprintf('Child "%s" is mandatory, but is not present while saving "%s" at path "%s"', $childDef->getName(), $nodeTypeDefinition->getName(), $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);
                 $additionalOperations[] = $operation;
             }
         }
     }
     foreach ($nodeTypeDefinition->getDeclaredPropertyDefinitions() as $propertyDef) {
         /* @var $propertyDef PropertyDefinitionInterface */
         if ('*' === $propertyDef->getName()) {
             continue;
         }
         if (!$node->hasProperty($propertyDef->getName())) {
             if ($propertyDef->isMandatory() && !$propertyDef->isAutoCreated()) {
                 throw new RepositoryException(sprintf('Property "%s" is mandatory, but is not present while saving "%s" at "%s"', $propertyDef->getName(), $nodeTypeDefinition->getName(), $node->getPath()));
             }
             if ($propertyDef->isAutoCreated()) {
                 switch ($propertyDef->getName()) {
                     case 'jcr:uuid':
                         $value = UUIDHelper::generateUUID();
                         break;
                     case 'jcr:createdBy':
                     case 'jcr:lastModifiedBy':
                         $value = $this->userId;
                         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(sprintf('No default value for autocreated property "%s" at "%s"', $propertyDef->getName(), $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->autoLastModified) {
                             $prop->setValue(new \DateTime());
                         }
                         break;
                     case 'jcr:lastModifiedBy':
                         if ($this->autoLastModified) {
                             $prop->setValue($this->userId);
                         }
                         break;
                     case 'jcr:etag':
                         // TODO: update etag if needed
                         break;
                 }
             }
         }
     }
     foreach ($nodeTypeDefinition->getDeclaredSupertypes() as $superType) {
         $this->processNodeWithType($node, $superType);
     }
     foreach ($node->getProperties() as $property) {
         $this->assertValidProperty($property);
     }
     return $additionalOperations;
 }