protected function processStudent($row) { if ($row) { $manager = $this->getContainer()->get('doctrine.orm.entity_manager'); $studentRepo = $manager->getRepository('TSK\\StudentBundle\\Entity\\Student'); $statesRepo = $manager->getRepository('TSK\\UserBundle\\Entity\\States'); $studentStatusRepo = $manager->getRepository('TSK\\StudentBundle\\Entity\\StudentStatus'); $rankRepo = $manager->getRepository('TSK\\RankBundle\\Entity\\Rank'); $schoolRepo = $manager->getRepository('TSK\\SchoolBundle\\Entity\\School'); $row[0] = preg_replace('/-/', '', $row[0]); $student = $studentRepo->findOneBy(array('legacyStudentId' => $row[0])); if (!$student) { $student = new Student(); $contactManager = $this->getContainer()->get('tsk_user.contact_manager'); $contact = $contactManager->createContact(); $contact->setOrganization($this->org); $contact->setFirstName($row[1]); $contact->setLastName($row[2]); $contact->setEmail($row[13]); $contact->setAddress1($row[3]); $contact->setAddress2($row[4]); $contact->setCity($row[5]); $contact->setState($statesRepo->find($row[6])); $contact->setPostalCode($row[7]); $contact->setPhone($row[8]); $contact->setMobile($row[9]); $contact->setDateOfBirth(new \DateTime($row[10])); $contact->addSchool($this->school); $contactManager->updateCanonicalFields($contact); $student->setContact($contact); $student->setLegacyStudentId($row[0]); $student->setStudentStatus($studentStatusRepo->findOneBy(array('name' => 'active'))); $rank = $rankRepo->findOneBy(array('fullDescription' => $row[12])); if (!$rank) { print 'Bad rank [' . $row[12] . ']' . "\n"; try { } catch (\Exception $e) { // throw new \Exception('Bad Rank [' . $row[12] . ']'); } } else { $student->setRank($rank); $studentRank = new StudentRank(); $studentRank->setStudent($student); $studentRank->setRank($rank); $studentRank->setRankType($rank->getRankType()); $studentRank->setAwardedDate(new \DateTime($row[14])); $manager->persist($studentRank); } $manager->persist($student); $manager->flush(); } } }