getEntityManager example

return [];
        }
        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;
        }

        
/** * Helper function to create the query builder for the "getMailQuery" function. * This function can be hooked to modify the query builder of the query object. * * @param int $mailId * * @return QueryBuilder */
    public function getMailQueryBuilder($mailId)
    {
        $builder = $this->getEntityManager()->createQueryBuilder();
        $builder->select(['mails', 'attribute'])
                ->from(Mail::class, 'mails')
                ->leftJoin('mails.attribute', 'attribute')
                ->where('mails.id = ?1')
                ->setParameter(1, $mailId);

        return $builder;
    }

    /** * Returns an instance of the \Doctrine\ORM\Query object which search the attribute model * for the passed mail id. * * @param int $mailId * * @return Query<MailAttribute> */
class RememberMeTokenProviderDoctrineSchemaListener extends AbstractSchemaListener
{
    /** * @param iterable<mixed, RememberMeHandlerInterface> $rememberMeHandlers */
    public function __construct(private iterable $rememberMeHandlers)
    {
    }

    public function postGenerateSchema(GenerateSchemaEventArgs $event): void
    {
        $connection = $event->getEntityManager()->getConnection();

        foreach ($this->rememberMeHandlers as $rememberMeHandler) {
            if (
                $rememberMeHandler instanceof PersistentRememberMeHandler
                && ($tokenProvider = $rememberMeHandler->getTokenProvider()) instanceof DoctrineTokenProvider
            ) {
                $tokenProvider->configureSchema($event->getSchema()$connection$this->getIsSameDatabaseChecker($connection));
            }
        }
    }
}
$width = (int) $attr->width;
                            $height = (int) $attr->height;
                        } elseif ($attr->viewBox && \count($size = explode(' ', $attr->viewBox)) === 4) {
                            $width = (int) $size[2];
                            $height = (int) $size[3];
                        }
                    }
            }

            if (!empty($height) && !empty($width)) {
                if ($media->getId()) {
                    $eventArgs->getEntityManager()->getConnection()->executeUpdate(
                        'UPDATE s_media SET width = :width, height = :height WHERE id = :id',
                        [
                            ':width' => $width,
                            ':height' => $height,
                            ':id' => $media->getId(),
                        ]
                    );
                }

                $media->setWidth($width);
                $media->setHeight($height);
            }

    public function getPaymentStatusQueryBuilder($filter = null, $order = null)
    {
        /** @var QueryBuilder $builder */
        $builder = $this->getEntityManager()->createQueryBuilder();
        $builder->select([
            'status.id as id',
            'status.name as name',
        ]);
        $builder->from(Status::class, 'status')
            ->where('status.group = ?1')
            ->setParameter(1, 'payment');

        if ($filter !== null) {
            $builder->addFilter($filter);
        }
        
$query->addOrderBy('shop.position');
        $query->setMaxResults(1);

        return $query->execute()->fetch(PDO::FETCH_ASSOC);
    }

    /** * @return \Doctrine\DBAL\Query\QueryBuilder */
    private function getDbalShopsQuery()
    {
        $query = $this->getEntityManager()->getConnection()->createQueryBuilder();
        $query->select([
            'shop.id',
            'shop.name',
            'shop.base_url',
            'shop.position',
            'IF(main_shop.id IS NULL, 1, 0) is_main',
            'IFNULL(main_shop.host, shop.host) as host',
            'IFNULL(main_shop.hosts, shop.hosts) as hosts',
            'IFNULL(main_shop.secure, shop.secure) as secure',
            'IFNULL(main_shop.base_path, shop.base_path) as base_path',
            'IFNULL(main_shop.template_id, shop.template_id) as template_id',
            

    public function getBackendPremiumListQuery($start$limit$order$filterValue = null)
    {
        /** @var QueryBuilder $builder */
        $builder = $this->getEntityManager()->createQueryBuilder();
        $builder->select([
            'premium.id',
            'premium.startPrice as startPrice',
            'premium.orderNumber as orderNumber',
            'premium.orderNumberExport as orderNumberExport',
            'premium.shopId as shopId',
            'subshop.name as subShopName',
            'article.name as name',
            ])
            ->from($this->getEntityName(), 'premium')
            ->leftJoin('premium.shop', 'subshop')
            
class DoctrineDbalCacheAdapterSchemaListener extends AbstractSchemaListener
{
    /** * @param iterable<mixed, DoctrineDbalAdapter> $dbalAdapters */
    public function __construct(private iterable $dbalAdapters)
    {
    }

    public function postGenerateSchema(GenerateSchemaEventArgs $event): void
    {
        $connection = $event->getEntityManager()->getConnection();

        foreach ($this->dbalAdapters as $dbalAdapter) {
            $dbalAdapter->configureSchema($event->getSchema()$connection$this->getIsSameDatabaseChecker($connection));
        }
    }
}
/** * Helper function to create the query builder for the "getListQuery" function. * This function can be hooked to modify the query builder of the query object. * * @param array<array{property: string, direction: string}>|null $orderBy * * @return QueryBuilder */
    public function getListQueryBuilder(?array $orderBy = null)
    {
        /** @var QueryBuilder $builder */
        $builder = $this->getEntityManager()->createQueryBuilder();
        $builder->select(
            [
                'productFeed.id as id',
                'productFeed.name as name',
                'productFeed.active as active',
                'productFeed.fileName as fileName',
                'productFeed.countArticles as countArticles',
                'productFeed.hash as hash',
                'productFeed.lastExport as lastExport',
            ]
        );
        
public function getSubscribedEvents()
    {
        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());
            }

            
private const PROCESSING_TABLE_FLAG = self::class.':processing';

    /** * @param iterable<mixed, TransportInterface> $transports */
    public function __construct(private iterable $transports)
    {
    }

    public function postGenerateSchema(GenerateSchemaEventArgs $event): void
    {
        $connection = $event->getEntityManager()->getConnection();

        foreach ($this->transports as $transport) {
            if (!$transport instanceof DoctrineTransport) {
                continue;
            }

            $transport->configureSchema($event->getSchema()$connection$this->getIsSameDatabaseChecker($connection));
        }
    }

    public function onSchemaCreateTable(SchemaCreateTableEventArgs $event): void
    {
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;
        }

        

    public function getGroupListQueryBuilder(?array $filterBy = null, ?array $orderBy = null, $limit = null, $offset = null)
    {
        /** @var QueryBuilder $builder */
        $builder = $this->getEntityManager()->createQueryBuilder();
        $builder->from(Group::class, 'g');
        $builder->leftJoin('g.mapping', 'm');

        $builder->select([
            'g.id as id',
            'g.key as key',
            'g.name as name',
            'g.active as active',
            'm.id as mappingId',
        ]);
        if ($filterBy !== null) {
            
/** * Helper function to create the query builder for the "getAverageVoteQuery" function. * This function can be hooked to modify the query builder of the query object. * * @param int $blogId * @param int|null $shopId * * @return QueryBuilder */
    public function getAverageVoteQueryBuilder($blogId$shopId = null)
    {
        $builder = $this->getEntityManager()->createQueryBuilder();
        $builder->select([
            'AVG(comment.points) as avgVote',
        ])
        ->from(Comment::class, 'comment')
        ->where('comment.active = 1')
        ->andWhere('comment.blogId = :blogId')
        ->setParameter('blogId', $blogId);

        if ($shopId && Shopware()->Config()->get('displayOnlySubShopBlogComments')) {
            $builder
                ->andWhere('comment.shopId IS NULL OR comment.shopId = :shopId')
                
// Get the entity for the attribute, e.g. Shopware\Models\Article\Detail         $entity = $this->getDqlHelper()->getEntityForAttribute($attribute);
        // Get the prefixed column, e.g. detail.number         $column = $this->getDqlHelper()->getColumnForAttribute($attribute);

        // Alias for the entity, e.g. details         $alias = $this->getDqlHelper()->getPrefixForEntity($entity);

        // Get column name without prefix         list($prefix$plainColumn) = explode('.', $column);
        // Column type might be needed for additional formatting         $columnType = $this->getDqlHelper()->getEntityManager()->getClassMetadata($entity)->fieldMappings[$plainColumn]['type'];

        // Query         $builder = $this->getDqlHelper()->getEntityManager()->createQueryBuilder()
            // Using distinct instead of groupBy is waaay faster - but will result in some pages having only one result             ->select("DISTINCT {$column}")
            ->from($entity$alias);
        // Limit to results matching the filter string         if ($queryConfig['filter']) {
            $builder->where("{$column} LIKE ?1")
                ->setParameter(1, '%' . $queryConfig['filter'] . '%');
        }
        
Home | Imprint | This part of the site doesn't use cookies.