public function save(UserPolygon &$userPolygon, $flush = true) { /* * REGION * * does the region already exist, if not we need to save it in all entities * because it will get saved multiple times */ try { $regionName = $userPolygon->getRegion()->getName(); $region = $this->regionMapper()->getRegionByName($regionName); $userPolygon->setRegion($region); $userPolygon->getNeighborhood()->setRegion($region); } catch (\Doctrine\ORM\NoResultException $e) { $region = $userPolygon->getRegion(); $this->regionMapper()->save($region); $userPolygon->setRegion($region); $userPolygon->getNeighborhood()->setRegion($region); } /* * NEIGHBORHOOD * * does the neighborhood already exist, if it does reset it in the neighborhood */ try { $neighborhoodName = $userPolygon->getNeighborhood()->getName(); $regionName = $userPolygon->getNeighborhood()->getRegion()->getName(); $neighborhood = $this->neighborhoodMapper()->getNeighborhoodByName($neighborhoodName, $regionName); $userPolygon->setNeighborhood($neighborhood); } catch (\Doctrine\ORM\NoResultException $e) { $this->neighborhoodMapper->save($userPolygon->getNeighborhood()); } $whathoodUser = $this->getMaybeSaveByName($userPolygon->getWhathoodUser()->getIpAddress()); $userPolygon->setWhathoodUser($whathoodUser); if ($userPolygon->getDateTimeAdded() == null) { $userPolygon->setDateTimeAdded($this->getCurrentDateTimeAsString()); } $this->em->persist($userPolygon); if ($flush) { $this->em->flush($userPolygon); } }
public function save(UserPolygon $userPolygon) { /* * REGION * * does the region already exist, if not we need to save it in all entities * because it will get saved multiple times */ try { $regionName = $userPolygon->getRegion()->getName(); $region = $this->regionMapper()->getRegionByName($regionName); $userPolygon->setRegion($region); $userPolygon->getNeighborhood()->setRegion($region); } catch (\Doctrine\ORM\NoResultException $e) { $region = $userPolygon->getRegion(); $this->regionMapper()->save($region); $userPolygon->setRegion($region); $userPolygon->getNeighborhood()->setRegion($region); } $this->logger()->info("after region"); /* * NEIGHBORHOOD * * does the neighborhood already exist, if it does reset it in the neighborhood */ try { $neighborhoodName = $userPolygon->getNeighborhood()->getName(); $regionName = $userPolygon->getNeighborhood()->getRegion()->getName(); $neighborhood = $this->neighborhoodMapper()->getNeighborhoodByName($neighborhoodName, $regionName); $userPolygon->setNeighborhood($neighborhood); } catch (\Doctrine\ORM\NoResultException $e) { $this->neighborhoodMapper->save($userPolygon->getNeighborhood()); } $this->logger()->info('after neighborhood'); $whathoodUser = $this->getMaybeSaveByName($userPolygon->getWhathoodUser()->getIpAddress()); $userPolygon->setWhathoodUser($whathoodUser); if ($userPolygon->getDateTimeAdded() == null) { $userPolygon->setDateTimeAdded($this->getCurrentDateTimeAsString()); } if (0) { \Zend\Debug\Debug::dump($userPolygon->getId(), 'in UserPolygonMapper'); exit; } $this->logger()->info("about to save"); $this->em->persist($userPolygon); $this->logger()->info("about to flush"); $this->em->flush($userPolygon); $this->logger()->info("saved"); }