Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2726

EventSubscriber PreUpdate Error Bug?

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 2.3.4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:

      Description

      Should this:

      public function preUpdate(PreUpdateEventArgs $eventArgs)
      {
          $entity = $eventArgs->getEntity();
          $em = $eventArgs->getEntityManager();
          $uow = $em->getUnitOfWork();
      
          if ($entity instanceof User) {
              if ($eventArgs->hasChangedField('finalStatus')) {
                  $entity->setFinalStatusDate(new \DateTime('now'));
                  $uow->recomputeSingleEntityChangeSet(
                      $em->getClassMetadata("MyAdminBundle:User"),
                      $entity
                  );
              }
              if ($eventArgs->hasChangedField('membershipCode')) {
                  $entity->setMembershipCodeDate(new \DateTime('now'));
                  $uow->recomputeSingleEntityChangeSet(
                      $em->getClassMetadata("MyAdminBundle:User"),
                      $entity
                  );
              }
          }
      }
      

      ...result in this?

      Catchable Fatal Error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be an array, null given, called in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 995 and defined in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php line 47

      I'm just setting a time stamp for two updated values. Dumping the 3rd argument in PreUpdateEventArgs.php on line 47 reveals an array of changes. I'm not sure if this is a bug or if I'm performing this simple operation incorrectly.

        Activity

        Hide
        Marco Pivetta added a comment -

        Can you write an integration test around it? Looks like the changeset is removed in a particular edge case, but it's hard to figure it out without a test.

        Show
        Marco Pivetta added a comment - Can you write an integration test around it? Looks like the changeset is removed in a particular edge case, but it's hard to figure it out without a test.
        Hide
        Florin added a comment -

        here, solve it

        Show
        Florin added a comment - here, solve it
        Hide
        Marco Pivetta added a comment -

        Missing test case

        Show
        Marco Pivetta added a comment - Missing test case

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Nelson Ford
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: