/**
  * Imports the given issue file
  * @param int    $id    Issue file's ID
  * @param int    $oldId Old issue file's ID
  * @param Issue  $issue File's issue
  * @param string $slug  Journal's slug
  */
 public function importIssueFile($id, $oldId, $issue, $slug)
 {
     $this->consoleOutput->writeln("Reading issue file #" . $id . "... ", true);
     $issueFileSql = "SELECT * FROM issue_files WHERE file_id = :id LIMIT 1";
     $issueFileStatement = $this->dbalConnection->prepare($issueFileSql);
     $issueFileStatement->bindValue('id', $id);
     $issueFileStatement->execute();
     $galleysSql = "SELECT galley_id, issue_id, locale, label FROM issue_galleys " . "WHERE issue_id = :issue_id AND file_id = :id";
     $galleysStatement = $this->dbalConnection->prepare($galleysSql);
     $galleysStatement->bindValue('issue_id', $oldId);
     $galleysStatement->bindValue('id', $id);
     $galleysStatement->execute();
     $pkpIssueFile = $issueFileStatement->fetch();
     $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'] : '-';
         $filename = sprintf('imported/%s/%s.%s', $galley['issue_id'], $galley['galley_id'], FileHelper::$mimeToExtMap[$pkpIssueFile['file_type']]);
         $issueFile = new IssueFile();
         $issueFile->setFile($filename);
         $issueFile->setIssue($issue);
         $issueFile->setVersion(0);
         $issueFile->setType(0);
         // Fill translatable fields
         $issueFile->setCurrentLocale($locale);
         $issueFile->setTitle($label);
         $issueFile->setDescription('-');
         $history = $this->em->getRepository(FileHistory::class)->findOneBy(['fileName' => $filename]);
         if (!$history) {
             $history = new FileHistory();
             $history->setFileName($filename);
             $history->setOriginalName($pkpIssueFile['original_file_name']);
             $history->setType('issuefiles');
             $this->em->persist($history);
         }
         $source = sprintf('%s/issue/download/%s/%s', $slug, $galley['issue_id'], $galley['galley_id']);
         $target = sprintf('/../web/uploads/issuefiles/imported/%s/%s.%s', $galley['issue_id'], $galley['galley_id'], FileHelper::$mimeToExtMap[$pkpIssueFile['file_type']]);
         $pendingDownload = new PendingDownload();
         $pendingDownload->setSource($source);
         $pendingDownload->setTarget($target);
         $this->em->persist($pendingDownload);
         $this->em->persist($issueFile);
     }
 }
 /**
  * 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);
 }