Skip to content

Commit

Permalink
Merge branch '3.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
marc1706 committed Feb 18, 2024
2 parents 99884d8 + eabe263 commit 6fe2012
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions phpBB/config/default/container/services_event.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
arguments:
- '@template'
- '@language'
- '@user'
- '%debug.exceptions%'
tags:
- { name: kernel.event_subscriber }
Expand Down
14 changes: 13 additions & 1 deletion phpBB/phpbb/event/kernel_exception_subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class kernel_exception_subscriber implements EventSubscriberInterface
*/
protected $language;

/**
* User object
*
* @var \phpbb\user
*/
protected $user;

/** @var \phpbb\request\type_cast_helper */
protected $type_caster;

Expand All @@ -52,13 +59,15 @@ class kernel_exception_subscriber implements EventSubscriberInterface
*
* @param \phpbb\template\template $template Template 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
*/
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->template = $template;
$this->language = $language;
$this->user = $user;
$this->type_caster = new \phpbb\request\type_cast_helper();
}

Expand All @@ -81,6 +90,9 @@ public function on_kernel_exception(ExceptionEvent $event)
}
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');
}

Expand Down
3 changes: 2 additions & 1 deletion tests/event/exception_listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ public function test_phpbb_exception($is_ajax, $exception, $expected)

$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$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\ExceptionEvent($this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, $exception);
$exception_listener->on_kernel_exception($event);
Expand Down
55 changes: 55 additions & 0 deletions tests/functional/session_page_update_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

/**
* @group functional
*/

class phpbb_functional_session_page_update_test extends phpbb_functional_test_case
{
protected function test_session_page_update()
{
$this->login();
$db = $this->get_db();

if (!function_exists('utf_clean_string'))
{
require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
}
if (!function_exists('user_get_id_name'))
{
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
}

$user_ids = [];
$username = [$this->get_logged_in_user()];
user_get_id_name($user_ids, $username);
$user_id = (int) $user_ids[0];

// Request index page
self::request('GET', 'index.php');
$this->assertEquals(200, self::$client->getResponse()->getStatus());

$sql = 'SELECT session_page FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . $user_id . ' ORDER BY session_time DESC';
$db->sql_query_limit($sql, 1);
$this->assertEquals('index.php', $db->sql_fetchfield('session_page'));

// Request non-existent url
self::request('GET', 'nonexistent.jpg');
$this->assertEquals(404, self::$client->getResponse()->getStatus());

$db->sql_query_limit($sql, 1);
// User page should not be updated to non-existent one
$this->assertEquals('index.php', $db->sql_fetchfield('session_page'));
}
}

0 comments on commit 6fe2012

Please sign in to comment.