[ticket/17286] Do not update user session page if it does not exist

PHPBB3-17286
This commit is contained in:
rxu 2024-02-02 23:24:40 +07:00
parent 512a93727a
commit ec7180db4f
No known key found for this signature in database
GPG key ID: 955F0567380E586A
3 changed files with 16 additions and 2 deletions

View file

@ -9,6 +9,7 @@ services:
arguments: arguments:
- '@template' - '@template'
- '@language' - '@language'
- '@user'
- '%debug.exceptions%' - '%debug.exceptions%'
tags: tags:
- { name: kernel.event_subscriber } - { name: kernel.event_subscriber }

View file

@ -44,6 +44,13 @@ class kernel_exception_subscriber implements EventSubscriberInterface
*/ */
protected $language; protected $language;
/**
* User object
*
* @var \phpbb\user
*/
protected $user;
/** @var \phpbb\request\type_cast_helper */ /** @var \phpbb\request\type_cast_helper */
protected $type_caster; protected $type_caster;
@ -52,13 +59,15 @@ class kernel_exception_subscriber implements EventSubscriberInterface
* *
* @param \phpbb\template\template $template Template object * @param \phpbb\template\template $template Template object
* @param \phpbb\language\language $language Language object * @param \phpbb\language\language $language Language object
* @param \phpbb\User $user User object
* @param bool $debug Set to true to show full exception messages * @param bool $debug Set to true to show full exception messages
*/ */
public function __construct(\phpbb\template\template $template, \phpbb\language\language $language, $debug = false) public function __construct(\phpbb\template\template $template, \phpbb\language\language $language, \phpbb\user $user, $debug = false)
{ {
$this->debug = $debug || defined('DEBUG'); $this->debug = $debug || defined('DEBUG');
$this->template = $template; $this->template = $template;
$this->language = $language; $this->language = $language;
$this->user = $user;
$this->type_caster = new \phpbb\request\type_cast_helper(); $this->type_caster = new \phpbb\request\type_cast_helper();
} }
@ -81,6 +90,9 @@ class kernel_exception_subscriber implements EventSubscriberInterface
} }
else if (!$this->debug && $exception instanceof NotFoundHttpException) else if (!$this->debug && $exception instanceof NotFoundHttpException)
{ {
// Do not update user session page if it does not exist
$this->user->update_session_page = false;
$message = $this->language->lang('PAGE_NOT_FOUND'); $message = $this->language->lang('PAGE_NOT_FOUND');
} }

View file

@ -81,8 +81,9 @@ class exception_listener extends phpbb_test_case
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader); $lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
$exception_listener = new \phpbb\event\kernel_exception_subscriber($template, $lang); $exception_listener = new \phpbb\event\kernel_exception_subscriber($template, $lang, $user);
$event = new \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent($this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, $exception); $event = new \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent($this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, $exception);
$exception_listener->on_kernel_exception($event); $exception_listener->on_kernel_exception($event);