private function processNode(Node $node) { if (false === $node->hasProperty(Storage::JCR_UUID)) { return; } $jcrUuid = UUIDHelper::generateUUID(); $node->setProperty(Storage::JCR_UUID, $jcrUuid, 'String'); }
public function testFromPhpcrNode() { $phpcrNode = $this->prophesize('PHPCR\\NodeInterface'); $prop1 = $this->prophesize('PHPCR\\PropertyInterface'); $prop1->getType()->willReturn(1); $prop1->getValue()->willReturn('Foo'); $phpcrNode->getProperties()->willReturn(array('prop1' => $prop1->reveal())); $node = new Node($phpcrNode->reveal()); $this->assertEquals(array('type' => 'String', 'value' => 'Foo'), $node->getProperty('prop1')); }
public function serialize(Node $node) { $properties = array(); $this->binaries = array(); foreach ($node->getProperties() as $propertyName => $property) { $propertyType = $property['type']; if (is_object($property['value'])) { $propertyValues = array($property['value']); } else { $propertyValues = (array) $property['value']; } $propertyLengths = array(); $binaryHashes = array(); foreach ($propertyValues as $i => &$value) { if (null === $value) { continue; } if ($propertyType == 'Date') { // should this be moved "up" ? if ($value instanceof \DateTime) { $value = $value->format('c'); } else { $date = new \DateTime($value); $value = $date->format('c'); } } if ($propertyType == 'Binary') { if (is_resource($value)) { $stream = $value; $value = stream_get_contents($stream); fclose($stream); } $propertyLengths[] = strlen($value); $binaryHash = md5($value); $this->binaries[$binaryHash] = $value; $value = $binaryHash; } else { $propertyLengths[] = ''; } } if (empty($propertyValues)) { continue; } $properties[$propertyName]['type'] = $propertyType; if (is_array($property['value'])) { $properties[$propertyName]['value'] = $propertyValues; $properties[$propertyName]['length'] = $propertyLengths; } else { $properties[$propertyName]['value'] = reset($propertyValues); $properties[$propertyName]['length'] = reset($propertyLengths); } } $yaml = Yaml::dump($properties); return $yaml; }
/** * Write the given node data. * * @return array Node data */ public function writeNode($workspace, $path, Node $node) { $internalUuid = $this->getOrCreateInternalUuid($path); $node->setProperty(Storage::INTERNAL_UUID, $internalUuid, 'String'); $jcrUuid = null; if ($node->hasProperty('jcr:mixinTypes')) { $mixinTypes = $node->getPropertyValue('jcr:mixinTypes'); if (in_array('mix:referenceable', $mixinTypes)) { if (false === $node->hasProperty('jcr:uuid')) { $jcrUuid = UUIDHelper::generateUUID(); $node->setProperty('jcr:uuid', $jcrUuid); } else { $jcrUuid = $node->getPropertyValue('jcr:uuid'); } } } $serialized = $this->serializer->serialize($node); $absPath = $this->helper->getNodePath($workspace, $path); $this->filesystem->write($absPath, $serialized); foreach ($this->serializer->getSerializedBinaries() as $binaryHash => $binaryData) { // TODO: use Helper to get path ..., $binaryPath = sprintf('%s/%s.bin', dirname($absPath), $binaryHash); $this->filesystem->write($binaryPath, $binaryData); } $this->index->indexUuid($internalUuid, $workspace, $path, true); if ($jcrUuid) { $this->index->indexUuid($jcrUuid, $workspace, $path, false); } foreach ($node->getProperties() as $propertyName => $property) { foreach ((array) $property['value'] as $propertyValue) { if ($property['type'] === 'Reference') { $this->index->indexReferrer($internalUuid, $propertyName, $propertyValue, false); } if ($property['type'] === 'WeakReference') { $this->index->indexReferrer($internalUuid, $propertyName, $propertyValue, true); } } } return $node; }
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; }
public function workspaceInit($name) { $node = new Node(); $node->setProperty('jcr:primaryType', 'nt:unstructured', 'Name'); $this->writeNode($name, '/', $node); $node = new Node(); $node->setProperty('jcr:primaryType', 'rep:system', 'Name'); $this->writeNode($name, '/jcr:system', $node); $node = new Node(); $node->setProperty('jcr:primaryType', 'rep:nodeTypes', 'Name'); $this->writeNode($name, '/jcr:system/jcr:nodeTypes', $node); }
/** * {@inheritDoc} */ public function index($workspace, $path, Node $node) { $index = $this->getIndex($workspace); $document = new Document(); $nodeName = PathHelper::getNodeName($path); $localNodeName = $nodeName; // PathHelper::getLocalNodeName($path); $parentPath = PathHelper::getParentPath($path); $document->addField(Field::Keyword(self::IDX_PATH, $path)); $document->addField(Field::Keyword(self::IDX_NODENAME, $nodeName)); $document->addField(Field::Keyword(self::IDX_NODELOCALNAME, $localNodeName)); $document->addField(Field::Keyword(self::IDX_PARENTPATH, $parentPath)); foreach ($node->getProperties() as $propertyName => $property) { $propertyValue = $property['value']; $propertyType = $property['type']; if ($propertyName === Storage::INTERNAL_UUID) { $document->addField(Field::Keyword(Storage::INTERNAL_UUID, $propertyValue)); continue; } switch ($propertyType) { case PropertyType::TYPENAME_STRING: case PropertyType::TYPENAME_NAME: case PropertyType::TYPENAME_PATH: case PropertyType::TYPENAME_URI: $value = (array) $propertyValue; $value = join(self::MULTIVALUE_SEPARATOR, $value); $document->addField(Field::Text($propertyName, $value)); break; case PropertyType::TYPENAME_DATE: $values = (array) $propertyValue; foreach ($values as $i => $value) { if ($value instanceof \DateTime) { $values[$i] = $value->format('c'); } } $value = join(self::MULTIVALUE_SEPARATOR, $values); $document->addField(Field::Text($propertyName, $value)); break; case PropertyType::TYPENAME_DECIMAL: case PropertyType::TYPENAME_LONG: case PropertyType::TYPENAME_DOUBLE: $values = (array) $propertyValue; foreach ($values as &$value) { $value = sprintf('%0' . strlen(PHP_INT_MAX) . 's', $value); } $value = join(self::MULTIVALUE_SEPARATOR, $values); $document->addField(Field::Text($propertyName, $value)); break; case PropertyType::TYPENAME_BOOLEAN: $values = (array) $propertyValue; foreach ($values as &$value) { if ($propertyValue === 'false') { $value = self::VALUE_BOOLEAN_FALSE; } else { $value = 1; } } $value = join(self::MULTIVALUE_SEPARATOR, $values); $document->addField(Field::Text($propertyName, $value)); break; } } $index->addDocument($document); }