src/EventListener/ImageStorageListener.php
/**
     * Removing old cached and real images, before the upload function.
     */
Removing old cached and real images, before the upload function.
Removing old cached and real images before the upload function .
public function onFlush(OnFlushEventArgs $args): void
    {
        $em = $args->getEntityManager();
        $uow = $em->getUnitOfWork();
        $entities = $uow->getScheduledEntityUpdates();
        if ($entities) {
            $entity = $entities[array_key_first($entities)];
            if (!$entity instanceof Reduction) {
                return;
            }
            $image = $entity->getImage();
            if (!$this->imageManager->imageCanBeDeleted($image)) {
                return;
            }
            $this->imageManager->cacheRemove($image, self::TARGETED_FILTERS);
            $this->imageManager->remove($image);
        }
    }
public function onFlush ( OnFlushEventArgs $ args ) : void { $ em = $ args -> getEntityManager ( ) ; $ uow = $ em -> getUnitOfWork ( ) ; $ entities = $ uow -> getScheduledEntityUpdates ( ) ; if ( $ entities ) { $ entity = $ entities [ array_key_first ( $ entities ) ] ; if ( ! $ entity instanceof Reduction ) { return ; } $ image = $ entity -> getImage ( ) ; if ( ! $ this -> imageManager -> imageCanBeDeleted ( $ image ) ) { return ; } $ this -> imageManager -> cacheRemove ( $ image , self :: TARGETED_FILTERS ) ; $ this -> imageManager -> remove ( $ image ) ; } }
Removing old cached and real images, before the upload function.
Removing old cached and real images before the upload function .
/** @var Reduction $entity */ /** @var Image $image */