<commit_before><?php

namespace OpenOrchestra\MediaAdmin\EventSubscriber;

use OpenOrchestra\MediaAdmin\FileAlternatives\FileAlternativesManager;
use OpenOrchestra\MediaAdmin\Event\MediaEvent;
use OpenOrchestra\MediaAdmin\MediaEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use OpenOrchestra\Media\Model\MediaInterface;

/**
 * Class MediaDeletedSubscriber
 */
class MediaDeletedSubscriber implements EventSubscriberInterface
{
    protected $medias = array();
    protected $fileAlternativesManager;

    /**
     * @param FileAlternativesManager $fileAlternativesManager
     */
    public function __construct(FileAlternativesManager $fileAlternativesManager)
    {
        $this->fileAlternativesManager = $fileAlternativesManager;
    }

    /**
     * @param MediaEvent $event
     */
    public function deleteMedia(MediaEvent $event)
    {
        $media = $event->getMedia();
        $this->medias[] = $media;
    }

    /**
     * Remove medias
     */
    public function deleteAlternatives()
    {
        /** @var MediaInterface $media */
        foreach ($this->medias as $media) {
            $this->fileAlternativesManager->deleteThumbnail($media);
            $this->fileAlternativesManager->deleteAlternatives($media);
        }
    }

    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return array(
            MediaEvents::MEDIA_DELETE => 'deleteMedia',
            KernelEvents::TERMINATE => 'deleteAlternatives',
        );
    }
}<commit_msg>fix error on non existing thumbnail deletion<commit_after><?php

namespace OpenOrchestra\MediaAdmin\EventSubscriber;

use OpenOrchestra\MediaAdmin\FileAlternatives\FileAlternativesManager;
use OpenOrchestra\MediaAdmin\Event\MediaEvent;
use OpenOrchestra\MediaAdmin\MediaEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use OpenOrchestra\Media\Model\MediaInterface;

/**
 * Class MediaDeletedSubscriber
 */
class MediaDeletedSubscriber implements EventSubscriberInterface
{
    protected $medias = array();
    protected $fileAlternativesManager;

    /**
     * @param FileAlternativesManager $fileAlternativesManager
     */
    public function __construct(FileAlternativesManager $fileAlternativesManager)
    {
        $this->fileAlternativesManager = $fileAlternativesManager;
    }

    /**
     * @param MediaEvent $event
     */
    public function deleteMedia(MediaEvent $event)
    {
        $media = $event->getMedia();
        $this->medias[] = $media;
    }

    /**
     * Remove medias
     */
    public function deleteAlternatives()
    {
        /** @var MediaInterface $media */
        foreach ($this->medias as $media) {
            if (null !== $media->getThumbnail()) {
                $this->fileAlternativesManager->deleteThumbnail($media);
            }

            $this->fileAlternativesManager->deleteAlternatives($media);
        }
    }

    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return array(
            MediaEvents::MEDIA_DELETE => 'deleteMedia',
            KernelEvents::TERMINATE => 'deleteAlternatives',
        );
    }
}
{'fraction_non_alphanumeric': 0.10442748091603053, 'fraction_numerical': 0.0, 'mean_word_length': 3.0898876404494384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6124272', 'n_tokens_mistral': 905, 'n_tokens_neox': 876, 'n_words': 153}