Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

MediaBundle/Controller/AviaryController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\MediaBundle\Controller;
4
5
use Kunstmaan\MediaBundle\Entity\Folder;
6
use Kunstmaan\MediaBundle\Entity\Media;
7
use Kunstmaan\MediaBundle\Helper\MediaManager;
8
use Symfony\Component\Routing\Annotation\Route;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\RedirectResponse;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * Controller class which Aviary can use to upload the edited image and add it to the database
15
 */
16
class AviaryController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use {@see AbstractController} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
17
{
18
    /**
19
     * @param Request $request
20
     * @param int     $folderId The id of the Folder
21
     * @param int     $mediaId  The id of the image
22
     *
23
     * @Route("/aviary/{folderId}/{mediaId}", requirements={"folderId" = "\d+", "mediaId" = "\d+"}, name="KunstmaanMediaBundle_aviary")
24
     *
25
     * @return RedirectResponse
26
     */
27
    public function indexAction(Request $request, $folderId, $mediaId)
28
    {
29
        $em = $this->getDoctrine()->getManager();
30
31
        /* @var Folder $folder */
32
        $folder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($folderId);
33
        /* @var Media $media */
34
        $media = $em->getRepository('KunstmaanMediaBundle:Media')->getMedia($mediaId);
35
        /* @var MediaManager $mediaManager */
36
        $mediaManager = $this->get('kunstmaan_media.media_manager');
37
38
        $media = clone $media;
39
        $handler = $mediaManager->getHandler($media);
40
        $fileHelper = $handler->getFormHelper($media);
41
        $fileHelper->getMediaFromUrl($request->get('url'));
42
        $media = $fileHelper->getMedia();
43
44
        $media->setUuid(null);
45
        $handler->prepareMedia($media);
46
47
        $em->persist($media);
48
        $em->flush();
49
50
        $media->setCreatedAt($media->getUpdatedAt());
51
        $em->persist($media);
52
        $em->flush();
53
54
        return new RedirectResponse(
55
            $this->generateUrl(
56
                'KunstmaanMediaBundle_folder_show',
57
                array('folderId' => $folder->getId())
58
            )
59
        );
60
    }
61
}
62