Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3222

PostUpdate event destroying collectionUpdates

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Mac OSX, AMP, php 5.3.27

      Description

      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.

        Activity

        Hide
        Marco Pivetta added a comment -

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

        Show
        Marco Pivetta added a comment - What does the listener actually do? Doesn't look like a bug to me...
        Hide
        Jacob Spizziri added a comment -

        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?

        Show
        Jacob Spizziri added a comment - 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?

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Jacob Spizziri
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: