From 0db1beaea6b849790aa0f1f4ecbf6439ce4f1104 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Thu, 22 Jul 2021 21:17:57 +0200 Subject: Catch possible PDOException for search request Catch possible PDOException on search requests with queries like "*" and pass the exception message to the template for displaying. --- admin/post/search.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'admin/post/search.php') diff --git a/admin/post/search.php b/admin/post/search.php index a270ccb..8cbfafb 100644 --- a/admin/post/search.php +++ b/admin/post/search.php @@ -30,9 +30,13 @@ $offset = ($currentSite-1) * $site_size; # Check for search request #=============================================================================== if($search = HTTP::GET('q')) { - foreach($PostRepository->search($search, [], $site_size, $offset) as $Post) { - $User = $UserRepository->find($Post->get('user')); - $templates[] = generatePostItemTemplate($Post, $User); + try { + foreach ($PostRepository->search($search, [], $site_size, $offset) as $Post) { + $User = $UserRepository->find($Post->get('user')); + $templates[] = generatePostItemTemplate($Post, $User); + } + } catch(PDOException $Exception) { + $messages[] = $Exception->getMessage(); } } @@ -57,6 +61,9 @@ if($count = $PostRepository->getLastSearchOverallCount()) { $SearchTemplate = Template\Factory::build('post/search'); $SearchTemplate->set('QUERY', $search); $SearchTemplate->set('POSTS', $templates ?? []); +$SearchTemplate->set('FORM', [ + 'INFO' => $messages ?? [] +]); $SearchTemplate->set('PAGINATION', $pagination_data ?? []); $MainTemplate = Template\Factory::build('main'); -- cgit v1.2.3