markAsUsed example

$mediaIds = [];
        foreach ($allThemeIds as $themeId) {
            $config = $this->themeService->getThemeConfiguration($themeId, false, $context);

            foreach ($config['fields'] ?? [] as $data) {
                if ($data['type'] === 'media' && $data['value'] && Uuid::isValid($data['value'])) {
                    $mediaIds[] = $data['value'];
                }
            }
        }

        $event->markAsUsed(array_unique($mediaIds));
    }
}
if (\count($statements) === 0) {
            return;
        }

        foreach ($statements as $statement) {
            $usedMediaIds = $this->connection->fetchFirstColumn(
                $statement,
                [$event->getUnusedIds()],
                [ArrayParameterType::STRING]
            );

            $event->markAsUsed($usedMediaIds);
        }
    }

    /** * @return list<array{id: string, name: string, entity_name: string}> */
    private function findCustomFieldsWithEntitySelect(string $componentType): array
    {
        /** @var list<array{id: string, name: string, entity_name: string}> $results */
        $results = $this->connection->fetchAllAssociative(
            sprintf(
                


    /** * @dataProvider removeIdsProvider * * @param array<string> $idsToRemove * @param array<string> $expectedIds */
    public function testRemoveIds(array $idsToRemove, array $expectedIds): void
    {
        $event = new UnusedMediaSearchEvent(['1', '2', '3']);
        $event->markAsUsed($idsToRemove);
        static::assertEquals($expectedIds$event->getUnusedIds());
    }

    /** * @return array<string, array{remove: array<string>, expected: array<string>}> */
    public static function removeIdsProvider(): array
    {
        return [
            'remove-last-id' => ['remove' => ['3'], 'expected' => ['1', '2']],
            'remove-middle-id' => ['remove' => ['2'], 'expected' => ['1', '3']],
            


    public static function getSubscribedEvents(): array
    {
        return [
            UnusedMediaSearchEvent::class => 'removeUsedMedia',
        ];
    }

    public function removeUsedMedia(UnusedMediaSearchEvent $event): void
    {
        $event->markAsUsed($this->findMediaIdsInImageGalleries($event));
        $event->markAsUsed($this->findMediaIdsInImages($event));

        foreach (['category_translation', 'product_translation'] as $table) {
            $event->markAsUsed($this->findMediaIdsInImageGalleriesInOverridesTable($table$event));
            $event->markAsUsed($this->findMediaIdsInImagesInOverridesTable($table$event));
        }
    }

    /** * @return array<string> */
    
static::assertSame([$id2]$criteria->getIds());

                    return new MediaCollection([$media2]);
                },
                [],
            ],
            $mediaDefinition
        );

        $eventDispatcher = new EventDispatcher();
        $eventDispatcher->addListener(UnusedMediaSearchEvent::classfunction DUnusedMediaSearchEvent $event) use ($id1): void {
            $event->markAsUsed([$id1]);
        });

        $purger = new UnusedMediaPurger($repo$eventDispatcher);
        $media = array_merge([], ...iterator_to_array($purger->getNotUsedMedia()));

        static::assertEquals([$media2]$media);
    }

    public function testGetNotUsedMediaDoesNotFetchAnyMediaIfAllRemovedByListener(): void
    {
        $this->configureRegistry([
            
Home | Imprint | This part of the site doesn't use cookies.