/** * @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); }