/** * @param Site $site */ protected function createMilestones(Site $site) { $em = $this->getDoctrine()->getEntityManager(); $loanUtil = $this->get('sudoux_mortgage.los_util'); $losMilestoneGroups = $loanUtil->getAllMilestones($site); foreach ($losMilestoneGroups['allMilestones'] as $losMilestoneGroup) { $milestoneGroup = $em->getRepository('SudouxMortgageBundle:LoanMilestoneGroup')->findOneByLosId($site, $losMilestoneGroup['ID']); if (!isset($milestoneGroup)) { $milestoneGroup = new LoanMilestoneGroup(); } $milestoneGroup->setName($losMilestoneGroup['name']); $milestoneGroup->setLosId($losMilestoneGroup['ID']); $milestoneGroup->setSite($site); $i = 0; foreach ($losMilestoneGroup['milestones'] as $losMilestone) { $milestone = $em->getRepository('SudouxMortgageBundle:LoanMilestone')->findOneMilestoneByLosId($site, $losMilestone['ID'], $losMilestoneGroup['ID']); if (!isset($milestone)) { $milestone = new LoanMilestone(); $milestoneGroup->addMilestone($milestone); } $milestone->setLosId($losMilestone['ID']); $milestone->setName($losMilestone['name']); $milestone->setWeight($i); $milestone->setMilestoneGroup($milestoneGroup); $em->persist($milestone); $i++; } $em->persist($milestoneGroup); } $em->flush(); }
/** * * @param Site $site */ protected function upsertMilestones(Site $site) { $losMilestoneGroups = $this->loanUtil->getAllMilestones($site); foreach ($losMilestoneGroups['allMilestones'] as $losMilestoneGroup) { $milestoneGroup = $this->em->getRepository('SudouxMortgageBundle:LoanMilestoneGroup')->findOneByLosId($site, $losMilestoneGroup['ID']); if (!isset($milestoneGroup)) { $milestoneGroup = new LoanMilestoneGroup(); } $milestoneGroup->setName($losMilestoneGroup['name']); $milestoneGroup->setLosId($losMilestoneGroup['ID']); $milestoneGroup->setSite($site); $i = 0; foreach ($losMilestoneGroup['milestones'] as $losMilestone) { $milestone = $this->em->getRepository('SudouxMortgageBundle:LoanMilestone')->findOneMilestoneByLosId($site, $losMilestone['ID'], $losMilestoneGroup['ID']); if (!isset($milestone)) { $milestone = new LoanMilestone(); $milestoneGroup->addMilestone($milestone); } $milestone->setLosId($losMilestone['ID']); $milestone->setName($losMilestone['name']); $milestone->setWeight($i); $milestone->setMilestoneGroup($milestoneGroup); $this->em->persist($milestone); $i++; } $this->em->persist($milestoneGroup); } $this->em->flush(); }
/** * * @param Site $site */ protected function upsertMilestones(Site $site) { try { $losMilestoneGroups = $this->loanUtil->getAllMilestones($site); // deactivate all milestone groups first $milestoneGroups = $this->em->getRepository('SudouxMortgageBundle:LoanMilestoneGroup')->findAllBySite($site); foreach ($milestoneGroups as $milestoneGroup) { $milestoneGroup->setActive(false); $this->em->persist($milestoneGroup); } $this->em->flush(); if (array_key_exists('allMilestones', $losMilestoneGroups)) { foreach ($losMilestoneGroups['allMilestones'] as $losMilestoneGroup) { $milestoneGroup = $this->em->getRepository('SudouxMortgageBundle:LoanMilestoneGroup')->findOneByLosId($site, $losMilestoneGroup['ID']); if (!isset($milestoneGroup)) { $milestoneGroup = new LoanMilestoneGroup(); } $milestoneGroup->setName($losMilestoneGroup['name']); $milestoneGroup->setLosId($losMilestoneGroup['ID']); $milestoneGroup->setSite($site); $milestoneGroup->setActive(true); $i = 0; foreach ($losMilestoneGroup['milestones'] as $losMilestone) { $milestone = $this->em->getRepository('SudouxMortgageBundle:LoanMilestone')->findOneMilestoneByLosId($site, $losMilestone['ID'], $losMilestoneGroup['ID']); if (!isset($milestone)) { $milestone = new LoanMilestone(); $milestoneGroup->addMilestone($milestone); } $milestone->setLosId($losMilestone['ID']); $milestone->setName($losMilestone['name']); $milestone->setWeight($i); $milestone->setActive(true); $milestone->setMilestoneGroup($milestoneGroup); $this->em->persist($milestone); $i++; } $this->em->persist($milestoneGroup); } $this->em->flush(); } } catch (\Exception $e) { $this->output->writeln($e->getMessage()); $this->logger->crit($e->getMessage()); if ($this->batchCommand) { $jobLog = new BatchJobLog(); $jobLog->setStatus(2); $jobLog->setBatchJob($this->batchJob); $jobLog->setMessage($e->getMessage()); $jobLog->setStackTrace($e->getTraceAsString()); $this->em->persist($jobLog); $this->em->flush($jobLog); } } }