public function testDelete() { $em = $this->em; $article = $em->getRepository('OjsJournalBundle:Article')->find('1'); $entity = new ArticleFile(); $entity->setTitle('Article File Delete'); $entity->setArticle($article); $entity->setDescription('Description - phpunit'); $em->persist($entity); $em->flush(); $id = $entity->getId(); $this->logIn(); $client = $this->client; $token = $this->generateToken('ojs_journal_article_file' . $id); $client->request('DELETE', '/journal/1/article/1/file/' . $id . '/delete', array('_token' => $token)); $this->assertStatusCode(302, $client); }
/** * Imports the given article file * @param int $pkpArticleFile ID of the old article file * @param int $oldArticleId ID of the old article * @param Article $article Newly imported Article entity * @param string $slug Journal's slug */ public function importArticleFile($pkpArticleFile, $oldArticleId, $article, $slug) { $this->consoleOutput->writeln("Reading article file #" . $pkpArticleFile['file_id'] . "... ", true); $galleysSql = "SELECT galley_id, article_id, locale, label FROM article_galleys " . "WHERE article_id = :article_id AND file_id = :id"; $galleysStatement = $this->dbalConnection->prepare($galleysSql); $galleysStatement->bindValue('article_id', $oldArticleId); $galleysStatement->bindValue('id', $pkpArticleFile['file_id']); $galleysStatement->execute(); $pkpGalleys = $galleysStatement->fetchAll(); foreach ($pkpGalleys as $galley) { $locale = !empty($galley['locale']) ? mb_substr($galley['locale'], 0, 2, 'UTF-8') : 'en'; $label = !empty($galley['label']) ? $galley['label'] : '-'; $version = !empty($pkpArticleFile['revision']) ? $pkpArticleFile['revision'] : 0; $filename = sprintf('imported/%s/%s.%s', $galley['article_id'], $galley['galley_id'], FileHelper::$mimeToExtMap[$pkpArticleFile['file_type']]); $articleFile = new ArticleFile(); $articleFile->setFile($filename); $articleFile->setArticle($article); $articleFile->setVersion($version); $articleFile->setTitle($label); $articleFile->setLangCode($locale); $articleFile->setDescription('-'); $articleFile->setType(ArticleFileParams::FULL_TEXT); $history = $this->em->getRepository(FileHistory::class)->findOneBy(['fileName' => $filename]); if (!$history) { $history = new FileHistory(); $history->setFileName($filename); $history->setOriginalName($pkpArticleFile['original_file_name']); $history->setType('articlefiles'); $this->em->persist($history); } $source = sprintf('%s/article/download/%s/%s', $slug, $galley['article_id'], $galley['galley_id']); $target = sprintf('/../web/uploads/articlefiles/imported/%s/%s.%s', $galley['article_id'], $galley['galley_id'], FileHelper::$mimeToExtMap[$pkpArticleFile['file_type']]); $pendingDownload = new PendingDownload(); $pendingDownload->setSource($source); $pendingDownload->setTarget($target); $this->em->persist($pendingDownload); $this->em->persist($articleFile); } }
/** * @param Article $article New article entity * @param array $row Supp file row from the source database * @param integer $oldArticleId Old ID of the article * @param string $oldJournalSlug Slug of the article's journal */ public function importSupFile(Article $article, $row, $oldArticleId, $oldJournalSlug) { $settings = $this->getSettings($row["supp_id"]); if (empty($settings)) { return; } $accessor = PropertyAccess::createPropertyAccessor(); $code = $article->getJournal()->getMandatoryLang()->getCode(); $settings = empty($settings[$code]) ? current($settings) : $settings[$code]; $fileFormat = "imported/supplementary/%s/%s.%s"; $extension = !empty($row["file_type"]) ? $accessor->getValue(FileHelper::$mimeToExtMap, "[" . $row["file_type"] . "]") : ""; $filename = sprintf($fileFormat, $oldArticleId, $row["file_id"], $extension); $keywords = mb_substr($accessor->getValue($settings, "[subject]"), 0, 255); $file = new ArticleFile(); $file->setVersion(0); $file->setLangCode($code); $file->setFile($filename); $file->setArticle($article); $file->setKeywords($keywords); $file->setType(ArticleFileParams::SUPPLEMENTARY_FILE); $file->setTitle($accessor->getValue($settings, "[title]")); $file->setDescription($accessor->getValue($settings, "[description]")); $history = $this->em->getRepository(FileHistory::class)->findOneBy(["fileName" => $filename]); if (!$history) { $history = new FileHistory(); $history->setFileName($filename); $history->setType("articlefiles"); $history->setOriginalName($row["original_file_name"]); $this->em->persist($history); } $source = sprintf("%s/article/downloadSuppFile/%s/%s", $oldJournalSlug, $oldArticleId, $row["supp_id"]); $target = sprintf("/../web/uploads/articlefiles/%s", $filename); $download = new PendingDownload(); $download->setSource($source); $download->setTarget($target); $this->em->persist($file); $this->em->persist($download); }
/** * Displays a form to create a new ArticleFile entity. * @param integer $articleId * @return Response */ public function newAction($articleId) { $journalService = $this->get('ojs.journal_service'); $journal = $journalService->getSelectedJournal(); $em = $this->getDoctrine()->getManager(); if (!$this->isGranted('EDIT', $journal, 'articles')) { throw new AccessDeniedException("You not authorized for this page!"); } /** @var Article $article */ $article = $em->getRepository('OjsJournalBundle:Article')->find($articleId); $entity = new ArticleFile(); $entity->setArticle($article); $form = $this->createCreateForm($entity, $journal, $article)->add('create', 'submit', ['label' => 'c']); return $this->render('OjsJournalBundle:ArticleFile:new.html.twig', ['entity' => $entity, 'form' => $form->createView(), 'article' => $article]); }
/** * Displays a form to create a new ArticleFile entity. * * @param Article $article * @return Response */ public function newAction(Article $article) { $journalService = $this->get('ojs.journal_service'); $journal = $journalService->getSelectedJournal(); if (!$this->isGranted('EDIT', $journal, 'articles')) { throw new AccessDeniedException("You not authorized for this page!"); } $entity = new ArticleFile(); $entity->setArticle($article); $form = $this->createCreateForm($entity, $journal, $article, $journalService->getJournalLocales())->add('create', 'submit', array('label' => 'c')); return $this->render('OjsJournalBundle:ArticleFile:new.html.twig', array('entity' => $entity, 'form' => $form->createView(), 'article' => $article)); }
/** * Edits an existing Article entity. * * @param Request $request * @param int $id * @return RedirectResponse|Response */ public function updateAction(Request $request, $id) { $journal = $this->get('ojs.journal_service')->getSelectedJournal(); /** @var Article $entity */ $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('OjsJournalBundle:Article')->findOneBy(array('journal' => $journal, 'id' => $id)); $this->throw404IfNotFound($entity); if (!$this->isGranted('EDIT', $entity->getJournal(), 'articles')) { throw new AccessDeniedException("You not authorized for this page!"); } $editForm = $this->createEditForm($entity, $journal); $editForm->handleRequest($request); if ($editForm->isValid()) { $header = $request->request->get('header'); if ($header) { $entity->setHeaderOptions(json_encode($header)); } $files = $request->request->get('articlefiles', []); $fileHelper = new FileHelper(); foreach ($files as $file) { $file_entity = new File(); $file_entity->setName($file); $imagepath = $this->get('kernel')->getRootDir() . '/../web/uploads/articlefiles/' . $fileHelper->generatePath($file, false); $file_entity->setSize(filesize($imagepath . $file)); $file_entity->setMimeType(mime_content_type($imagepath . $file)); $file_entity->setPath('/uploads/articlefiles/' . $fileHelper->generatePath($file, false)); $em->persist($file_entity); $articleFile = new ArticleFile(); $articleFile->setArticle($entity); $articleFile->setFile($file_entity); $articleFile->setType(0); // TODO: See ArticleFileParams::$FILE_TYPES $articleFile->setVersion(1); $articleFile->setLangCode('tr'); // TODO: Don't use hardcoded locale $em->persist($articleFile); $entity->addArticleFile($articleFile); } $em->flush(); $this->successFlashBag('successful.update'); return $this->redirect($this->generateUrl('ojs_journal_article_edit', array('id' => $id, 'journalId' => $journal->getId()))); } return $this->render('OjsJournalBundle:Article:edit.html.twig', ['entity' => $entity, 'edit_form' => $editForm->createView()]); }