@param Media $media

@return void
548099
public function saveMedia(Media $media)
    {
        if (!$media->getContent() instanceof File) {
            return;
        }

        $this->uploader->uploadMedia($media);
    }
1123566
public function deleteAlternatives(MediaInterface $media)
    {
        foreach ($media->getAlternatives() as $storageKey) {
            $this->deleteFile($storageKey);
        }

        parent::deleteAlternatives($media);
    }
414606
public function prepareMedia(Media $media)
    {
        if (null === $media->getUuid()) {
            $uuid = uniqid();
            $media->setUuid($uuid);
        }

        $content = $media->getContent();
        if (empty($content)) {
            return;
        }

        if (!$content instanceof File) {
            if (!is_file($content)) {
                throw new \RuntimeException('Invalid file');
            }

            $file = new File($content);
            $media->setContent($file);
        }

        $contentType = $this->mimeTypeGuesser->guess($content->getPathname());
        if ($content instanceof UploadedFile) {
            $pathInfo = pathinfo($content->getClientOriginalName());

            if (!array_key_exists('extension', $pathInfo)) {
                $pathInfo['extension'] = $this->extensionGuesser->guess($contentType);
            }

            $media->setOriginalFilename($this->slugifier->slugify($pathInfo['filename']).'.'.$pathInfo['extension']);
            $name = $media->getName();

            if (empty($name)) {
                $media->setName($media->getOriginalFilename());
            }
        }

        $media->setContentType($contentType);
        $media->setFileSize(filesize($media->getContent()));
        $media->setUrl($this->mediaPath . $this->getFilePath($media));
        $media->setLocation('local');
    }
933407
protected void tickAllMedia (long tickStamp)
    {
        // we use _tickpos so that it can be adjusted if media is added or removed during the tick
        // dispatch
        for (_tickpos = 0; _tickpos < _media.size(); _tickpos++) {
            tickMedia(_media.get(_tickpos), tickStamp);
        }
        _tickpos = -1;
    }
585328
public function setMedia(\Sonata\MediaBundle\Entity\BaseMedia $media = null)
    {
        $this->media = $media;
        return $this;
    }
209254
public function registerMediaConversions(Media $media = null)
    {
        $conversions        = config('assetlibrary.conversions');

        foreach ($conversions as $key => $value) {
            $conversionName = $key;

            $this->addMediaConversion($conversionName)
                ->width($value['width'])
                ->height($value['height'])
                ->keepOriginalImageFormat()
                ->optimize();
        }

        if (config('assetlibrary.allowCropping')) {
            $this->addMediaConversion('cropped')
                ->keepOriginalImageFormat()
                ->optimize();
        }
    }
842415
public function updateFocus(MediaInterface $media)
    {
        $originalFocusLeftPx = ($media->getFocusLeft() * $media->getWidth()) / 100;
        $newFocusLeftPx = $originalFocusLeftPx - $this->x;
        $newFocusLeft = ($newFocusLeftPx * 100) / $this->w;

        if ($newFocusLeft < 0) {
            $newFocusLeft = 0;
        }
        if ($newFocusLeft > 100) {
            $newFocusLeft = 100;
        }

        $media->setFocusLeft($newFocusLeft);

        $originalFocusTopPx = ($media->getFocusTop() * $media->getHeight()) / 100;
        $newFocusTopPx = $originalFocusTopPx - $this->y;
        $newFocusTop = ($newFocusTopPx * 100) / $this->h;

        if ($newFocusTop < 0) {
            $newFocusTop = 0;
        }
        if ($newFocusTop > 100) {
            $newFocusTop = 100;
        }

        $media->setFocusTop($newFocusTop);
    }
1066079
public function deleteAction(Request $request, Media $media)
    {
        $user = $this->getBlogUser();
        $mediaLibrary = $this->container->get('sonata.media.manager.gallery')->findOneBy(array('name' => 'Media Library'));
        $em = $this->getDoctrine()->getManager();

        foreach($media->getGalleryHasMedias() as $hasMedia)
        {
            if($hasMedia->getGallery() == $mediaLibrary)
            {
                $em->remove($hasMedia);
            }
        }

        $em->flush();

        if($request->isXmlHttpRequest())
        {
            return new JsonResponse(array('success' => 'true'));
        }

        $this->get('session')->getFlashBag()->add('success', 'Photo removed successfully.');
        return $this->redirectToRoute('ed_blog_admin_media_list');
    }
1307143
protected function registerMediaSort()
    {
        $this->media_sort_null = sha1(time());

        if (defined('MEDIASORT_NULL') === false) {
            define('MEDIASORT_NULL', $this->media_sort_null);
        }
    }
80110
protected function invalidate($media)
    {
        $tags = array($this->tagManager->formatMediaIdTag($media->getId()));

        $nodeUsage = $media->getUseReferences(NodeInterface::ENTITY_TYPE);

        foreach ($nodeUsage as $nodeId) {
            $tags[] = $this->tagManager->formatNodeIdTag($nodeId);
        }

        $contentUsage = $media->getUseReferences(ContentInterface::ENTITY_TYPE);
        foreach ($contentUsage as $contentId) {
            $tags[] = $this->tagManager->formatContentIdTag($contentId);
        }

        $contentTypeUsage = $media->getUseReferences(ContentTypeInterface::ENTITY_TYPE);
        foreach ($contentTypeUsage as $contentTypeId) {
            $tags[] = $this->tagManager->formatContentTypeTag($contentTypeId);
        }

        $this->cacheableManager->invalidateTags($tags);
    }
745987
public function destroy(Manager $manager, Media $media)
    {
        $manager->media()->where($media->getKeyName(), $media->getKey())->first()->delete();

        return intend([
            'url' => route('adminarea.managers.edit', ['manager' => $manager]),
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])],
        ]);
    }
198163
public function removeMedia(MediaInterface $media)
    {
        if ($this->medias->contains($media)) {
            $this->medias->removeElement($media);
        }
        return $this;
    }
409694
private function removeOrphanMedias(Media $media)
    {
        if (count($media->getTweets()) == 0) {
            $this->_em->remove($media);
        }
    }
623076
private function deleteExistingMedia(Media $model)
    {
        Media::where('disk', $model->disk)
            ->where('directory', $model->directory)
            ->where('filename', $model->filename)
            ->where('extension', $model->extension)
            ->delete();

        $this->deleteExistingFile($model);
    }
1091553
public function prune($media = null)
    {
        if ($media) {
            $this->addUsingAlias(MediaTableMap::COL_ID, $media->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }
964015
public function destroy(Event $event, Media $media)
    {
        $event->media()->where($media->getKeyName(), $media->getKey())->first()->delete();

        return intend([
            'url' => route('adminarea.events.media.index', ['event' => $event]),
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/foundation::common.media'), 'identifier' => $media->getRouteKey()])],
        ]);
    }
230735
public function syncMedia($media, $tags)
    {
        $this->detachMediaTags($tags);
        $this->attachMedia($media, $tags);
    }