DDC-3222: PostUpdate event destroying collectionUpdates #3987

Closed
opened 2026-01-22 14:33:03 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 21, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user jspizziri:

I have an entity that contains a Many-To-Many Unidirectional association. When the association is updated and the entity is flushed the changes are not being persisted to the database.

This is because the postUpdate event is being fired on executeUpdates, which is being called before the collection updates are being processed here:

            // Collection updates (deleteRows, updateRows, insertRows)
            foreach ($this->collectionUpdates as $collectionToUpdate) {
                $this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate);
            }

This is occurring in UnitOfWork->commit() lines 333 through 366.

Apparently the postUpdate listener I wrote was causing the collectionUpdates property to be erased.

Originally created by @doctrinebot on GitHub (Jul 21, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user jspizziri: I have an entity that contains a Many-To-Many Unidirectional association. When the association is updated and the entity is flushed the changes are not being persisted to the database. This is because the postUpdate event is being fired on executeUpdates, which is being called before the collection updates are being processed here: ``` // Collection updates (deleteRows, updateRows, insertRows) foreach ($this->collectionUpdates as $collectionToUpdate) { $this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate); } ``` This is occurring in UnitOfWork->commit() lines 333 through 366. Apparently the postUpdate listener I wrote was causing the collectionUpdates property to be erased.
admin added the Bug label 2026-01-22 14:33:03 +01:00
admin closed this issue 2026-01-22 14:33:04 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 21, 2014):

Comment created by @ocramius:

What does the listener actually do? Doesn't look like a bug to me...

@doctrinebot commented on GitHub (Jul 21, 2014): Comment created by @ocramius: What does the listener actually do? Doesn't look like a bug to me...
Author
Owner

@doctrinebot commented on GitHub (Jul 21, 2014):

Comment created by jspizziri:

I'm using FOSElasticaBundle/ElasticSearch. On the postUpdate event I'm calling fos:elastica:populate on the entity indexes. Heres the code

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

namespace SRC\Bundle\SearchBundle\EventListener;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Doctrine\ORM\Event\LifecycleEventArgs;
use SRC\Bundle\ProductBundle\Entity\Product;
use SRC\Bundle\UserBundle\Entity\User;

/****
 * Description of SearchIndexer
 *
 * @author jacobspizziri
 */
class SearchIndexer
{   
    protected $container;
    protected $logger;

    public function **construct($container, $logger) {
        $this->container = $container;
        $this->logger = $logger;
    }


    public function postUpdate(LifecycleEventArgs $args){
        $this->index($args);
    }

    protected function index($args){
        $entity = $args->getEntity();

        $arguments = false;
        $command = new \FOS\ElasticaBundle\Command\PopulateCommand();
        $command->setContainer($this->container);

        //TODO: probably need to specify the --env=prod/dev
        // update Elastica on Product update
        if ($entity instanceof Product) {
            $this->logger->info('Updating Product Search Indexes');

            $arguments = array(
                    '--index'=>'website',
                    '--type' => 'product'
                    );
        } else if ($entity instanceof User) {
            $this->logger->info('Updating User Search Indexes');

            $arguments = array(
                    '--index'=>'website',
                    '--type' => 'user'
                    );
        }


        if($command && $arguments){
            $input = new ArrayInput($arguments);
            $output = new NullOutput();

            $result = $command->run($input, $output);
            $this->logger->info('Finished Updating Search Indexes with result: '. strval($result));
        }
    }
}
?>

Am I using this event incorrectly? Should I only be using postPersist?

@doctrinebot commented on GitHub (Jul 21, 2014): Comment created by jspizziri: I'm using FOSElasticaBundle/ElasticSearch. On the postUpdate event I'm calling fos:elastica:populate on the entity indexes. Heres the code ``` <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ namespace SRC\Bundle\SearchBundle\EventListener; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; use Doctrine\ORM\Event\LifecycleEventArgs; use SRC\Bundle\ProductBundle\Entity\Product; use SRC\Bundle\UserBundle\Entity\User; /**** * Description of SearchIndexer * * @author jacobspizziri */ class SearchIndexer { protected $container; protected $logger; public function **construct($container, $logger) { $this->container = $container; $this->logger = $logger; } public function postUpdate(LifecycleEventArgs $args){ $this->index($args); } protected function index($args){ $entity = $args->getEntity(); $arguments = false; $command = new \FOS\ElasticaBundle\Command\PopulateCommand(); $command->setContainer($this->container); //TODO: probably need to specify the --env=prod/dev // update Elastica on Product update if ($entity instanceof Product) { $this->logger->info('Updating Product Search Indexes'); $arguments = array( '--index'=>'website', '--type' => 'product' ); } else if ($entity instanceof User) { $this->logger->info('Updating User Search Indexes'); $arguments = array( '--index'=>'website', '--type' => 'user' ); } if($command && $arguments){ $input = new ArrayInput($arguments); $output = new NullOutput(); $result = $command->run($input, $output); $this->logger->info('Finished Updating Search Indexes with result: '. strval($result)); } } } ?> ``` Am I using this event incorrectly? Should I only be using postPersist?
Author
Owner

@doctrinebot commented on GitHub (Sep 17, 2014):

Comment created by @ocramius:

After checking again, I think this issue is invalid. Please use the onFlush event to log changes (instead of post-* events

@doctrinebot commented on GitHub (Sep 17, 2014): Comment created by @ocramius: After checking again, I think this issue is invalid. Please use the `onFlush` event to log changes (instead of `post-*` events
Author
Owner

@doctrinebot commented on GitHub (Sep 17, 2014):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Sep 17, 2014): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3987