getUnitOfWork example

throw new InvalidArgumentException(sprintf('Expected an instance of %s', ReflectionProperty::class));
            }

            $key = $inflector->tableize($field);
            if ($mapping['isCascadeDetach']) {
                $data[$key] = $metadata->reflFields[$field]->getValue($entity);
                if ($data[$key] !== null) {
                    $data[$key] = $this->serializeEntity($data[$key]);
                }
            } elseif ($mapping['isOwningSide'] && $mapping['type'] & ClassMetadata::TO_ONE) {
                $association = $metadata->reflFields[$field]->getValue($entity);
                if (\is_object($association) && $this->getUnitOfWork()->isInIdentityMap($association)) {
                    $data[$key] = $this->getUnitOfWork()->getEntityIdentifier($association);
                } else {
                    // In some case the relationship may not exist, but we want to know about it                     $data[$key] = null;
                }
            }
        }

        return $data;
    }
}

    public function preUpdate(Enlight_Event_EventArgs $arguments)
    {
        /** @var Detail $orderDetail */
        $orderDetail = $arguments->get('entity');

        $entityManager = $arguments->get('entityManager');

        // returns a change set for the model, which contains all changed properties with the old and new value.         $changeSet = $entityManager->getUnitOfWork()->getEntityChangeSet($orderDetail);

        $this->stockService->updateProductDetail(
            $orderDetail,
            isset($changeSet['articleNumber']) ? $changeSet['articleNumber'][0] : null,
            isset($changeSet['quantity']) ? $changeSet['quantity'][0] : null,
            isset($changeSet['articleNumber']) ? $changeSet['articleNumber'][1] : null,
            isset($changeSet['quantity']) ? $changeSet['quantity'][1] : null
        );
    }

    /** * If an position is added, the stock of the product will be reduced by the ordered quantity. */
return null;
    }

    private function getBacklogKey(Backlog $backlog): string
    {
        return $backlog->entity . '_' . $backlog->entity_id;
    }

    private function trace(OnFlushEventArgs $eventArgs): void
    {
        $em = $eventArgs->getEntityManager();
        $uow = $em->getUnitOfWork();

        $queue = [];
        // Entity deletions         foreach ($uow->getScheduledEntityDeletions() as $entity) {
            $backlog = $this->getBacklog($entity);
            if (!$backlog) {
                continue;
            }
            $queue[$this->getBacklogKey($backlog)] = $backlog;
        }

        
/** * Initializes a new <tt>BasicEntityPersister</tt> that uses the given EntityManager * and persists instances of the class described by the given ClassMetadata descriptor. */
    public function __construct(EntityManagerInterface $em, ClassMetadata $class)
    {
        $this->em                    = $em;
        $this->class                 = $class;
        $this->conn                  = $em->getConnection();
        $this->platform              = $this->conn->getDatabasePlatform();
        $this->quoteStrategy         = $em->getConfiguration()->getQuoteStrategy();
        $this->identifierFlattener   = new IdentifierFlattener($em->getUnitOfWork()$em->getMetadataFactory());
        $this->noLimitsContext       = $this->currentPersisterContext = new CachedPersisterContext(
            $class,
            new Query\ResultSetMapping(),
            false
        );
        $this->limitsHandlingContext = new CachedPersisterContext(
            $class,
            new Query\ResultSetMapping(),
            true
        );
    }

    
