/** * {@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; }
/** * @param Property $property */ private function storeProperty(Property $property) { $path = $property->getPath(); $typeid = $property->getType(); $nativeValue = $property->getValueForStorage(); if ($typeid === PropertyType::STRING) { foreach ((array) $nativeValue as $string) { if (!$this->isStringValid($string)) { throw new ValueFormatException('Invalid character found in property "' . $property->getName() . '". Are you passing a valid string?'); } } } $value = $this->propertyToJsopString($property); if (!$value) { $this->setJsopBody($nativeValue, $path, $typeid); if (is_array($nativeValue)) { $this->setJsopBody('^' . $path . ' : []'); } else { $this->setJsopBody('^' . $path . ' : '); } } else { $encoded = json_encode($value); if (PropertyType::DOUBLE == $property->getType() && !strpos($encoded, '.')) { $encoded .= '.0'; } $this->setJsopBody('^' . $path . ' : ' . $encoded); } }