/** * Compute the query to update all the entities * * @param SplObjectStorage $entities Entities that need to be updated * * @return Query */ protected function computeUpdateQuery(\SplObjectStorage $entities) { $qb = new QueryBuilder(); $toUpdate = []; $idx = 0; foreach ($entities as $entity) { $class = $this->getClass($entity); $metadata = $this->metadataRegistry->getMetadata($class); $data = $entities[$entity]; $idProp = $metadata->getId()->getProperty(); $id = $this->accessor->getValue($entity, $idProp); $var = 'e' . (string) $idx; if ($metadata instanceof NodeMetadata) { $qb->matchNode($var, $class, [$idProp => $id]); } else { $qb->addExpr($qb->expr()->matchNode()->relatedTo($qb->expr()->matchRelationship($var, $class, [$idProp => $id]))); } $toUpdate[$var] = $data; $idx++; } foreach ($toUpdate as $var => $value) { $qb->update($var, $value); } return $qb->getQuery(); }