searchMedia example


    /** * @internal */
    public function __construct(private readonly EntityRepository $mediaRepository)
    {
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('searchMedia', $this->searchMedia(...)),
        ];
    }

    public function searchMedia(array $ids, Context $context): MediaCollection
    {
        if (empty($ids)) {
            return new MediaCollection();
        }

        $criteria = new Criteria($ids);

        
$criteria->setLimit($limit);

        // if we provided an offset, then just grab that batch based on the limit         if ($offset !== null) {
            $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;
            }

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