LastIdQuery example

private function createQuery(): LastIdQuery
    {
        $query = $this->connection->createQueryBuilder();
        $query->select(['id', 'id']);
        $query->from('s_user', 'u');
        $query->where('u.id > :lastId');
        $query->setParameter(':lastId', 0);
        $query->orderBy('u.id', 'ASC');
        $query->setMaxResults(100);

        return new LastIdQuery($query);
    }
}
if ($definition->hasAutoIncrement()) {
            $query->select([$escaped . '.auto_increment', 'LOWER(HEX(' . $escaped . '.id)) as id']);
            $query->andWhere($escaped . '.auto_increment > :lastId');
            $query->addOrderBy($escaped . '.auto_increment');
            $query->setParameter('lastId', 0);

            if ($lastId !== null) {
                $query->setParameter('lastId', $lastId['offset']);
            }

            return new LastIdQuery($query);
        }

        $query->select([$escaped . '.id', 'LOWER(HEX(' . $escaped . '.id))']);
        $query->setFirstResult(0);
        if ($lastId !== null) {
            $query->setFirstResult((int) $lastId['offset']);
        }

        return new OffsetQuery($query);
    }
}
protected function createIterator(): LastIdQuery
    {
        $query = $this->connection->createQueryBuilder();
        $query->addSelect(['cart.auto_increment', 'cart.token']);
        $query->from('cart');
        $query->andWhere('cart.auto_increment > :lastId');
        $query->addOrderBy('cart.auto_increment');
        $query->setMaxResults(50);
        $query->setParameter('lastId', 0);

        return new LastIdQuery($query);
    }

    private function redisToSql(InputInterface $input, OutputInterface $output): int
    {
        if ($this->redis === null) {
            throw new \RuntimeException('%shopware.cart.redis_url% is not configured and no url provided.');
        }

        $this->io = new ShopwareStyle($input$output);

        $keys = $this->redis->keys(RedisCartPersister::PREFIX . '*');
        
->select(['products.id', 'products.ordernumber'])
            ->from('s_articles_details', 'products')
            ->andWhere('products.id > :lastId')
            ->andWhere('products.articleID = :article')
            ->setParameter(':lastId', 0)
            ->setParameter(':article', $id)
            ->addOrderBy('products.id')
            ->setMaxResults(50);

        $indexer = $this->container->get('shopware_es_backend.indexer');

        $query = new LastIdQuery($query);

        $repository = $this->container->get(\Shopware\Bundle\AttributeBundle\Repository\ProductRepository::class);

        $index = $this->getIndexName($repository->getDomainName());

        while ($numbers = $query->fetch()) {
            $indexer->indexEntities($index$repository$numbers);
        }
    }

    private function getIndexName($domainName)
    {

    public function getIterator()
    {
        $query = $this->entityManager->getConnection()->createQueryBuilder();
        $query->select(['orders.id', 'orders.id']);
        $query->from('s_order', 'orders');
        $query->andWhere('orders.id > :lastId');
        $query->setParameter(':lastId', 0);
        $query->addOrderBy('orders.id');
        $query->setMaxResults(50);

        return new LastIdQuery($query);
    }

    /** * {@inheritdoc} */
    public function getMapping()
    {
        return [
            'properties' => [
                'id' => TypeMappingInterface::MAPPING_LONG_FIELD,
                'number' => $this->getTextFieldWithRawData(),
                

    public function getIterator()
    {
        $query = $this->entityManager->getConnection()->createQueryBuilder();
        $query->select(['customer.id', 'customer.id']);
        $query->from('s_user', 'customer');
        $query->andWhere('customer.id > :lastId');
        $query->setParameter(':lastId', 0);
        $query->addOrderBy('customer.id');
        $query->setMaxResults(50);

        return new LastIdQuery($query);
    }

    /** * {@inheritdoc} */
    public function getMapping()
    {
        return [
            'properties' => [
                'id' => TypeMappingInterface::MAPPING_LONG_FIELD,
                'number' => $this->getTextFieldWithRawData(),
                
private function createQuery()
    {
        $query = $this->container->get(\Doctrine\DBAL\Connection::class)->createQueryBuilder();
        $query->select(['id', 'id']);
        $query->from('s_user', 'u');
        $query->where('u.id > :lastId');
        $query->setParameter(':lastId', 0);
        $query->orderBy('u.id', 'ASC');
        $query->setMaxResults(100);

        return new LastIdQuery($query);
    }
}

        $query = $this->entityManager->getConnection()->createQueryBuilder();

        $query = $query
            ->select(['products.id', 'products.ordernumber'])
            ->from('s_articles_details', 'products')
            ->andWhere('products.id > :lastId')
            ->setParameter(':lastId', 0)
            ->addOrderBy('products.id')
            ->setMaxResults(50);

        return new LastIdQuery($query);
    }

    /** * {@inheritdoc} */
    public function getMapping()
    {
        return [
            'properties' => [
                'id' => TypeMappingInterface::MAPPING_LONG_FIELD,
                'number' => array_merge($this->textMapping->getKeywordField()['copy_to' => 'swag_all']),
                

        $this->connection = $connection;
    }

    /** * @param int|null $limit * * @return LastIdQuery */
    public function createQuery($limit = null)
    {
        return new LastIdQuery($this->createOptionQuery($limit));
    }

    /** * @param int|null $limit * * @return \Doctrine\DBAL\Query\QueryBuilder */
    private function createOptionQuery($limit = null)
    {
        $query = $this->connection->createQueryBuilder();
        $query->select(['propertyGroups.id', 'propertyGroups.id'])
            
if ($limit !== null) {
                $query->setMaxResults($limit);
            }
        } else {
            $query = $this->createQuery($limit);
            $query->innerJoin('variant', 's_articles_categories_ro', 'categories', 'variant.articleID = categories.articleID')
                ->andWhere('categories.categoryID = :categoryId')
                ->setParameter(':categoryId', $categoryId, PDO::PARAM_INT);
        }

        return new LastIdQuery($query);
    }

    /** * @deprecated in 5.6, will be removed in 5.7 without replacement. * * {@inheritdoc} */
    public function createPriceIdQuery($priceIds$limit = null)
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be removed with 5.7. Will be removed without replacement.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        
Home | Imprint | This part of the site doesn't use cookies.