public function deleteAction(Request $request, Article $article)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
$em = $this->getDoctrine()->getManager();
if (!$this->isGranted('EDIT', $journal, 'articles')) {
throw new AccessDeniedException("You not authorized for this page!");
}
/** @var $dispatcher EventDispatcherInterface */
$dispatcher = $this->get('event_dispatcher');
$csrf = $this->get('security.csrf.token_manager');
$token = $csrf->getToken('ojs_journal_article' . $article->getId());
if ($token != $request->get('_token')) {
throw new TokenNotFoundException("Token Not Found!");
}
$event = new JournalItemEvent($article);
$dispatcher->dispatch(ArticleEvents::PRE_DELETE, $event);
/** @var Article $article */
$article = $event->getItem();
$article->getCitations()->clear();
$article->getLanguages()->clear();
$this->get('ojs_core.delete.service')->check($event->getItem());
$em->remove($event->getItem());
$em->flush();
$this->successFlashBag('successful.remove');
$event = new JournalEvent($journal);
$dispatcher->dispatch(ArticleEvents::POST_DELETE, $event);
if ($event->getResponse()) {
return $event->getResponse();
}
return $this->redirectToRoute('ojs_journal_article_index', ['journalId' => $journal->getId()]);
}