Pre persist event handler.

@param MediaInterface $media
176665
public function prePersist(MediaInterface $media)
    {
        $this->cleanTranslations($media);
        $this->uploader->prepare($media);
    }
573607
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) {
		$this->processItems($entity, 'input');
	}
811254
public function onBootstrap(EventInterface $e)
    {
        $serviceManager = $e->getApplication()->getServiceManager();
        if (!$serviceManager->get(Environment::class)->is(\Admin42\Module::ENVIRONMENT_ADMIN)) {
            return;
        }
        $serviceManager
            ->get(MediaEventListener::class)
            ->attach($serviceManager->get('Media42\EventManager'));
    }
79423
protected function updateRecordForFile(Media $media, $path)
    {
        try {
            if ($this->uploader->update($media)) {
                ++$this->counters['updated'];
                $this->info("Updated record for {$path}", 'v');
            } else {
                ++$this->counters['skipped'];
                $this->info("Skipped unmodified file at {$path}", 'v');
            }
        } catch (MediaUploadException $e) {
            $this->warn($e->getMessage(), 'vvv');
            ++$this->counters['skipped'];
            $this->info("Skipped file at {$path}", 'v');
        }
    }
13271
public function deleteAlternatives(MediaInterface $media)
    {
        foreach ($this->strategies as $strategy) {
            if ($strategy->support($media)) {
                $strategy->deleteAlternatives($media);

                return;
            }
        }

        $this->defaultStrategy->deleteAlternatives($media);
    }
1041752
public function handlePreIndex(PreIndexEvent $event)
    {
        $metadata = $event->getMetadata();
        $reflection = $metadata->getClassMetadata()->reflection;

        if (
            false === $reflection->isSubclassOf(FileVersionMeta::class)
            && FileVersionMeta::class !== $metadata->getName()) {
            return;
        }

        $document = $event->getDocument();
        $subject = $event->getSubject();
        $locale = $subject->getLocale();

        $fileVersion = $subject->getFileVersion();
        $file = $fileVersion->getFile();
        $media = $file->getMedia();

        // Do not try and get the image URL if the mime type is not in the
        // list of mime types for which thumbnails are generated.
        foreach ($this->thumbnailMimeTypes as $type) {
            if (fnmatch($type, $fileVersion->getMimeType())) {
                $document->setImageUrl($this->getImageUrl($media, $locale));
                break;
            }
        }

        $document->addField($this->factory->createField(
            'media_id',
            $media->getId()
        ));

        $document->addField($this->factory->createField(
            'media_mime',
            $fileVersion->getMimeType()
        ));

        if ($collection = $media->getCollection()) {
            $document->addField($this->factory->createField(
                'collection_id',
                $collection->getId()
            ));
        }
    }
230939
public function postRemove(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof MediaInterface) {
            $this->getProvider($args)->postRemove($args->getObject());
        }
    }
679795
public function updateFocus(MediaInterface $media)
    {
        if ($this->angle == 90) {
            $focusLeft = 100 - $media->getFocusTop();
            $focusTop = $media->getFocusLeft();
        } elseif ($this->angle == -90) {
            $focusLeft = $media->getFocusTop();
            $focusTop = 100 - $media->getFocusLeft();
        }

        $media->setFocusLeft($focusLeft);
        $media->setFocusTop($focusTop);
    }
926112
public function generateAlternatives(MediaInterface $media)
    {
        if ($media->getFilesystemName() != '') {
            $filePath = $this->tmpDir . DIRECTORY_SEPARATOR . $media->getFilesystemName();
            $this->fileSystem->remove(array($filePath));
        }
    }
481831
public function flashMessengerHandler(EventInterface $e) : void
    {
        /** @var \Zend\Mvc\Controller\AbstractActionController $controller */
        $controller = $e->getTarget();
        if (!$controller->getPluginManager()->has('flashMessenger')) {
            return;
        }

        $flash = $controller->plugin('flashMessenger');
        $container = $flash->getContainer();
        $this->duplicateFlashMessengerSessionData($container);
    }
515811
public function postUpdate(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof MediaInterface) {
            $this->getProvider($args)->postUpdate($args->getObject());
        }
    }
230735
public function syncMedia($media, $tags)
    {
        $this->detachMediaTags($tags);
        $this->attachMedia($media, $tags);
    }
828741
public function onLoaded(ResourceInterface $resource)
    {
        if (!$this->isDebugging() || $this->current === $resource) {
            return;
        }

        $this->ensureCollector($this->current);
        $this->meta[$this->current]->addResource($resource);
    }
95418
public function beforeSave(Event $event, EntityInterface $entity) {
		if ($this->getConfig('uploadOn') === 'beforeSave') {
			$this->_handleFiles($entity);
		}
	}
523660
protected function fixFilename(MediaInterface $media)
    {
        if ($media->getBinaryContent() instanceof UploadedFile) {
            $media->setName($media->getName() ?: $media->getBinaryContent()->getClientOriginalName());
            $media->setMetadataValue('filename', $media->getBinaryContent()->getClientOriginalName());
        } elseif ($media->getBinaryContent() instanceof File) {
            $media->setName($media->getName() ?: $media->getBinaryContent()->getBasename());
            $media->setMetadataValue('filename', $media->getBinaryContent()->getBasename());
        }

        // this is the original name
        if (!$media->getName()) {
            throw new \RuntimeException('Please define a valid media\'s name');
        }
    }
779179
protected final void tickMedia (AbstractMedia media, long tickStamp)
    {
        if (media._firstTick == 0L) {
            media.willStart(tickStamp);
        }
        media.tick(tickStamp);
    }
810937
public function setSizeWidthAndHeight(MediaInterface $media)
    {
        $key = $this->originalDir.'/'.$media->getReference();

        $media->setSize($this->filesystemManipulator->size($key));

        if ($media->getType() === $media::IMAGE) {
            $image = $this->imagine->load(
                $this->filesystemManipulator->read($key)
            );
            $size = $image->getSize();
            $media->setWidth($size->getWidth());
            $media->setHeight($size->getHeight());
        }

        return $this;
    }