Example #1
0
 private function writeEntities()
 {
     $this->begin();
     foreach ($this->entities as $entity) {
         $this->dispatchEvent(new Events\PrePersist($entity));
         $hash = $this->getHash($entity);
         $this->nodes[$hash] = $this->createNode($entity)->save();
         $this->dispatchEvent(new Events\PostPersist($entity));
     }
     $this->commit();
     // Write the primary key
     foreach ($this->entities as $entity) {
         $hash = $this->getHash($entity);
         $meta = $this->getMeta($entity);
         $pk = $meta->getPrimaryKey();
         $nodeId = $this->nodes[$hash]->getId();
         if ($pk->getValue($entity) !== $nodeId) {
             $pk->setValue($entity, $nodeId);
             if ($meta->getLabels()) {
                 $labels = array();
                 foreach ($meta->getLabels() as $label) {
                     $labels[] = new Label($this->client, $label);
                 }
                 $this->client->addLabels($this->nodes[$hash], $labels);
             }
         }
     }
 }