Duplicates content based on their id.

@param Request $request

@return Response
778975
public function duplicateAction(Request $request)
    {
        $content = $request->getContent();

        if (!empty($content)) {
            $params = json_decode($content, true);
        }

        /** @var ContentManagerInterface $contentManager */
        $contentManager = $this->get('opifer.content.content_manager');
        $content = $contentManager->getRepository()->find($params['id']);
        $response = new JsonResponse();

        try {
            if (!$content) {
                throw $this->createNotFoundException('No content found for id '.$params['id']);
            }

            /** @var BlockManager $blockManager */
            $blockManager = $this->container->get('opifer.content.block_manager');

            $duplicatedContent = $contentManager->duplicate($content);
            $this->getDoctrine()->getManager()->flush($duplicatedContent);

            $duplicatedBlocks = $blockManager->duplicate($content->getBlocks(), $duplicatedContent);

            $duplicatedContent->setBlocks($duplicatedBlocks);
            $this->getDoctrine()->getManager()->flush($duplicatedContent);

            $response->setData(['success' => true]);
        } catch (\Exception $e) {
            $response->setStatusCode(500);
            $response->setData(['error' => $e->getMessage()]);
        }

        return $response;
    }
396418
public function removeAction(Request $request): Response
    {
        $form = $this->formFactory->removeContentDraft();
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (ContentRemoveData $data) {
                foreach (array_keys($data->getVersions()) as $version) {
                    $versionId = VersionId::fromString($version);

                    $this->contentService->deleteVersion(
                        $this->contentService->loadVersionInfoById(
                            $versionId->getContentId(),
                            $versionId->getVersionNo()
                        )
                    );
                }

                return $this->redirectToRoute('ezplatform.content_draft.list');
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirectToRoute('ezplatform.content_draft.list');
    }
968561
public function addAction(Request $request): Response
    {
        $form = $this->formFactory->addTranslation();
        $form->handleRequest($request);

        /** @var TranslationAddData $data */
        $data = $form->getData();
        $location = $data->getLocation();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (TranslationAddData $data) {
                $location = $data->getLocation();
                $contentInfo = $location->getContentInfo();
                $language = $data->getLanguage();
                $baseLanguage = $data->getBaseLanguage();

                return new RedirectResponse($this->generateUrl('ezplatform.content.translate', [
                    'contentId' => $contentInfo->id,
                    'fromLanguageCode' => null !== $baseLanguage ? $baseLanguage->languageCode : null,
                    'toLanguageCode' => $language->languageCode,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        $redirectionUrl = null !== $location
            ? $this->generateUrl('_ezpublishLocation', ['locationId' => $location->id])
            : $this->generateUrl('ezplatform.dashboard');

        return $this->redirect($redirectionUrl);
    }
1311562
public function putAction(Request $request, $id)
    {
        $document = $this->findDocument($id, $this->getLocale($request));

        $this->requestHashChecker->checkHash($request, $document, $document->getUuid());
        if (!$this->checkAreaSnippet($request, $document)) {
            return new JsonResponse(
                [
                    'structures' => [],
                    'other' => [],
                    'isDefault' => true,
                ],
                409
            );
        }

        $this->processForm($request, $document);

        return $this->handleView($document);
    }
461027
protected function appendNextUrl(Request $request)
    {
        return !empty($request->getPathInfo()) && strpos($request->getPathInfo(), $this->loginPath) == false;
    }
1144822
public function postAction(Request $request)
    {
        $contentUid = $request->request->get('content_uid');
        $contentType = $request->request->get('content_type', null);
        $mediaFolderUid = $request->request->get('folder_uid', null);
        $mediaTitle = $request->request->get('title', 'Untitled media');

        if (null === $mediaFolderUid) {
            $mediaFolder = $this->getMediaFolderRepository()->getRoot();
        } else {
            $mediaFolder = $this->getMediaFolderRepository()->find($mediaFolderUid);
        }

        if (null === $mediaFolder) {
            throw new NotFoundHttpException('Cannot find a media folder');
        }

        if (null !== $content = $this->getClassContentManager()->findOneByTypeAndUid($contentType, $contentUid)) {
            $this->autoCommitContent($content);
        }

        $media = new Media();
        $media->setContent($content);
        $media->setTitle($mediaTitle);
        $media->setMediaFolder($mediaFolder);

        $this->getEntityManager()->persist($media);
        $this->getEntityManager()->flush();

        return $this->createJsonResponse(null, 201, [
            'BB-RESOURCE-UID' => $media->getId(),
            'Location'        => $this->getApplication()->getRouting()->getUrlByRouteName(
                'bb.rest.media.get',
                [
                    'version' => $request->attributes->get('version'),
                    'uid'     => $media->getId(),
                ],
                '',
                false
            ),
        ]);
    }
899428
public function duplicateAction(Request $request)
    {
        $format = $request->get('_format', 'json');
        $facade = $this->get('jms_serializer')->deserialize(
            $request->getContent(),
            $this->getParameter('open_orchestra_api.facade.content.class'),
            $format
        );
        $content = $this->get('open_orchestra_api.transformer_manager')->reverseTransform('content', $facade);
        $this->denyAccessUnlessGranted(ContributionActionInterface::CREATE, $content);

        if (!$this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::READ, $content)) {
            throw new ContentTypeNotAllowedException();
        }

        $frontLanguages = $this->getParameter('open_orchestra_backoffice.orchestra_choice.front_language');

        $contentId = $content->getContentId();
        $newContentId = null;
        $objectManager = $this->get('object_manager');

        foreach (array_keys($frontLanguages) as $language) {
            $content = $this->findOneContent($contentId, $language);
            if ($content instanceof ContentInterface) {
                $duplicateContent = $this->get('open_orchestra_backoffice.manager.content')->duplicateContent($content, $newContentId);
                $objectManager->persist($duplicateContent);

                $newContentId = $duplicateContent->getContentId();
                $this->dispatchEvent(ContentEvents::CONTENT_DUPLICATE, new ContentEvent($duplicateContent));
            }
        }
        $objectManager->flush();

        return array();
    }
74123
public function markAllAsReadAction(Request $request): Response
    {
        $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
        $this->isGrantedOr403($configuration, ResourceActions::UPDATE);

        $this->messageManager->markAllAsRead($this->getUser());

        if (!$configuration->isHtmlRequest()) {
            return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
        }

        $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE);

        return $this->redirectHandler->redirectToIndex($configuration);
    }
571620
public function deleteAction(Request $request, $id)
    {
        $locale = $this->getLocale($request);
        $webspaceKey = $request->query->get('webspace', null);

        $references = $this->snippetRepository->getReferences($id);

        if (count($references) > 0) {
            $force = $request->headers->get('SuluForceRemove', false);
            if ($force) {
                $this->contentMapper->delete($id, $webspaceKey, true);
            } else {
                return $this->getReferentialIntegrityResponse($webspaceKey, $references, $id, $locale);
            }
        } else {
            $this->contentMapper->delete($id, $webspaceKey);
        }

        return new JsonResponse();
    }
1044107
public function send(Request $request)
    {
        $response     = new GetIndexResponse();
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);
        $json         = $httpResponse->json();

        $response->name   = $request->name;
        $response->nVal   = $json['n_val'];
        $response->schema = $json['schema'];

        return $response;
    }
1105018
public static function canBeUsedForRequest(Request $request)
    {
        return $request->has(self::CHUNK_UUID_INDEX) && $request->has(self::CHUNK_TOTAL_INDEX) &&
            $request->has(self::CHUNK_INDEX);
    }
769925
public function editVariation(Request $request)
    {
        $product = Product::findorfail($request->get('variation_id'));
        $view = view('avored-framework::product.variation-modal')
                            ->with('model', $product);

        return new JsonResponse(
            ['success' => true,
            'content' => $view->render(),
            'modalId' => '#variation-modal-' . $product->id]
        );
    }
809992
public function getAction(Request $request, $id)
    {
        $document = $this->getModel()->getSerialised($id, $request);

        $response = $this->getResponse()
            ->setStatusCode(Response::HTTP_OK)
            ->setContent($document);

        return $response;
    }
819079
public function loadContentTypeByRemoteId(Request $request)
    {
        return $this->contentTypeService->loadContentTypeByRemoteId(
            $request->query->get('remoteId'),
            Language::ALL
        );
    }
464339
public function duplicateAction(Request $request)
    {
        /* @var $rep ItemRepository */
        $rep = $this->getDoctrine()->getRepository('AnimeDbCatalogBundle:Item');

        // get store item
        $item = $request->getSession()->get(self::NAME_ITEM_ADDED);
        if (!($item instanceof Item)) {
            throw $this->createNotFoundException('Not found item for confirm duplicate');
        }

        // confirm duplicate
        if ($request->isMethod('POST')) {
            $request->getSession()->remove(self::NAME_ITEM_ADDED);
            switch ($request->request->get('do')) {
                case 'add':
                    return $this->addItem($item->freez($this->getDoctrine()));
                default:
                    return $this->redirect($this->generateUrl('home'));
            }
        }

        // re searching for duplicates
        $duplicate = $rep->findDuplicate($item);
        // now there is no duplication
        if (!$duplicate) {
            return $this->addItem($item->freez($this->getDoctrine()));
        }

        return $this->render('AnimeDbCatalogBundle:Item:duplicate.html.twig', [
            'items' => $duplicate,
        ]);
    }
1340999
public function indexAction(Request $request)
    {
        // Special case, not correctly setup yet. Do so now.
        if (!$this->isInstalled()) {
            return new RedirectResponse($request->getUri() . 'install.html');
        }

        return new Response(
            str_replace(
                'var TENSIDEApi=window.location.href.split(\'#\')[0];',
                'var TENSIDEApi=\'' . $request->getSchemeAndHttpHost() . $request->getBaseUrl() . '/\';',
                file_get_contents($this->getAssetsDir() . '/index.html')
            ),
            200,
            [
                'Content-Type' => 'text/html; charset=UTF-8'
            ]
        );
    }
602993
public function duplicateAction(Request $request)
    {
        $this->denyAccessUnlessGranted(ContributionActionInterface::CREATE, GroupInterface::ENTITY_TYPE);

        $format = $request->get('_format', 'json');
        $facade = $this->get('jms_serializer')->deserialize(
            $request->getContent(),
            $this->getParameter('open_orchestra_group.facade.group.class'),
            $format
        );

        $group = $this->get('open_orchestra_api.transformer_manager')->reverseTransform('group', $facade);

        $newGroup = clone $group;

        $currentSiteId = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteId();
        $currentSite = $this->get('open_orchestra_model.repository.site')->findOneBySiteId($currentSiteId);

        $newGroup->setWorkflowProfileCollections($group->getWorkflowProfileCollections());
        if ($newGroup->getSite()->getId() === $currentSite->getId()) {
            $newGroup->setPerimeters($group->getPerimeters());
        }
        $newGroup->setSite($currentSite);

        $objectManager = $this->get('object_manager');
        $objectManager->persist($newGroup);
        $objectManager->flush();

        return array();
    }