Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
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\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\Routing\Annotation\Route;
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 "Symfony\Bundle\FrameworkBundle\Controller\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 int $folderId The id of the Folder
20
     * @param int $mediaId  The id of the image
21
     *
22
     * @Route("/aviary/{folderId}/{mediaId}", requirements={"folderId" = "\d+", "mediaId" = "\d+"}, name="KunstmaanMediaBundle_aviary")
23
     *
24
     * @return RedirectResponse
25
     */
26
    public function indexAction(Request $request, $folderId, $mediaId)
27
    {
28
        $em = $this->getDoctrine()->getManager();
29
30
        /* @var Folder $folder */
31
        $folder = $em->getRepository(Folder::class)->getFolder($folderId);
32
        /* @var Media $media */
33
        $media = $em->getRepository(Media::class)->getMedia($mediaId);
34
        /* @var MediaManager $mediaManager */
35
        $mediaManager = $this->get('kunstmaan_media.media_manager');
36
37
        $media = clone $media;
38
        $handler = $mediaManager->getHandler($media);
39
        $fileHelper = $handler->getFormHelper($media);
40
        $fileHelper->getMediaFromUrl($request->get('url'));
41
        $media = $fileHelper->getMedia();
42
43
        $media->setUuid(null);
44
        $handler->prepareMedia($media);
45
46
        $em->persist($media);
47
        $em->flush();
48
49
        $media->setCreatedAt($media->getUpdatedAt());
50
        $em->persist($media);
51
        $em->flush();
52
53
        return new RedirectResponse(
54
            $this->generateUrl(
55
                'KunstmaanMediaBundle_folder_show',
56
                ['folderId' => $folder->getId()]
57
            )
58
        );
59
    }
60
}
61