Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
problem evet listener doctrine
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
joselito  
View profile  
 More options Oct 8 2012, 5:10 am
From: joselito <paradit...@gmail.com>
Date: Mon, 8 Oct 2012 02:10:41 -0700 (PDT)
Local: Mon, Oct 8 2012 5:10 am
Subject: problem evet listener doctrine

Hello, i have a listener for insert in database the changes in the tables
to database. but the problme is with no insert to database.

with eventlistener onFLush insert to database but no get ID the object
insert.

I'm trying PostPersist but no inserto to database.

the code is:

file config.yml:

listenercrud:
    class: mio\mioBundle\ListenerCrud
    arguments: [@service_container]
    tags:
        - { name: doctrine.event_listener, event: postPersist}

file ListenerCrud.php

class ListenerCrud{

protected $container;

public function __construct(ContainerInterface $container)
{
    $this->container = $container;

}

public function postPersist(LifecycleEventArgs $eventArgs)
    {
            $em = $eventArgs->getEntityManager();
            $uow = $em->getUnitOfWork();
            foreach ($uow->getScheduledEntityInsertions() as $entity) {
                    if (!$entity instanceof Modificacion ) {
                    $campos = "";
                    $modificacion = new Modificacion();
                    $modificacion->setFechamod(new \DateTime('now'));
                    $className = join('', array_slice(explode('\\', get_class($entity)), -1));
                    $modificacion->setEntidad($className);
                    $modificacion->setIdentificador('aaaa');
                    $modificacion->setTipo('Modificación');
                    $securityContext = $this->container->get('security.context');
                    $modificacion->setEmpleado($securityContext->getToken()->getUser());
                    $changeset = $uow->getEntityChangeSet($entity);
                    foreach ($changeset AS $field => $vals) {
                        list($oldValue, $newValue) = $vals;
                        $campos = $campos . $field .':'.$oldValue .' '.$newValue.' ';
                        };
                    $modificacion->setInfo($campos);
                    $em->persist($modificacion);
                    $classMetadata = $em->getClassMetadata(get_class($modificacion));
                    $uow->computeChangeSet($classMetadata, $modificacion);

}
}

thanks.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Pivetta  
View profile  
 More options Oct 8 2012, 5:18 am
From: Marco Pivetta <ocram...@gmail.com>
Date: Mon, 8 Oct 2012 11:18:31 +0200
Local: Mon, Oct 8 2012 5:18 am
Subject: Re: [Symfony2] problem evet listener doctrine

You cannot really do that, since operations are already happening.
You would probably want to act in `onFlush` and manually add items to the
scheduled insertions in the UoW.

Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com

On 8 October 2012 11:10, joselito <paradit...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
joselito  
View profile  
 More options Oct 8 2012, 6:29 am
From: joselito <paradit...@gmail.com>
Date: Mon, 8 Oct 2012 03:29:02 -0700 (PDT)
Local: Mon, Oct 8 2012 6:29 am
Subject: Re: [Symfony2] problem evet listener doctrine

thanks, sorry for my english.

Can not use the method postpersist? How do I add operations?

I am new using doctrine.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
joselito  
View profile  
 More options Oct 8 2012, 6:30 am
From: joselito <paradit...@gmail.com>
Date: Mon, 8 Oct 2012 03:30:51 -0700 (PDT)
Local: Mon, Oct 8 2012 6:30 am
Subject: Re: [Symfony2] problem evet listener doctrine

class ListenerCrud{

    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function onFlush(onFlushEventArgs $eventArgs)
        {
                $em = $eventArgs->getEntityManager();
                $uow = $em->getUnitOfWork();

                foreach ($uow->getScheduledEntityInsertions() AS $entity) {
                    if (!$entity instanceof Modificacion) {
                        $modificacion = new Modificacion();
                        $modificacion->setFechamod(new \DateTime('now'));
                        $className = join('', array_slice(explode('\\',
get_class($entity)), -1));
                        $modificacion->setEntidad($className);
                        $modificacion->setTipo('Inserción');
                        $hola = $this->getConfiguration($em, $meta->name)
                        $modificacion->setIdentificador('bbbb');// add the
id inserted ????
                        $securityContext =
$this->container->get('security.context');

$modificacion->setEmpleado($securityContext->getToken()->getUser());
                        $modificacion->setInfo('');
                        $em->persist($modificacion);
                        $classMetadata =
$em->getClassMetadata(get_class($modificacion));
                        $uow->computeChangeSet($classMetadata,
$modificacion);
                        }
                    }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Pivetta  
View profile  
 More options Oct 8 2012, 6:36 am
From: Marco Pivetta <ocram...@gmail.com>
Date: Mon, 8 Oct 2012 12:36:17 +0200
Local: Mon, Oct 8 2012 6:36 am
Subject: Re: [Symfony2] problem evet listener doctrine

You can use `$uow->scheduleForInsert($modificacion);` (
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Un...)
Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com

On 8 October 2012 12:30, joselito <paradit...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
joselito  
View profile  
 More options Oct 8 2012, 7:04 am
From: joselito <paradit...@gmail.com>
Date: Mon, 8 Oct 2012 04:04:06 -0700 (PDT)
Local: Mon, Oct 8 2012 7:04 am
Subject: Re: [Symfony2] problem evet listener doctrine

Would not it be this way?

foreach ($uow->getScheduledEntityInsertions() AS $entity) {
                    if (!$entity instanceof Modificacion) {
                        $modificacion = new Modificacion();
                        $modificacion->setFechamod(new \DateTime('now'));
                        $className = join('', array_slice(explode('\\',
get_class($entity)), -1));
                        $modificacion->setEntidad($className);
                        $modificacion->setTipo('Inserción');
                        $uow->scheduleForInsert($entity);
                        $modificacion->setIdentificador($entity->getId());
                        $securityContext =
$this->container->get('security.context');

$modificacion->setEmpleado($securityContext->getToken()->getUser());
                        $modificacion->setInfo('');
                        $em->persist($modificacion);
                        $classMetadata =
$em->getClassMetadata(get_class($modificacion));
                        $uow->computeChangeSet($classMetadata,
$modificacion);
                        }
                    }

Entity can not be scheduled for insertion twice.

Could you give an example in the code?

sorry and thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »