doctrine2 - symfony batch only first flush is working -
in code below. first flush() working. subsequent flushes being reached , called, having no effect.
if remove flush() , clear() loop, records updated (but need limit search prevent memory issues).
$processedentries = 0; $advertquery = $entitymanager->createquery( "select mybundle:advert left join mybundle:history prh prh.id null" ); $advertquery->setfirstresult(0); $advertresults = $advertquery->getresult(); foreach ($advertresults $advertentity) { $advertentity->settimemodified(new \datetime()); try { $processedentries++; if (($processedentries % self::commit_batch_size) === 0) { $entitymanager->flush(); // executes updates. $entitymanager->clear(); // detaches objects doctrine! } } catch(\exception $ex) { $this->getcontainer()->get('doctrine')->resetentitymanager(); echo $ex->getmessage(); } } $entitymanager->flush(); // executes updates.
Comments
Post a Comment