removeThumbnails example

->setDescription('Deletes thumbnails for images whose original file has been deleted.')
            ->setHelp('The <info>%command.name%</info> deletes unused thumbnails.');
    }

    /** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input$output);

        $this->removeThumbnails($io);

        return 0;
    }

    private function removeThumbnails(SymfonyStyle $io): void
    {
        $filesystem = $this->getContainer()->get(MediaServiceInterface::class)->getFilesystem();

        $thumbnailFiles = $this->searchThumbnails($io$filesystem);

        if (\count($thumbnailFiles) === 0) {
            
$media->setFileSize(filesize($filePath));
        $media->setCreated(new DateTime());

        if ($media->getType() === Media::TYPE_IMAGE) {
            $imageSize = getimagesize($filePath);

            if ($imageSize) {
                $media->setWidth($imageSize[0]);
                $media->setHeight($imageSize[1]);
            }

            $media->removeThumbnails();

            if ($newFileName) {
                $media->setPath($newFileName);
            }

            $this->thumbnailManager->createMediaThumbnail($media$media->getDefaultThumbnails(), true);
            $media->createAlbumThumbnails($media->getAlbum());
        } elseif ($newFileName) {
            $media->setPath($newFileName);
        }

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