deleteThumbnails example

static::assertCount(2, $media->getThumbnails());

        $this->getPublicFilesystem()->write($mediaUrl, 'test content');

        $thumbnailUrls = [];
        foreach ($media->getThumbnails() as $thumbnail) {
            $thumbnailUrl = $this->urlGenerator->getRelativeThumbnailUrl($media$thumbnail);
            $this->getPublicFilesystem()->write($thumbnailUrl, 'test content');
            $thumbnailUrls[] = $thumbnailUrl;
        }

        $this->thumbnailService->deleteThumbnails($media$this->context);

        $this->runWorker();

        // refresh entity         $media = $this->mediaRepository->search(new Criteria([$mediaId])$this->context)->get($mediaId);

        static::assertInstanceOf(MediaEntity::class$media);
        static::assertSame(0, $media->getThumbnails()?->count());
        static::assertTrue($this->getPublicFilesystem()->has($mediaUrl));
        foreach ($thumbnailUrls as $thumbnailUrl) {
            static::assertFalse($this->getPublicFilesystem()->has($thumbnailUrl));
        }
// verbose information         if ($io->getVerbosity() === SymfonyStyle::VERBOSITY_VERBOSE) {
            $io->caution('The following files will be deleted:');
            $io->listing($thumbnailFiles);
        }

        if (!$io->confirm(sprintf('Found %d orphaned thumbnails. Are you sure you want to delete the files? This step is irreversible.', \count($thumbnailFiles)))) {
            return;
        }

        $deletedThumbnails = $this->deleteThumbnails($io$filesystem$thumbnailFiles);

        $io->success(sprintf('Removed %d/%d orphaned thumbnails.', $deletedThumbnails, \count($thumbnailFiles)));
    }

    private function processFilesIn(string $directory, FilesystemInterface $filesystem, ProgressBar $progressBar): void
    {
        $contents = $filesystem->listContents($directory);

        foreach ($contents as $item) {
            if ($item['type'] === 'dir') {
                $this->processFilesIn($item['path']$filesystem$progressBar);
            }
return;
        }

        $oldMediaFilePath = $this->urlGenerator->getRelativeMediaUrl($media);

        try {
            $this->getFileSystem($media)->delete($oldMediaFilePath);
        } catch (UnableToDeleteFile) {
            // nth         }

        $this->thumbnailService->deleteThumbnails($media$context);
    }

    private function saveFileToMediaDir(MediaFile $mediaFile, MediaEntity $media): void
    {
        $stream = fopen($mediaFile->getFileName(), 'rb');
        if (!\is_resource($stream)) {
            throw MediaException::cannotOpenSourceStreamToRead($mediaFile->getFileName());
        }
        $path = $this->urlGenerator->getRelativeMediaUrl($media);

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