I am trying to insert (in a mySQL database) datas from a "large" CSV file (3Mo / 37000 lines / 7 columns) using doctrine data fixtures.
The process is very slow and at this time I could not succeed (may be I had to wait a little bit more).
I suppose that doctrine data fixtures are not intended to manage such amount of datas ? Maybe the solution should be to import directly my csv into database ?
Any idea of how to proceed ?
Here is the code :
<?php
namespace FBN\GuideBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use FBN\GuideBundle\Entity\CoordinatesFRCity as CoordFRCity;
class CoordinatesFRCity extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager)
{
$csv = fopen(dirname(__FILE__).'/Resources/Coordinates/CoordinatesFRCity.csv', 'r');
$i = 0;
while (!feof($csv)) {
$line = fgetcsv($csv);
$coordinatesfrcity[$i] = new CoordFRCity();
$coordinatesfrcity[$i]->setAreaPre2016($line[0]);
$coordinatesfrcity[$i]->setAreaPost2016($line[1]);
$coordinatesfrcity[$i]->setDeptNum($line[2]);
$coordinatesfrcity[$i]->setDeptName($line[3]);
$coordinatesfrcity[$i]->setdistrict($line[4]);
$coordinatesfrcity[$i]->setpostCode($line[5]);
$coordinatesfrcity[$i]->setCity($line[6]);
$manager->persist($coordinatesfrcity[$i]);
$this->addReference('coordinatesfrcity-'.$i, $coordinatesfrcity[$i]);
$i = $i + 1;
}
fclose($csv);
$manager->flush();
}
public function getOrder()
{
return 1;
}
}