public function download($articleId, $fileName) { try { $articleRow = ArticleDao::findById($articleId); } catch (NoElementException $e) { App::abort(404, 'Article not found'); } $article = ArticleService::getEnrichedArticle($articleRow); $edition = EditionDao::findById($articleRow->journal_edition_id); $journal = JournalDao::findById($edition->journal_id); $original_filename = ArticleService::getFilePath($article, $journal, $edition); $new_filename = ArticleService::getArticleFileName($journal->prefix, $edition->issue_year, $edition->number_in_year, $article->sort_order); if ($fileName != $new_filename) { return redirect(route('article.download', [$articleId, $new_filename]), 301); } $headers = array("Content-Type: application/pdf"); return response()->download($original_filename, $new_filename, $headers); }
private function getArticleId($oaiId, $request) { $oaiPrefix = self::getCommonValues($request)['id_prefix']; if (!self::startsWith($oaiId, $oaiPrefix)) { throw new OaiError("Incorrect id prefix", self::ERROR_ID_DOES_NOT_EXIST); } $articleId = substr($oaiId, strlen($oaiPrefix)); if (!is_numeric($articleId)) { throw new OaiError("Id not numeric", self::ERROR_ID_DOES_NOT_EXIST); } try { ArticleDao::findById($articleId); } catch (NoElementException $e) { throw new OaiError("Id not found in db", self::ERROR_ID_DOES_NOT_EXIST); } return $articleId; }