2
votes

Catchable Fatal Error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in /srv/mysite/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1060 and defined

In controller

removeExpireProducts();
$em->flush();

Inside my service:

function removeExpireProducts()
{
    foreach ($products as $product) {
         $this->productRemover->removeProduct($product);
    }
}

productRemover class:
public function removeProduct(Product $product)
{

    $newOffer =
        $this->offerGroup
        ->createOffer($product);

    if (null !== $newOffer) {
        $this->em->persist($newOffer);
        $this->em->flush();
    }

    $this->em->remove($product);
}
1
do you have same doctrine event listener on it? - Matteo
@Matteo means same object of entity manager? - Ricky ponting
I mean this some services tagged as doctrine.event_listener - Matteo
@Matteo I have not used any doctrine.event_listener its automatic throwing error. - Ricky ponting
Please include productRemover class and removeProduct method in your question. It's possible you unnecessary flush() going on Lifecycle Events - Łukasz D. Tulikowski

1 Answers

3
votes

Move flush() to the bottom like this:

public function removeProduct(Product $product)
{
    $newOffer =
        $this->offerGroup
        ->createOffer($product);

    if (null !== $newOffer) {
        $this->em->persist($newOffer);
    }

    $this->em->remove($product);
    $this->em->flush();
}

And in you controller remove $em->flush();

Than refactor your code to avoid executing flush() in this loop:

foreach ($products as $product) {
     $this->productRemover->removeProduct($product);
}