Don't hydrate objects in batch script, just use the insert method from the doctrine's connection object ...
On Tue, Apr 6, 2010 at 9:10 PM, Roland Cremer <roland.cre...@gmail.com>wrote: > Hi, > > I've made a model for a bookstore and i have to import new books. I've > generated a symfony task to import a csv file and loop thru the records and > genarate the book object and related objects. > > The problem is that the script is not performing. Inserting 4000 books > takes more than 30 minutes. It seems that the longer the script runs, the > slower it gets. Maybe i've made a mistake for clearing objects or so. > > function looping thru the csv records > > public static function importToDatabse($csvContent,$rowSeparator = > "\n",$fieldSeparator = "\t") { > $rows = explode ($rowSeparator,$csvContent); > foreach($rows as $row) { > if ((strlen($row))>0) { > $boek = new Boek(); > $boek->createFromArray(explode ($fieldSeparator, $row)); > $boek->save(); > $boek->free(true); > } > } > } > > function in the book object to create the objects > > class Boek extends BaseBoek > { > public function createFromArray($import) { > $this->setIsbn($import[0]); > $this->setTitel($import[1]); > $this->setSubtitel($import[2]); > $uitgever = > Doctrine::getTable('Uitgever')->findOrCreate($import[4]); > $this->Uitgever = $uitgever; > $this->setImprint($import[5]); > $category = > Doctrine::getTable('Category')->findOrCreate((intval($import[6])==0?1:intval($import[6]))); > $this->Category = $category; > $this->setBoeksoortCode($import[7]); > if ($import[8]) { > $serie = Doctrine::getTable('Serie')->findOrCreate($import[8]); > $this->Serie = $serie; > } > $this->setBibliografischeDruk($import[10]); > $this->setGeillustreerd(($import[11]=='N'?0:1)); > $this->setTitelCommercieel($import[12]); > $this->setPaginas(($import[13]==''?null:$import[13])); > if ($import[14]) { > $taal = Doctrine::getTable('Taal')->findOrCreate($import[14]); > $this->Taal = $taal; > } > $this->setProductVorm('ED'); > $this->setProductVormId(1); > > $this->setVerschijningsdatum(CSVFunctions::convertBoekhuisDate($import[17])); > $this->setStadiumLevenscyclusCode($import[18]); > $this->setIsbnFysiekBoek(($import[19]==''?null:$import[19])); > $this->setAfbeeldingUrl($import[20]); > > $this->setIsbnVervangendArtikel(($import[21]==''?null:$import[21])); > $this->setAuteurTitel($import[22]); > > $this->setMutatieDatum(CSVFunctions::convertBoekhuisDate($import[23])); > $this->setAdviesprijs($import[24]); > $this->setNettoprijs($import[25]); > $this->setBtwLaag(($import[26]==''?null:$import[26])); > $this->setBtwHoog(($import[27]==''?null:$import[27])); > $this->setBestandsgrootte(($import[28]==''?null:$import[28])); > $this->setDrmCopyAantalPaginas($import[29]); > $this->setDrmCopyAantalPaginasEenheid($import[30]); > $this->setDrmPrintAantalPaginas($import[31]); > $this->setDrmPrintAantalPaginasEenheid($import[32]); > $this->setDrmVoorlees(($import[33]=='N'?0:1)); > $this->setKortingPercentage($import[34]); > $this->setBeschrijving($import[84]); > if ($import[35] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[37],$import[36],$import[35]); > $this->BoekPersoon[0]->Persoon = $persoon; > $this->BoekPersoon[0]->setRelatieTypeId(1); > } > if ($import[38] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[40],$import[39],$import[38]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(2); > } > if ($import[41] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[43],$import[42],$import[41]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(2); > } > if ($import[44] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[46],$import[45],$import[44]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(3); > } > if ($import[48] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[50],$import[49],$import[48]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(4); > } > if ($import[51] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[53],$import[52],$import[51]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(4); > } > if ($import[54] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[56],$import[55],$import[54]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(4); > } > if ($import[57] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[59],$import[58],$import[57]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(5); > } > if ($import[60] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[62],$import[61],$import[60]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(5); > } > if ($import[63] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[65],$import[64],$import[63]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(5); > } > if ($import[66] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[68],$import[67],$import[66]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(6); > } > if ($import[69] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[71],$import[70],$import[69]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(6); > } > if ($import[72] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[74],$import[73],$import[72]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(6); > } > if ($import[75] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[77],$import[76],$import[75]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(7); > } > if ($import[78] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[80],$import[79],$import[78]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(7); > } > if ($import[81] <> '') { > $persoon = > Doctrine::getTable('Persoon')->findOrCreate($import[83],$import[82],$import[81]); > $this->BoekPersoon[1]->Persoon = $persoon; > $this->BoekPersoon[1]->setRelatieTypeId(7); > } > } > } > > > > findOrCreate function (made this function to check if a relation already > exists. if so use it, if not create new one) > > public function findOrCreate($name) > { > $serie = $this->findOneBy('name', $name); > if ( ! $serie) { > $serie = new Serie(); > $serie->name = $name; > } > return $serie; > } > > > Hope someone can help me > > Thanks! > > Roland > > -- > If you want to report a vulnerability issue on symfony, please send it to > security at symfony-project.com > > You received this message because you are subscribed to the Google > Groups "symfony users" group. > To post to this group, send email to symfony-users@googlegroups.com > To unsubscribe from this group, send email to > symfony-users+unsubscr...@googlegroups.com<symfony-users%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/symfony-users?hl=en > -- Thomas Rabaix http://rabaix.net -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en To unsubscribe, reply using "remove me" as the subject.