在我的代码中。只有第一个flush()正在运行。正在接触并调用后续冲洗,但没有效果。
如果我从循环中删除flush()和clear(),则会更新所有记录(但我需要限制搜索以防止内存问题)。
$processedEntries = 0;
$advertQuery = $entityManager->createQuery(
"SELECT a
FROM MyBundle:Advert a
LEFT JOIN MyBundle:History prh
WHERE prh.id IS NULL"
);
$advertQuery->setFirstResult(0);
$advertResults = $advertQuery->getResult();
foreach ($advertResults as $advertEntity) {
$advertEntity->setTimeModified(new \DateTime());
try {
$processedEntries++;
if (($processedEntries % self::COMMIT_BATCH_SIZE) === 0) {
$entityManager->flush(); // Executes all updates.
$entityManager->clear(); // Detaches all objects from Doctrine!
}
} catch(\Exception $ex) {
$this->getContainer()->get('doctrine')->resetEntityManager();
echo $ex->getMessage();
}
}
$entityManager->flush(); // Executes all updates.