/**
* Imports the given article.
* @param int $id Article's ID
* @param int $newJournalId New journal's ID
* @param array|int $issueIds IDs of issues
* @param array|int $sectionIds IDs of sections
* @return Article
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\ORM\ORMException
*/
public function importArticle($id, $newJournalId, $issueIds, $sectionIds)
{
/** @var Journal $journal */
$journal = $this->em->getReference('OjsJournalBundle:Journal', $newJournalId);
$this->consoleOutput->writeln("Reading article #" . $id . "... ", true);
$articleSql = "SELECT articles.*, published_articles.issue_id, published_articles.seq, published_articles.date_published FROM articles " . " LEFT JOIN published_articles ON published_articles.article_id = articles.article_id WHERE" . " articles.article_id = :id";
$articleStatement = $this->dbalConnection->prepare($articleSql);
$articleStatement->bindValue('id', $id);
$articleStatement->execute();
$settingsSql = "SELECT locale, setting_name, setting_value FROM article_settings WHERE article_id = :id";
$settingsStatement = $this->dbalConnection->prepare($settingsSql);
$settingsStatement->bindValue('id', $id);
$settingsStatement->execute();
$pkpArticle = $articleStatement->fetch();
$pkpSettings = $settingsStatement->fetchAll();
$settings = array();
foreach ($pkpSettings as $setting) {
$locale = !empty($setting['locale']) ? $setting['locale'] : 'none';
$name = $setting['setting_name'];
$value = $setting['setting_value'];
$settings[$locale][$name] = $value;
}
$article = new Article();
$article->setJournal($journal);
$article->setCurrentLocale(!empty($pkpArticle['language']) ? $pkpArticle['language'] : 'en');
$article->setPrimaryLanguage(!empty($pkpArticle['language']) ? mb_substr($pkpArticle['language'], 0, 2, 'UTF-8') : 'en');
$article->setDoi(!empty($settings['none']['pub-id::doi']) ? $settings['none']['pub-id::doi'] : null);
foreach ($settings as $fieldLocale => $fields) {
$subject = !empty($fields['subject']) ? mb_substr($fields['subject'], 0, 254, 'UTF-8') : '-';
$article->setCurrentLocale(mb_substr($fieldLocale, 0, 2, 'UTF-8'));
$article->setTitle(!empty($fields['title']) ? $fields['title'] : '-');
$article->setAbstract(!empty($fields['abstract']) ? $fields['abstract'] : '-');
$article->setKeywords($subject);
$article->setTags($subject);
}
switch ($pkpArticle['status']) {
case 0:
// STATUS_ARCHIVED
$article->setStatus(ArticleStatuses::STATUS_REJECTED);
break;
case 1:
// STATUS_QUEUED
$article->setStatus($this->determineStatus($id));
break;
case 3:
// STATUS_PUBLISHED
$article->setStatus(ArticleStatuses::STATUS_PUBLISHED);
break;
case 4:
// STATUS_DECLINED
$article->setStatus(ArticleStatuses::STATUS_REJECTED);
break;
case 5:
// STATUS_QUEUED_UNASSIGNED
$article->setStatus(ArticleStatuses::STATUS_INREVIEW);
break;
case 6:
// STATUS_QUEUED_REVIEW
$article->setStatus(ArticleStatuses::STATUS_INREVIEW);
break;
case 7:
// STATUS_QUEUED_EDITING
$article->setStatus(ArticleStatuses::STATUS_PUBLISH_READY);
break;
case 8:
// STATUS_INCOMPLETE
$article->setStatus(ArticleStatuses::STATUS_NOT_SUBMITTED);
break;
}
if (!empty($issueIds)) {
if (!is_array($issueIds)) {
/** @var Issue $issue */
$issue = $this->em->getReference('OjsJournalBundle:Issue', $issueIds);
$article->setIssue($issue);
} else {
if (!empty($pkpArticle['issue_id']) && isset($issueIds[$pkpArticle['issue_id']])) {
/** @var Issue $issue */
$issue = $this->em->getReference('OjsJournalBundle:Issue', $issueIds[$pkpArticle['issue_id']]);
$article->setIssue($issue);
}
}
}
if (!empty($sectionIds)) {
if (!is_array($sectionIds)) {
/** @var Section $section */
$section = $this->em->getReference('OjsJournalBundle:Section', $sectionIds);
$article->setSection($section);
} else {
if (!empty($pkpArticle['section_id']) && isset($sectionIds[$pkpArticle['section_id']])) {
/** @var Section $section */
$section = $this->em->getReference('OjsJournalBundle:Section', $sectionIds[$pkpArticle['section_id']]);
$article->setSection($section);
}
}
}
$article->setSubmissionDate(!empty($pkpArticle['date_submitted']) ? DateTime::createFromFormat('Y-m-d H:i:s', $pkpArticle['date_submitted']) : new DateTime());
$article->setPubdate(!empty($pkpArticle['date_published']) ? DateTime::createFromFormat('Y-m-d H:i:s', $pkpArticle['date_published']) : null);
if (isset($pkpArticle['pages'])) {
$pages = explode('-', $pkpArticle['pages']);
isset($pages[0]) && $article->setFirstPage((int) $pages[0] == 0 && !empty($pages[0]) ? (int) StringHelper::roman2int($pages[0]) : (int) $pages[0]);
isset($pages[1]) && $article->setLastPage((int) $pages[1] == 0 && !empty($pages[1]) ? (int) StringHelper::roman2int($pages[1]) : (int) $pages[1]);
}
if (!empty($pkpArticle['seq'])) {
$article->setOrderNum(intval($pkpArticle['seq']));
}
$this->em->persist($article);
$this->importCitations($id, $article);
$this->importAuthors($id, $article);
$articleFileImporter = new ArticleFileImporter($this->dbalConnection, $this->em, $this->logger, $this->consoleOutput);
$articleFileImporter->importArticleFiles($article, $id, $journal->getSlug());
$supFileImporter = new SupFileImporter($this->dbalConnection, $this->em, $this->logger, $this->consoleOutput);
$supFileImporter->importSupFiles($article, $id, $journal->getSlug());
$pendingStatImport = new PendingStatisticImport($article, $id);
$pendingSubmitterImport = new PendingSubmitterImport($article, $pkpArticle['user_id']);
$this->em->persist($pendingStatImport);
$this->em->persist($pendingSubmitterImport);
return $article;
}