Skip to content

Commit

Permalink
pkp/pkp-lib#10027 Move 404 handling to Symfony exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Jan 4, 2025
1 parent bbf17b0 commit 2bcb790
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 24 deletions.
3 changes: 1 addition & 2 deletions classes/plugins/PubObjectsExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ public function executeExportAction($request, $objects, $filter, $tab, $objectsF
$request->redirect(null, null, null, $path, null, $tab);
}
} else {
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
}

Expand Down
22 changes: 10 additions & 12 deletions pages/article/ArticleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function initialize($request, $args = [])

// 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();
}

// If the urlPath does not match the urlPath of the current
Expand All @@ -149,15 +149,15 @@ public function initialize($request, $args = [])
}
}
if (!$this->publication) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
} else {
$this->publication = $this->article->getCurrentPublication();
$galleyId = $subPath;
}

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

if ($galleyId && in_array($request->getRequestedOp(), ['view', 'download'])) {
Expand Down Expand Up @@ -185,7 +185,7 @@ public function initialize($request, $args = [])
}
}
}
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

// Store the file id if it exists
Expand Down Expand Up @@ -419,8 +419,7 @@ public function downloadSuppFile($args, $request)
$articleId = $args[0] ?? 0;
$article = Repo::submission()->get($articleId);
if (!$article) {
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$suppId = $args[1] ?? 0;

Expand All @@ -444,8 +443,7 @@ public function downloadSuppFile($args, $request)
}
}
}
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

/**
Expand All @@ -460,7 +458,7 @@ public function downloadSuppFile($args, $request)
public function download($args, $request)
{
if (!isset($this->galley)) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
if ($this->galley->getData('urlRemote')) {
$request->redirectUrl($this->galley->getData('urlRemote'));
Expand All @@ -471,7 +469,7 @@ public function download($args, $request)

// If no file ID could be determined, treat it as a 404.
if (!$this->submissionFileId) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

// If the file ID is not the galley's file ID, ensure it is a dependent file, or else 404.
Expand All @@ -488,15 +486,15 @@ public function download($args, $request)
->toArray();

if (!in_array($this->submissionFileId, $dependentFileIds)) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
}

if (!Hook::call('ArticleHandler::download', [$this->article, &$this->galley, &$this->submissionFileId])) {
$submissionFile = Repo::submissionFile()->get($this->submissionFileId);

if (!app()->get('file')->fs->has($submissionFile->getData('path'))) {
$request->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

$filename = app()->get('file')->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name'));
Expand Down
2 changes: 1 addition & 1 deletion pages/gateway/GatewayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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 pages/issue/IssueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function archive($args, $request)
$prevPage = $showingStart > 1 ? $page - 1 : null;

if (!count($issues) && $offset) {
$this->getDispatcher()->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

$templateMgr->assign([
Expand Down
3 changes: 1 addition & 2 deletions pages/oai/OAIHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function index($args, $request)

$oai = new JournalOAI(new OAIConfig($request->url(null, 'oai'), Config::getVar('oai', 'repository_id')));
if (!$request->getJournal() && $request->getRouter()->getRequestedContextPath($request) != Application::SITE_CONTEXT_PATH) {
$dispatcher = $request->getDispatcher();
return $dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$oai->execute();
}
Expand Down
2 changes: 1 addition & 1 deletion pages/payments/PaymentsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function subscriptions($args, $request)
)
);
}
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion pages/stats/StatsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function issues(array $args, Request $request): void
$context = $request->getContext();

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

$templateMgr = TemplateManager::getManager($request);
Expand Down
3 changes: 1 addition & 2 deletions plugins/importexport/native/NativeImportExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public function display($args, $request)

return $this->getExportTemplateResult($deployment, $templateMgr, 'issues');
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
}

Expand Down
3 changes: 1 addition & 2 deletions plugins/importexport/pubmed/PubMedExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public function display($args, $request)
$fileManager->deleteByPath($exportFileName);
break;
default:
$dispatcher = $request->getDispatcher();
$dispatcher->handle404();
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
}

Expand Down

0 comments on commit 2bcb790

Please sign in to comment.