Importer/PKP/ArticleFileImporter.php
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);
        }
    }
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);
        }
    }
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 ) ; } }
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
Imports the given article file