function parseCSVAction($from, $to) { die('nope'); $em = $this->getDoctrine()->getManager(); $file = __DIR__ . '/../../../_Njemacka.csv'; // $file = __DIR__ . '/../../../regions_subregions.csv'; // $file = __DIR__ . '/../../../regions_subregions_city2.csv'; $csv = array_map('str_getcsv', file($file)); // $csv = str_getcsv(file_get_contents(__DIR__ . '/../../../regions_subregions_city.csv')); $country = $em->getRepository('AppBundle:Country')->findOneByEn('Germany'); if ($country) { try { $i = 0; $count = 0; foreach ($csv as $c) { if ($c[0] != 'GRAD' && ($i >= $from && $i <= $to)) { $regionCSV = $c[1]; $region = $em->getRepository('AppBundle:Region')->findOneByEn($regionCSV); if (!$region) { $region = new Region(); $region->setCountry($country); $region->setEn($c[1]); // $region->setDe($c[2]); # Depends on country // $region->setIt($c[2]); $em->persist($region); $em->flush(); } $subregion = false; // $subregionCSV = $c[1]; // $subregion = $em->getRepository('AppBundle:Subregion')->findOneByEn($subregionCSV); // if (!$subregion) { // $subregion = new Subregion(); // $subregion->setRegion($region); // $subregion->setEn($c[1]); // $em->persist($subregion); // $em->flush(); // } $cityCSV = $c[0]; $city = $em->getRepository('AppBundle:City')->findOneByEn($cityCSV); if (!$city) { $city = new City(); $city->setRegion($region); $city->setEn($cityCSV); if ($subregion) { $city->setSubregion($subregion); } $em->persist($city); $em->flush(); } $count++; } $i++; } } catch (\Exception $e) { return new Response($e); } } return new Response($count); // echo'<pre>';print_r($csv);echo'</pre>'; }