Skip to content

Commit

Permalink
pkp/pkp-lib#10027 Convert handle404 to exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Jan 7, 2025
1 parent 7dcc35c commit acded54
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
20 changes: 10 additions & 10 deletions pages/catalog/CatalogBookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function book($args, $request)

// Serve 404 if no submission available OR submission is unpublished and no user is logged in OR submission is unpublished and we have a user logged in but the user does not have access to preview
if (!$submission || ($submission->getData('status') !== PKPSubmission::STATUS_PUBLISHED && !$user) || ($submission->getData('status') !== PKPSubmission::STATUS_PUBLISHED && $user && !Repo::submission()->canPreview($user, $submission))) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

// Get the requested publication or default to the current publication
Expand All @@ -120,7 +120,7 @@ public function book($args, $request)
}

if (!$this->publication || ($this->publication->getData('status') !== PKPSubmission::STATUS_PUBLISHED && !Repo::submission()->canPreview($user, $submission))) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

// If the publication has been reached through an outdated
Expand All @@ -143,7 +143,7 @@ public function book($args, $request)

if ($this->isChapterRequest) {
if (!$this->chapter->isPageEnabled()) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$chapterAuthors = $this->chapter->getAuthors();
$chapterAuthors = $chapterAuthors->toArray();
Expand Down Expand Up @@ -360,7 +360,7 @@ public function download($args, $request, $view = false)

$publicationFormat = Application::get()->getRepresentationDAO()->getByBestId($representationId, $publicationId);
if (!$publicationFormat || !$publicationFormat->getIsAvailable() || $publicationFormat->getData('urlRemote')) {
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

$publication = null;
Expand All @@ -374,7 +374,7 @@ public function download($args, $request, $view = false)
if (empty($publication)
|| $publication->getData('status') !== PKPSubmission::STATUS_PUBLISHED
|| $publicationFormat->getData('publicationId') !== $publication->getId()) {
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

$submissionFile = Repo::submissionFile()
Expand All @@ -384,25 +384,25 @@ public function download($args, $request, $view = false)
$submission->getId()
);
if (!$submissionFile) {
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

$path = $submissionFile->getData('path');
$filename = app()->get('file')->formatFilename($path, $submissionFile->getLocalizedData('name'));
switch ($submissionFile->getData('assocType')) {
case Application::ASSOC_TYPE_PUBLICATION_FORMAT: // Publication format file
if ($submissionFile->getData('assocId') != $publicationFormat->getId() || $submissionFile->getDirectSalesPrice() === null) {
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
break;
case Application::ASSOC_TYPE_SUBMISSION_FILE: // Dependent file
$genreDao = DAORegistry::getDAO('GenreDAO'); /** @var GenreDAO $genreDao */
$genre = $genreDao->getById($submissionFile->getGenreId());
if (!$genre->getDependent()) {
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
return app()->get('file')->download($submissionFile->getData('fileId'), $filename);
default: $dispatcher->handle404();
default: throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

$urlPath = [$submission->getBestId()];
Expand Down Expand Up @@ -534,7 +534,7 @@ protected function setChapter(int $chapterId, PKPRequest $request): void
}

if (null === $this->chapter) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pages/catalog/CatalogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function page($args, $request, $isFirstPage = false)
}

if (!$isFirstPage && (empty($page) || $page < 2)) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

$templateMgr = TemplateManager::getManager($request);
Expand Down
2 changes: 1 addition & 1 deletion pages/gateway/GatewayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($request)
$pluginName = array_shift($args);
$plugins = PluginRegistry::loadCategory('gateways');
if (!isset($plugins[$pluginName])) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$this->plugin = $plugins[$pluginName];
foreach ($this->plugin->getPolicies($request) as $policy) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/importexport/native/NativeImportExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function display($args, $request)
switch ($this->opType) {
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
}

Expand Down
6 changes: 2 additions & 4 deletions plugins/importexport/onix30/Onix30ExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,12 @@ public function display($args, $request)
$downloadSuccess = $this->downloadExportedFile($exportedFileContentNamePart, $exportedFileDatePart, $this->getDeployment());

if (!$downloadSuccess) {
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

break;
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
}

Expand Down

0 comments on commit acded54

Please sign in to comment.