Item gets deleted on flush even when I restore it

15 Views Asked by At

I have the following code that I'm using to debug:

$localResource = $xResource->getLocalResource();
dump($localResource->getAllOptions()->toArray());

$xProvider->updateLocalResource($xResource, $localResource, $handler);
dump($localResource->getAllOptions()->toArray());

if ($flush) {
    $this->em->flush();
}
dump($localResource->getAllOptions()->toArray());
die;

The first dump shows the local resource, which in this case is currently deleted, so deletedAt is a timestamp.

The second dump shows the local resource, after it has been restored. deletedAt at this stage is null.

The third dump shows the local resource, after it is flushed. deletedAt is then the current timestamp when the code runs. This timestamp is not the same as the timestamp in the first dump.

I thought it might be cascading deleting somewhere, but seems it's not. I've checked events too, with no luck.

Here is the code where I do the restore:

$extra = $extrasRepo->findOneBy(['externalId' => $id, 'boat' => $localResource->getId()]);

if (empty($extra)) {
    $extra = new BoatExtra();
    $extra->setExternalId($id);
} else {
    $extra->restore();
    $extra->getAsset()->restore();
}

Is there anything else that I'm missing? Why would it - with a flush call - redelete the item.

0

There are 0 best solutions below