<commit_before><?php

namespace Ojs\SiteBundle\Controller;

use Ojs\JournalBundle\Entity\ArticleFile;
use Ojs\JournalBundle\Entity\IssueFile;
use Ojs\SiteBundle\Event\DownloadArticleFileEvent;
use Ojs\SiteBundle\Event\DownloadIssueFileEvent;
use Ojs\SiteBundle\Event\SiteEvents;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;

class DownloadController extends Controller
{
    public function articleFileAction(ArticleFile $articleFile)
    {
        $fileManager = $this->get('jb_fileuploader.file_history.manager');
        $rootDir = $this->getParameter('kernel.root_dir');
        $assetHelper = $this->get('templating.helper.assets');
        $fileHistory = $fileManager->findOneByFileName($articleFile->getFile());

        $path = $rootDir.'/../web'.$fileManager->getUrl($fileHistory);
        $path = preg_replace('/\?'.$assetHelper->getVersion().'$/', '', $path);
        $fileOriginalName = $fileHistory->getOriginalName();
        if(preg_match('/\//', $fileHistory->getOriginalName())){
            $explode = explode('/', $fileHistory->getOriginalName());
            $fileOriginalName = end($explode);
        }
        $response = new BinaryFileResponse($path);
        $response->setContentDisposition(
            ResponseHeaderBag::DISPOSITION_INLINE,
            preg_replace('/[[:^print:]]/', '_', $fileOriginalName)
        );

        $event = new DownloadArticleFileEvent($articleFile);
        $dispatcher = $this->get('event_dispatcher');
        $dispatcher->dispatch(SiteEvents::DOWNLOAD_ARTICLE_FILE, $event);

        return $response;
    }

    public function issueFileAction(IssueFile $issueFile)
    {
        $fileManager = $this->get('jb_fileuploader.file_history.manager');
        $rootDir = $this->getParameter('kernel.root_dir');<commit_msg>revise article file download original name with doi if exists, not use article title fixes #1488<commit_after><?php

namespace Ojs\SiteBundle\Controller;

use Ojs\JournalBundle\Entity\ArticleFile;
use Ojs\JournalBundle\Entity\IssueFile;
use Ojs\SiteBundle\Event\DownloadArticleFileEvent;
use Ojs\SiteBundle\Event\DownloadIssueFileEvent;
use Ojs\SiteBundle\Event\SiteEvents;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;

class DownloadController extends Controller
{
    public function articleFileAction(ArticleFile $articleFile)
    {
        $fileManager = $this->get('jb_fileuploader.file_history.manager');
        $rootDir = $this->getParameter('kernel.root_dir');
        $assetHelper = $this->get('templating.helper.assets');
        $fileHistory = $fileManager->findOneByFileName($articleFile->getFile());

        $path = $rootDir.'/../web'.$fileManager->getUrl($fileHistory);
        $path = preg_replace('/\?'.$assetHelper->getVersion().'$/', '', $path);

        $explode = explode('.', $fileHistory->getOriginalName());
        $mime = end($explode);
        if(!empty($articleFile->getArticle()->getDoi())){
            $fileOriginalName = $articleFile->getArticle()->getDoi().'-'.$articleFile->getId().'.'.$mime;
        }else{
            $fileOriginalName = $articleFile->getArticle().'-'.$articleFile->getId().'.'.$mime;
        }
        $response = new BinaryFileResponse($path);
        $response->setContentDisposition(
            ResponseHeaderBag::DISPOSITION_INLINE,
            preg_replace('/[[:^print:]]/', '_', $fileOriginalName)
        );

        $event = new DownloadArticleFileEvent($articleFile);
        $dispatcher = $this->get('event_dispatcher');
        $dispatcher->dispatch(SiteEvents::DOWNLOAD_ARTICLE_FILE, $event);

        return $response;
    }

    public function issueFileAction(IssueFile $issueFile)
    {
        $fileManager = $this->get('jb_fileuploader.file_history.manager');
        $rootDir = $this->getParameter('kernel.root_dir');
{'fraction_non_alphanumeric': 0.14715386527467064, 'fraction_numerical': 0.0009942828734775043, 'mean_word_length': 3.961775585696671, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136734', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1133, 'n_words': 162}