public function deleteAction(Request $request, $id)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
$eventDispatcher = $this->get('event_dispatcher');
if (!$this->isGranted('DELETE', $journal, 'issues')) {
throw new AccessDeniedException("You are not authorized for delete this journal's issue!");
}
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('OjsJournalBundle:Issue')->find($id);
$this->throw404IfNotFound($entity);
$csrf = $this->get('security.csrf.token_manager');
$token = $csrf->getToken('ojs_journal_issue' . $id);
if ($token != $request->get('_token')) {
throw new TokenNotFoundException("Token Not Found!");
}
$event = new JournalItemEvent($entity);
$eventDispatcher->dispatch(IssueEvents::PRE_DELETE, $event);
// We are detaching articles from both the issue and its section in order
// to make them available for putting inside another issue's section.
foreach ($entity->getArticles() as $article) {
$article->setIssue(null);
$article->setSection(null);
$em->persist($article);
}
$entity->getSections()->clear();
// Remove all section relations
$em->flush();
// Detach articles and sections first
$this->get('ojs_core.delete.service')->check($entity);
$em->remove($entity);
$em->flush();
$event = new JournalEvent($journal);
$eventDispatcher->dispatch(IssueEvents::POST_DELETE, $event);
if ($event->getResponse()) {
return $event->getResponse();
}
$this->successFlashBag('deletion.issue');
return $this->redirectToRoute('ojs_journal_issue_index', ['journalId' => $journal->getId()]);
}