RepositoryIterator example

$criteria = new Criteria($ids);
        $criteria->setLimit(500);
        $criteria->addAssociation('group');
        $criteria->addAssociation('media');
        $criteria->addFilter(new EqualsFilter('group.filterable', true));
        $criteria->setTitle('product-listing::property-filter');
        $criteria->addSorting(new FieldSorting('id', FieldSorting::ASCENDING));

        $mergedOptions = new PropertyGroupOptionCollection();

        $repositoryIterator = new RepositoryIterator($this->repository, $context->getContext()$criteria);
        while (($loop = $repositoryIterator->fetch()) !== null) {
            $entities = $loop->getEntities();

            $mergedOptions->merge($entities);
        }

        // group options by their property-group         $grouped = $mergedOptions->groupByPropertyGroups();
        $grouped->sortByPositions();
        $grouped->sortByConfig();

        

    private function getIterator(array $ids, Context $context, array $configFields): RepositoryIterator
    {
        $context->setConsiderInheritance(true);

        $criteria = new Criteria($ids);
        $criteria->setLimit(50);

        $this->buildCriteria(array_column($configFields, 'field')$criteria$context);

        return new RepositoryIterator($this->productRepository, $context$criteria);
    }

    /** * @param array<string> $ids */
    private function delete(array $ids, string $languageId, string $versionId): void
    {
        $bytes = Uuid::fromHexToBytesList($ids);

        $params = [
            'ids' => $bytes,
            
$criteria = $this->getCriteria($filter);

        if ($criteria === null) {
            return;
        }

        $criteria->setLimit(150);
        $considerInheritance = $message->getContext()->considerInheritance();
        $message->getContext()->setConsiderInheritance(true);

        $iterator = new RepositoryIterator(
            $this->repository,
            $message->getContext(),
            $criteria
        );

        $binary = Uuid::fromHexToBytes($id);

        $ids = $this->connection->fetchFirstColumn(
            'SELECT LOWER(HEX(product_id)) FROM product_stream_mapping WHERE product_stream_id = :id',
            ['id' => $binary],
        );

        
public function testIteratedSearch(): void
    {
        $context = Context::createDefaultContext();
        /** @var EntityRepository<SystemConfigCollection> $systemConfigRepository */
        $systemConfigRepository = $this->getContainer()->get('system_config.repository');

        $criteria = new Criteria();
        $criteria->addFilter(new ContainsFilter('configurationKey', 'core'));
        $criteria->setLimit(1);

        /** @var RepositoryIterator<SystemConfigCollection> $iterator */
        $iterator = new RepositoryIterator($systemConfigRepository$context$criteria);

        $offset = 1;
        while (($result = $iterator->fetch()) !== null) {
            static::assertNotEmpty($result->getEntities()->first()?->getId());
            static::assertEquals(
                [new ContainsFilter('configurationKey', 'core')],
                $criteria->getFilters()
            );
            static::assertCount(0, $criteria->getPostFilters());
            static::assertEquals($offset$criteria->getOffset());
            ++$offset;
        }
throw new DecorationPatternException(self::class);
    }

    public function load(Context $context): RuleCollection
    {
        $criteria = new Criteria();
        $criteria->addSorting(new FieldSorting('priority', FieldSorting::DESCENDING));
        $criteria->addSorting(new FieldSorting('id'));
        $criteria->setLimit(500);
        $criteria->setTitle('cart-rule-loader::load-rules');

        $repositoryIterator = new RepositoryIterator($this->repository, $context$criteria);
        $rules = new RuleCollection();
        while (($result = $repositoryIterator->fetch()) !== null) {
            foreach ($result->getEntities() as $rule) {
                if (!$rule->isInvalid() && $rule->getPayload()) {
                    $rules->add($rule);
                }
            }
            if ($result->count() < 500) {
                break;
            }
        }

        
private function createFilterForNotUsedMedia(Context $context): Criteria
    {
        $criteria = new Criteria();

        $defaultFolderCriteria = new Criteria();
        $defaultFolderCriteria->setOffset(0);
        $defaultFolderCriteria->setLimit(50);
        $defaultFolderCriteria->addAssociation('folder.configuration');

        /** @var RepositoryIterator<MediaDefaultFolderCollection> $iterator */
        $iterator = new RepositoryIterator($this->defaultFolderRepo, $context$defaultFolderCriteria);
        while ($defaultFolders = $iterator->fetch()) {
            foreach ($defaultFolders->getEntities() as $defaultFolder) {
                if ($this->isNoAssociation($defaultFolder)) {
                    $folder = $defaultFolder->getFolder();
                    if ($folder === null) {
                        continue;
                    }

                    $criteria->addFilter(
                        new MultiFilter(
                            'OR',
                            [
$config = $route->getConfig();

        $repository = $this->definitionRegistry->getRepository($config->getDefinition()->getEntityName());

        $associations = $this->getAssociations($template$repository->getDefinition());
        $criteria->addAssociations($associations);

        $criteria->setLimit(50);

        /** @var RepositoryIterator<LandingPageCollection|CategoryCollection|ProductCollection> $iterator */
        $iterator = $context->enableInheritance(static fn (Context $context): RepositoryIterator => new RepositoryIterator($repository$context$criteria));

        $this->setTwigTemplate($config$template);

        while ($entities = $iterator->fetch()) {
            yield from $this->generateUrls($route$config$salesChannel$entities);
        }
    }

    /** * @param EntityCollection<Entity> $entities * * @return iterable<SeoUrlEntity> */
/** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->io = new ShopwareStyle($input$output);
        $context = Context::createDefaultContext();

        $this->initializeCommand($input$context);

        /** @var RepositoryIterator<MediaCollection> $mediaIterator */
        $mediaIterator = new RepositoryIterator($this->mediaRepository, $context$this->createCriteria());

        if (!$this->isAsync) {
            $this->generateSynchronous($mediaIterator$context);
        } else {
            $this->generateAsynchronous($mediaIterator$context);
        }

        return self::SUCCESS;
    }

    private function initializeCommand(InputInterface $input, Context $context): void
    {
$criteria->setOffset($offset);

            /** @var array<string> $ids */
            $ids = $this->mediaRepo->searchIds($criteria$context)->getIds();
            $ids = $this->filterOutNewMedia($ids$gracePeriodDays);
            $ids = $this->dispatchEvent($ids);

            return yield $this->searchMedia($ids$context);
        }

        // otherwise, we need iterate over the entire result set in batches         $iterator = new RepositoryIterator($this->mediaRepo, $context$criteria);
        while (($ids = $iterator->fetchIds()) !== null) {
            $ids = $this->filterOutNewMedia($ids$gracePeriodDays);
            $unusedIds = $this->dispatchEvent($ids);

            if (empty($unusedIds)) {
                continue;
            }

            yield $this->searchMedia($unusedIds$context);
        }
    }

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