/** * @dataProvider provideGetNode */ public function testGetNode($values, $nodeUuids, $exceptionMessage = null) { if ($exceptionMessage) { $this->setExpectedException('PHPCR\\RepositoryException', $exceptionMessage); } $nodes = new \ArrayObject(); foreach ($nodeUuids as $nodeUuid) { $nodes[$nodeUuid] = $this->getNodeMock(); $nodes[$nodeUuid]->expects($this->any())->method('getIdentifier')->will($this->returnValue($nodeUuid)); } $data = array('type' => PropertyType::REFERENCE, 'value' => $values); $factory = new Factory(); $session = $this->getSessionMock(); $objectManager = $this->getObjectManagerMock(array('getNodesByIdentifier' => $nodes)); $property = new Property($factory, $data, '/path/to', $session, $objectManager); $property->getNode(); }
/** * {@inheritDoc} */ public function storeProperty(Property $property) { $this->assertLoggedIn(); $path = $property->getPath(); $path = $this->validatePath($path); $parent = $property->getParent(); $parentPath = $this->validatePath($parent->getPath()); try { $data = $this->decodeProperty($property); $coll = $this->db->selectCollection(self::COLLNAME_NODES); $qb = $coll->createQueryBuilder()->select('_id')->findAndUpdate()->field('props.name')->equals($property->getName())->field('path')->equals($parentPath)->field('w_id')->equals($this->workspaceId)->field('props.$')->set($data); $query = $qb->getQuery(); $node = $query->execute(); if (empty($node)) { $qb = $coll->createQueryBuilder()->update()->field('path')->equals($parentPath)->field('w_id')->equals($this->workspaceId)->field('props')->push($data); $query = $qb->getQuery(); $query->execute(); } } catch (\Exception $e) { throw $e; } return true; }
/** * This method is used when building a JSOP of the properties * * @param $value * @param $type * @return mixed|string */ protected function propertyToJsopString(Property $property) { switch ($property->getType()) { case PropertyType::DECIMAL: return null; case PropertyType::DOUBLE: return $this->valueConverter->convertType($property->getValueForStorage(), PropertyType::DOUBLE); case PropertyType::LONG: return $this->valueConverter->convertType($property->getValueForStorage(), PropertyType::LONG); case PropertyType::DATE: case PropertyType::WEAKREFERENCE: case PropertyType::REFERENCE: case PropertyType::BINARY: case PropertyType::PATH: case PropertyType::URI: return null; case PropertyType::NAME: if ($property->getName() != 'jcr:primaryType') { return null; } break; } return $property->getValueForStorage(); }