createFilterForNotUsedMedia example

private readonly EntityRepository $defaultFolderRepo
    ) {
    }

    public function countNotUsedMedia(Context $context): int
    {
        Feature::triggerDeprecationOrThrow(
            'v6.6.0.0',
            sprintf('%s is deprecated and will be removed in v6.6.0.0. Use %s instead.', self::class, UnusedMediaPurger::class),
        );

        $criteria = $this->createFilterForNotUsedMedia($context);
        $criteria->setLimit(1);
        $criteria->setTotalCountMode(Criteria::TOTAL_COUNT_MODE_EXACT);

        return $this->mediaRepo->search($criteria$context)->getTotal();
    }

    public function deleteNotUsedMedia(Context $context): void
    {
        Feature::triggerDeprecationOrThrow(
            'v6.6.0.0',
            sprintf('%s is deprecated and will be removed in v6.6.0.0. Use %s instead.', self::class, UnusedMediaPurger::class),
        );

    public function getNotUsedMedia(?int $limit = 50, ?int $offset = null, ?int $gracePeriodDays = null, ?string $folderEntity = null): \Generator
    {
        $limit ??= 50;
        $gracePeriodDays ??= 0;

        $context = Context::createDefaultContext();

        $criteria = $this->createFilterForNotUsedMedia($folderEntity);
        $criteria->addSorting(new FieldSorting('media.createdAt', FieldSorting::ASCENDING));
        $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);

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