Refresh not working: Issue after resetting Doctrine Manager
P粉731861241
P粉731861241 2023-08-29 15:07:12
0
1
569
<p>There is something wrong with my data, I get the error <code>out of range on a integer column</code> and I try to prevent <code>Close Entity Manager</code> from continuing to work, as I<code>reset manager</code> in exception</p > <pre class="brush:php;toolbar:false;">public function renewDeliveryTime($delayReport) : void { try { $this->delayReportRepository->updateRenewedDeliveryTimeAt($delayReport, 50000000); }catch (\Exception $exception){ // out of range error $this->managerRegistry->resetManager(); } } public function updateRenewedDeliveryTimeAt($delayReport,$delayDuration) { /*** @var DelayReport $delayReport*/ $delayReport->setDelayDuration($delayDuration); $delayReport->setStatus(DelayReport::STATUS['DONE']); $this->getEntityManager()->flush(); }</pre> <p>The problem is, I'm running into an error in my data, I'm getting the error message <code>out of range on a integer column</code>, and I'm trying to prevent <code>closed entity manager< /code>Continue working and for this purpose in the exception <code>reset manager</code></p> <pre class="brush:php;toolbar:false;">public function enqueue($delayReport) : void { $this->pushInQueueReport($delayReport); $this->delayReportRepository->updateStatus($delayReport, DelayReport::STATUS['IN_QUEUE']); } public function updateStatus($delayReport, $status) { /*** @var DelayReport $delayReport*/ $delayReport->setStatus($status); $this->getEntityManager()->flush(); }</pre> <p>The problem is that after I have another object and almost the same database operation, it seems that <code>$this->getEntityManager()->flush()</code> no longer works, database Nothing happens. This has to do with <code>$this->managerRegistry->resetManager()</code></p> <p>What is the solution to this problem? </p>
P粉731861241
P粉731861241

reply all(1)
P粉143640496

The problem is that resetManager(), not all services that directly reference the entity manager will automatically update to new instances.

In the updateStatus() method you can easily check if the entity is managed by the entity manager.

$uow = $this->getEntityManager()->getUnitOfWork();
if($uow->getEntityState($delayReport) !== UnitOfWork::STATE_MANAGED) {
    // not managed
}

Not sure if reassignment helps here, like $this->getEntityManager()->merge($delayReport).

But it's better to avoid closing the manager and validating the data before validating it.

edit:

Not tested, if you will get the reset EntityManager through the Registry. But it's worth a try.

$entityManager = $managerRegistry->getManagerForClass(get_class($delayReport));
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template