Exemple #1
0
 /**
  * Compute the query to delete all entities wished to be removed
  *
  * @return Query
  */
 protected function computeDeleteQuery()
 {
     $qb = new QueryBuilder();
     $variables = [];
     $idx = 0;
     foreach ($this->scheduledForDelete as $entity) {
         $class = $this->getClass($entity);
         $metadata = $this->metadataRegistry->getMetadata($class);
         $var = 'e' . (string) $idx;
         $idProp = $metadata->getId()->getProperty();
         $id = $this->accessor->getValue($entity, $idProp);
         if ($metadata instanceof NodeMetadata) {
             $qb->matchNode($var, $class, [$idProp => $id]);
         } else {
             $qb->addExpr($qb->expr()->matchNode()->relatedTo($qb->expr()->matchRelationship($var, $class, [$idProp => $id])));
         }
         $variables[] = $var;
         $idx++;
     }
     foreach ($variables as $var) {
         $qb->delete($var);
     }
     return $qb->getQuery();
 }
Exemple #2
0
 /**
  * Find the relationships for the given node property
  *
  * @param NodeMetadata $metadata
  * @param Property $property
  * @param array $info
  *
  * @return array
  */
 protected function getNodeRelationships(NodeMetadata $metadata, Property $property, array $info)
 {
     $relationships = [];
     $relClass = $this->map->getClass($property->getOption('relationship'));
     foreach ($this->entities as $entity) {
         if (!$entity instanceof $relClass) {
             continue;
         }
         $relInfo = $this->entities->getInfo($entity);
         if (in_array($info['realId'], [$relInfo['startNode'], $relInfo['endNode']], true)) {
             $relationships[] = $entity;
         }
     }
     if (!empty($relationships)) {
         return $relationships;
     }
     $idProp = $metadata->getId()->getProperty();
     $qb = new QueryBuilder();
     $qb->addExpr($qb->expr()->matchNode('n', $metadata->getClass(), [$idProp => $info['properties'][$idProp]])->relatedTo($qb->expr()->matchRelationship('r', $relClass)))->toReturn('r');
     return $this->uow->execute($qb->getQuery());
 }