コード例 #1
0
 /**
  * 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);
     }
 }
コード例 #2
0
 /**
  * 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);
     }
 }
コード例 #3
0
 /**
  * @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);
 }
コード例 #4
0
 /**
  * @param  int $id Issue's ID
  * @param  int $newJournalId new Journal's ID
  * @param  array $sectionIds Journal's section IDs
  * @return Issue Created issue
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Doctrine\ORM\ORMException
  */
 public function importIssue($id, $newJournalId, $sectionIds)
 {
     /** @var Journal $journal */
     $journal = $this->em->getReference('OjsJournalBundle:Journal', $newJournalId);
     $this->consoleOutput->writeln("Reading issue #" . $id . "... ", true);
     $issueSql = "SELECT * FROM issues WHERE issue_id = :id LIMIT 1";
     $issueStatement = $this->dbalConnection->prepare($issueSql);
     $issueStatement->bindValue('id', $id);
     $issueStatement->execute();
     $settingsSql = "SELECT locale, setting_name, setting_value FROM issue_settings WHERE issue_id = :id";
     $settingsStatement = $this->dbalConnection->prepare($settingsSql);
     $settingsStatement->bindValue('id', $id);
     $settingsStatement->execute();
     $pkpIssue = $issueStatement->fetch();
     $pkpSettings = $settingsStatement->fetchAll();
     $settings = [];
     foreach ($pkpSettings as $setting) {
         $locale = !empty($setting['locale']) ? $setting['locale'] : 'en_US';
         $name = $setting['setting_name'];
         $value = $setting['setting_value'];
         $settings[$locale][$name] = $value;
     }
     $issue = new Issue();
     $issue->setJournal($journal);
     $issue->setVolume(is_numeric($pkpIssue['volume']) ? $pkpIssue['volume'] : '');
     $issue->setNumber($pkpIssue['number']);
     $issue->setYear(DateTime::createFromFormat('Y-m-d H:i:s', $pkpIssue['year'] . '-01-01 00:00:00'));
     $issue->setPublished($pkpIssue['published']);
     $issue->setSpecial(false);
     foreach (array_values($sectionIds) as $sectionId) {
         if ($sectionId !== null) {
             /** @var Section $section */
             $section = $this->em->getReference('OjsJournalBundle:Section', $sectionId);
             $issue->addSection($section);
         }
     }
     // In some instances, imported data is not in a proper date format so DateTime::createFromFormat returns false
     // This part handles cases where data_published column is empty or when the data is in a bad format
     $date = false;
     if (!empty($pkpIssue['date_published'])) {
         // This might assign 'false' to the variable
         $date = DateTime::createFromFormat('Y-m-d H:i:s', $pkpIssue['date_published']);
     }
     // Current date & time is used when date is false
     $issue->setDatePublished($date ? $date : new DateTime());
     $cover = null;
     foreach ($settings as $fieldLocale => $fields) {
         if (!$cover && !empty($fields['fileName'])) {
             $cover = $fields['fileName'];
         }
         $issue->setCurrentLocale(mb_substr($fieldLocale, 0, 2, 'UTF-8'));
         $issue->setTitle(!empty($fields['title']) ? $fields['title'] : '-');
         $issue->setDescription(!empty($fields['description']) ? $fields['description'] : '-');
     }
     if ($cover) {
         $baseDir = '/../web/uploads/journal/imported/';
         $croppedBaseDir = '/../web/uploads/journal/croped/imported/';
         $coverPath = $pkpIssue['journal_id'] . '/' . $cover;
         $pendingDownload = new PendingDownload();
         $pendingDownload->setSource('public/journals/' . $coverPath)->setTarget($baseDir . $coverPath)->setTag('issue-cover');
         $croppedPendingDownload = new PendingDownload();
         $croppedPendingDownload->setSource('public/journals/' . $coverPath)->setTarget($croppedBaseDir . $coverPath)->setTag('issue-cover');
         $history = $this->em->getRepository(FileHistory::class)->findOneBy(['fileName' => 'imported/' . $coverPath]);
         if (!$history) {
             $history = new FileHistory();
             $history->setFileName('imported/' . $coverPath);
             $history->setOriginalName('imported/' . $coverPath);
             $history->setType('journal');
             $this->em->persist($history);
         }
         $this->em->persist($croppedPendingDownload);
         $this->em->persist($pendingDownload);
         $issue->setCover('imported/' . $coverPath);
     }
     $importer = new IssueFileImporter($this->dbalConnection, $this->em, $this->logger, $this->consoleOutput);
     $importer->importIssueFiles($issue, $id, $journal->getSlug());
     $this->em->persist($issue);
     return $issue;
 }