/** * Checks if the name changed, if this is the case, the uploaded file * has to be renamed. * Removes the thumbnail files if the album or the name changed. * Creates the default and album thumbnails if the name or the album changed. * * @ORM\PostUpdate() */
    public function onUpdate()
    {
        // Returns a change set for the model, which contains all changed properties with the old and new value.         $changeSet = Shopware()->Models()->getUnitOfWork()->getEntityChangeSet($this);

        $isNameChanged = isset($changeSet['name']) && $changeSet['name'][0] !== $changeSet['name'][1];
        $isAlbumChanged = isset($changeSet['albumId']) && $changeSet['albumId'][0] !== $changeSet['albumId'][1];

        // Name changed || album changed?         if ($isNameChanged || $isAlbumChanged) {
            // To remove the old thumbnails, use the old name.             $name = isset($changeSet['name']) ? $changeSet['name'][0] : $this->name;
            $name = $this->removeSpecialCharacters($name);
            $name = $name . '.' . $this->extension;

            

        return [Events::onFlush, Events::postFlush];
    }

    public function onFlush(OnFlushEventArgs $eventArgs)
    {
        if ($this->disabledForNextFlush) {
            return;
        }

        $em = $eventArgs->getEntityManager();
        $uow = $em->getUnitOfWork();

        $this->pendingAddAssignments = [];
        $this->pendingRemoveAssignments = [];

        // Entity deletions         foreach ($uow->getScheduledEntityDeletions() as $entity) {
            if ($entity instanceof Category) {
                $this->backlogRemoveCategory($entity->getId());
            }

            if ($entity instanceof Article) {
                
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
            'em' => 'default',
            'class' => self::SINGLE_IDENT_CLASS,
            'choice_label' => 'name',
        ]);

        $this->em->clear();

        $field->submit(1);

        $unitOfWorkIdentityMap = $this->em->getUnitOfWork()->getIdentityMap();
        $managedEntitiesNames = array_map('strval', $unitOfWorkIdentityMap['Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity']);

        $this->assertContains((string) $entity1$managedEntitiesNames);
        $this->assertNotContains((string) $entity2$managedEntitiesNames);
    }

    public function testGroupByChoices()
    {
        $item1 = new GroupableEntity(1, 'Foo', 'Group1');
        $item2 = new GroupableEntity(2, 'Bar', 'Group1');
        $item3 = new GroupableEntity(3, 'Baz', 'Group2');
        


    /** * If a product position get updated, the order totals must be recalculated * * @return void */
    public function preUpdate(Enlight_Event_EventArgs $arguments)
    {
        $orderDetail = $arguments->get('entity');
        // returns a change set for the model, which contains all changed properties with the old and new value.         $changeSet = $arguments->get('entityManager')->getUnitOfWork()->getEntityChangeSet($orderDetail);

        $productChange = \array_key_exists('articleNumber', $changeSet) && $changeSet['articleNumber'][0] !== $changeSet['articleNumber'][1];
        $quantityChange = \array_key_exists('quantity', $changeSet) && $changeSet['quantity'][0] !== $changeSet['quantity'][1];
        $priceChanged = \array_key_exists('price', $changeSet) && $changeSet['price'][0] !== $changeSet['price'][1];
        $taxChanged = \array_key_exists('taxRate', $changeSet) && $changeSet['taxRate'][0] !== $changeSet['taxRate'][1];

        // If anything in the order position has been changed, we must recalculate the totals of the order         if ($quantityChange || $productChange || $priceChanged || $taxChanged) {
            $this->calculationService->recalculateOrderTotals($orderDetail->getOrder());
        }
    }

    

        if (!$this->container->getParameter('shopware.es.write_backlog')) {
            return [];
        }

        return [Events::onFlush, Events::postFlush];
    }

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

        // Entity deletions         foreach ($uow->getScheduledEntityDeletions() as $entity) {
            $backlog = $this->getDeleteBacklog($entity);
            if (!$backlog) {
                continue;
            }
            $this->queue[] = $backlog;
        }

        // Entity Insertions

    public function onUpdate()
    {
        if (!empty($this->rawPassword)) {
            $this->hashPassword = $this->rawPassword;
        } elseif (!empty($this->password)) {
            $this->encoderName = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();
            $this->hashPassword = Shopware()->PasswordEncoder()->encodePassword($this->password, $this->encoderName);
        }

        $changeSet = Shopware()->Models()->getUnitOfWork()->getEntityChangeSet($this);

        $passwordChanged = isset($changeSet['hashPassword']) && $changeSet['hashPassword'][0] !== $changeSet['hashPassword'][1];

        if ($passwordChanged) {
            $this->passwordChangeDate = new DateTime();
        }
    }

    /** * @return CustomerAttribute|null */
    
Home | Imprint | This part of the site doesn't use cookies.