Ojs\JournalBundle\Controller\SectionController::deleteAction PHP Method

deleteAction() public method

Deletes a Section entity.
public deleteAction ( Request $request, $id ) : RedirectResponse
$request Symfony\Component\HttpFoundation\Request
$id
return Symfony\Component\HttpFoundation\RedirectResponse
    public function deleteAction(Request $request, $id)
    {
        $journal = $this->get('ojs.journal_service')->getSelectedJournal();
        $eventDispatcher = $this->get('event_dispatcher');
        if (!$this->isGranted('DELETE', $journal, 'sections')) {
            throw new AccessDeniedException("You are not authorized for delete this journal's section!");
        }
        $em = $this->getDoctrine()->getManager();
        $entity = $em->getRepository('OjsJournalBundle:Section')->find($id);
        if (!$entity) {
            throw $this->createNotFoundException('notFound');
        }
        $csrf = $this->get('security.csrf.token_manager');
        $token = $csrf->getToken('ojs_journal_section' . $id);
        if ($token != $request->get('_token')) {
            throw new TokenNotFoundException("Token Not Found!");
        }
        $event = new JournalItemEvent($entity);
        $eventDispatcher->dispatch(SectionEvents::PRE_DELETE, $event);
        foreach ($entity->getArticles() as $article) {
            $article->setIssue(null);
            $article->setSection(null);
            $article->setStatus(ArticleStatuses::STATUS_PUBLISH_READY);
            $em->persist($article);
        }
        $em->flush();
        // Detach articles first
        $this->get('ojs_core.delete.service')->check($entity);
        $em->remove($entity);
        $em->flush();
        $event = new JournalEvent($journal);
        $eventDispatcher->dispatch(SectionEvents::POST_DELETE, $event);
        if ($event->getResponse()) {
            return $event->getResponse();
        }
        $this->successFlashBag('deletion.section');
        return $this->redirectToRoute('ojs_journal_section_index', ['journalId' => $journal->getId()]);
    }