I have a script that should get a list of records in a database, and then iterate over those that create new records in another table, if they do not already exist.
Currently im doing:
foreach($entries as $entry){ $newItem = new Item(); $newItem->setAttribute($entry->getAttribute()); $entityManager->persist($newItem); try{ $entityManager->flush(); } catch(\Exception $e){ if(!strpos($e->getMessage(),'Duplicate')){ throw $e; } $entityManager = $this->getDoctrine()->getManager();
However, doing it so very intensively, there are 1000 entries, and the script takes more than 10 minutes several times. I have seen other messages suggest that when batch processing like this, to clean up about every 20 or so, writes the problem that if one of these 20 is a duplicate, then the whole transaction dies, I'm not sure how I will return and try to find an invalid entry to exclude it before resubmitting them again.
Any help with this would be greatly appreciated.
source share