public function testReLoadUpdate() { if ($this->client->getTransport()->getProtocolVersion() < 26) { // $this->markTestSkipped( 'Record Create/Update Unpredictable Behaviour' ); } $recOrig = ['alloggio' => 'case', 'lavoro' => 'mercato', 'vacanza' => 'mare']; $rec = new Record(); $rec->setOData($recOrig); $result = $this->client->execute('recordCreate', ['cluster_id' => 9, 'record' => $rec]); $this->assertInstanceOf('\\PhpOrient\\Protocols\\Binary\\Data\\Record', $result); $this->assertEquals('#9:0', (string) $result->getRid()); $this->assertEquals('9', $result->getRid()->cluster); $this->assertEquals('0', $result->getRid()->position); $recUp = ['alloggio' => 'home', 'lavoro' => 'bazar', 'vacanza' => 'sea']; //push the old record with a new value $rec->setOData($recUp); $rec->setOClass('V'); $updated = $this->client->execute('recordUpdate', ['rid' => $rec->getRid(), 'record' => $rec]); $this->assertInstanceOf('\\PhpOrient\\Protocols\\Binary\\Data\\Record', $result); $this->assertEquals('#9:0', (string) $updated->getRid()); $this->assertEquals('9', $updated->getRid()->cluster); $this->assertEquals('0', $updated->getRid()->position); $this->assertTrue($updated->getVersion() > 0); //assert that the created record is the same as the updated // ( why not should be?? is the same object this time ) $this->assertEquals((string) $rec, (string) $updated); $load = $this->client->execute('recordLoad', ['rid' => $updated->getRid()]); $this->assertInstanceOf('\\PhpOrient\\Protocols\\Binary\\Data\\Record', $load[0]); $this->assertEquals((string) $updated->getRid(), (string) $load[0]->getRid()); $this->assertEquals((string) $updated, (string) $load[0]); }
/** * Create a record * * @param Record $record * * @return RecordCreate|Record */ public function recordCreate(Record $record) { $result = $this->getTransport()->execute('recordCreate', ['cluster_id' => $record->getRid()->cluster, 'record' => $record]); $this->setFetchClass(false); return $result; }
/** * @param $record * @return \stdClass * @throws \Exception */ protected function populateRecord(Record $record) { $classMap = $this->em->classMap; $key = $record->getOClass(); if (array_key_exists($key, $classMap)) { $entity = new $classMap[$key](); /* @var EntityInterface $entity */ $entity->setRid($record->getRid()); $oData = $record->getOData(); if (!empty($oData) && is_array($oData)) { foreach ($oData as $key => $value) { $entity->{$key} = $value; } } return $entity; } throw new Exception('Key not found'); }
/** * Hydrate a SpiderRecord from an OrientRecord * * @param $orientRecord * @return Response */ protected function mapOrientRecordToCollection(OrientRecord $orientRecord) { // Or we map a single record to a Spider Record $collection = new Collection($orientRecord->getOData()); $collection->add(['id' => $orientRecord->getRid()->jsonSerialize(), 'label' => $orientRecord->getOClass(), 'meta.rid' => $orientRecord->getRid(), 'meta.version' => $orientRecord->getVersion(), 'meta.oClass' => $orientRecord->getOClass()]); $collection->protect('id'); $collection->protect('label'); $collection->protect('meta'); return $collection; }
public function extractRecord(Record &$record) { // prepair data: $rid = $record->getRid(); $recordData = $record->getOData(); $recordData['@rid'] = $this->IDtoRid($rid); $recordData['@version'] = $record->getVersion(); $recordData['@class'] = $record->getOClass(); foreach ($recordData as $key => $value) { if (is_a($value, 'DateTime')) { $value = $value->format('Y-m-d H:i:s'); $recordData[$key] = $value; } else { if (is_a($value, 'PhpOrient\\Protocols\\Binary\\Data\\Record')) { $recordData[$key] = $this->extractRecord($value); } else { if (is_array($value)) { $embeddedData = []; foreach ($value as $childRec) { // EMBEDDEDSET, EMBEDDEDLIST, EMBEDDEDMAP if (is_a($childRec, 'PhpOrient\\Protocols\\Binary\\Data\\Record')) { array_push($embeddedData, $this->extractRecord($childRec)); } else { // LINKSET, LINKLIST, LINKMAP if (is_a($childRec, 'PhpOrient\\Protocols\\Binary\\Data\\ID')) { $vortex = $this->findRelationByRid($childRec); if (!empty($vortex)) { array_push($embeddedData, $this->extractRecord($vortex)); } else { // not loaded array_push($embeddedData, $childRec); } } } } $recordData[$key] = $embeddedData; } else { if ($key !== '@rid' && is_a($value, 'PhpOrient\\Protocols\\Binary\\Data\\ID')) { $vortex = $this->findRelationByRid($value); if (!empty($vortex)) { $recordData[$key] = $this->extractRecord($vortex); } //??? convert to ActiveRecord } else { if (is_a($value, 'PhpOrient\\Protocols\\Binary\\Data\\Bag')) { $rids = $value->getRids(); foreach ($rids as $rid) { $relation = $this->findRelationByRid($rid); if (empty($relation)) { continue; } // relation not loaded if ($this->isEdge($relation)) { //? it always edge $edgeData = $relation->getOData(); $vortex = $this->findRelationByRid($edgeData['in']); $vortexData = $vortex->getOData(); // convert DateTime to ISO foreach ($vortexData as $vkey => $vval) { if (is_a($vval, 'DateTime')) { $vortexData[$vkey] = $vval->format('Y-m-d H:i:s'); } } $vortexData['@rid'] = $this->IDtoRid($vortex->getRid()); $vortexData['@version'] = $vortex->getVersion(); $vortexData['@class'] = $vortex->getOClass(); $vortexData['_edge'] = $this->IDtoRid($relation->getRid()); $recordData[$key] = $vortexData; } } } } } } } // continue; // if( !is_a($value, 'PhpOrient\Protocols\Binary\Data\Bag') // // && !is_a($value, 'PhpOrient\Protocols\Binary\Data\ID') // ) { // continue; // } } return $recordData; }
/** * Create a record * * @param Record $record * * @return RecordCreate|Record */ public function recordCreate(Record $record) { return $this->getTransport()->execute('recordCreate', ['cluster_id' => $record->getRid()->cluster, 'record' => $record]); }