コード例 #5
0
 /**
  * Imports the journal with given ID
  * @param  int $id Journal's ID
  * @return array New IDs as keys, old IDs as values
  * @throws Exception
  * @throws \Doctrine\DBAL\DBALException
  */
 public function importJournal($id)
 {
     $this->consoleOutput->writeln("Importing the journal...");
     $journalSql = "SELECT path, primary_locale FROM journals WHERE journal_id = :id LIMIT 1";
     $journalStatement = $this->dbalConnection->prepare($journalSql);
     $journalStatement->bindValue('id', $id);
     $journalStatement->execute();
     $settingsSql = "SELECT locale, setting_name, setting_value FROM journal_settings WHERE journal_id = :id";
     $settingsStatement = $this->dbalConnection->prepare($settingsSql);
     $settingsStatement->bindValue('id', $id);
     $settingsStatement->execute();
     $pkpJournal = $journalStatement->fetch();
     $pkpSettings = $settingsStatement->fetchAll();
     $primaryLocale = $pkpJournal['primary_locale'];
     $languageCode = mb_substr($primaryLocale, 0, 2, 'UTF-8');
     !$pkpJournal && die('Journal not found.' . PHP_EOL);
     $this->consoleOutput->writeln("Reading journal settings...");
     foreach ($pkpSettings as $setting) {
         $locale = !empty($setting['locale']) ? mb_substr($setting['locale'], 0, 2, 'UTF-8') : $languageCode;
         $name = $setting['setting_name'];
         $value = $setting['setting_value'];
         $this->settings[$locale][$name] = $value;
     }
     $this->journal = new Journal();
     $this->journal->setStatus(1);
     $this->journal->setSlug($pkpJournal['path']);
     // Fill translatable fields in all available languages except the primary one
     foreach ($this->settings as $fieldLocale => $fields) {
         if ($fieldLocale === $languageCode) {
             // We will fill fields of the primary language later.
             continue;
         }
         $this->journal->setCurrentLocale(mb_substr($fieldLocale, 0, 2, 'UTF-8'));
         !empty($fields['title']) ? $this->journal->setTitle($fields['title']) : $this->journal->setTitle('Unknown Journal');
         !empty($fields['description']) ? $this->journal->setDescription($fields['description']) : $this->journal->setDescription('-');
     }
     $this->journal->setCurrentLocale($languageCode);
     // Fill fields for the primary language
     !empty($this->settings[$languageCode]['title']) ? $this->journal->setTitle($this->settings[$languageCode]['title']) : $this->journal->setTitle('Unknown Journal');
     !empty($this->settings[$languageCode]['description']) ? $this->journal->setDescription($this->settings[$languageCode]['description']) : $this->journal->setDescription('-');
     !empty($this->settings[$languageCode]['journalPageFooter']) ? $this->journal->setFooterText($this->settings[$languageCode]['journalPageFooter']) : $this->journal->setFooterText(null);
     !empty($this->settings[$languageCode]['printIssn']) && count($this->settings[$languageCode]['printIssn']) == 9 ? $this->journal->setIssn($this->settings[$languageCode]['printIssn']) : $this->journal->setIssn('');
     !empty($this->settings[$languageCode]['onlineIssn']) && count($this->settings[$languageCode]['onlineIssn']) == 9 ? $this->journal->setEissn($this->settings[$languageCode]['onlineIssn']) : $this->journal->setEissn('');
     $date = sprintf('%d-01-01 00:00:00', !empty($this->settings[$languageCode]['initialYear']) ? $this->settings[$languageCode]['initialYear'] : '2015');
     $this->journal->setFounded(DateTime::createFromFormat('Y-m-d H:i:s', $date));
     // Set view and download counts
     !empty($this->settings[$languageCode]['total_views']) ? $this->journal->setViewCount($this->settings[$languageCode]['total_views']) : $this->journal->setViewCount(0);
     !empty($this->settings[$languageCode]['total_downloads']) ? $this->journal->setDownloadCount($this->settings[$languageCode]['total_downloads']) : $this->journal->setDownloadCount(0);
     !empty($this->settings[$languageCode]['homeHeaderTitleImage']) ? $header = unserialize($this->settings[$languageCode]['homeHeaderTitleImage']) : ($header = null);
     if ($header) {
         $baseDir = '/../web/uploads/journal/imported/';
         $croppedBaseDir = '/../web/uploads/journal/croped/imported/';
         $headerPath = $id . '/' . $header['uploadName'];
         $pendingDownload = new PendingDownload();
         $pendingDownload->setSource('public/journals/' . $headerPath)->setTarget($baseDir . $headerPath)->setTag('journal-header');
         $croppedPendingDownload = new PendingDownload();
         $croppedPendingDownload->setSource('public/journals/' . $headerPath)->setTarget($croppedBaseDir . $headerPath)->setTag('journal-header');
         $history = $this->em->getRepository(FileHistory::class)->findOneBy(['fileName' => 'imported/' . $headerPath]);
         if (!$history) {
             $history = new FileHistory();
             $history->setFileName('imported/' . $headerPath);
             $history->setOriginalName('imported/' . $headerPath);
             $history->setType('journal');
         }
         $this->em->persist($croppedPendingDownload);
         $this->em->persist($pendingDownload);
         $this->em->persist($history);
         $this->journal->setHeader('imported/' . $headerPath);
     }
     $subjects = $this->importSubjects($languageCode);
     foreach ($subjects as $subject) {
         $this->journal->addSubject($subject);
     }
     // Set publisher
     !empty($this->settings[$languageCode]['publisherInstitution']) ? $this->importAndSetPublisher($this->settings[$languageCode]['publisherInstitution'], $languageCode) : $this->journal->setPublisher($this->getUnknownPublisher($languageCode));
     // Use existing languages or create if needed
     $language = $this->em->getRepository('OjsJournalBundle:Lang')->findOneBy(['code' => $languageCode]);
     $this->journal->setMandatoryLang($language ? $language : $this->createLanguage($languageCode));
     $this->journal->addLanguage($language ? $language : $this->createLanguage($languageCode));
     $this->importContacts($languageCode);
     $this->importSubmissionChecklist($languageCode);
     $this->consoleOutput->writeln("Read journal's settings.");
     $this->em->beginTransaction();
     // Outer transaction
     try {
         $this->em->beginTransaction();
         // Inner transaction
         $this->em->persist($this->journal);
         $this->em->flush();
         $this->em->commit();
     } catch (Exception $exception) {
         $this->em->rollback();
         throw $exception;
     }
     $this->consoleOutput->writeln("Imported journal #" . $id);
     // Those below also create their own inner transactions
     $createdSections = $this->sectionImporter->importJournalSections($id, $this->journal->getId());
     $createdIssues = $this->issueImporter->importJournalIssues($id, $this->journal->getId(), $createdSections);
     $this->articleImporter->importJournalArticles($id, $this->journal->getId(), $createdIssues, $createdSections);
     $this->journalPageImporter->importPages($id, $this->journal->getId());
     $createdBoards = $this->boardImporter->importBoards($id, $this->journal->getId());
     foreach ($createdBoards as $oldBoardId => $newBoardId) {
         $this->boardMemberImporter->importBoardMembers($oldBoardId, $newBoardId);
     }
     $this->importAboutPage();
     $map = new ImportMap($id, $this->journal->getId(), Journal::class);
     $this->em->persist($map);
     $this->em->flush();
     $this->em->commit();
     return ['new' => $this->journal->getId(), 'old' => $id];
 }