Users variables integration to Symfony

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
EternalArcadia
Registered User
Posts: 5
Joined: Sat Aug 05, 2017 8:18 pm

Users variables integration to Symfony

Post by EternalArcadia »

Hello,

We have a website https://shycomics.fr/ associated with a PhpBB3.3 forum.
This website gets user variable with the classic code and allows to know if a user is connected or not :

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : $pathPhpBB;
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$request->enable_super_globals();
No problem here, it's working fine.

But we'd like to migrate the site on Symfony 5. Of course, this kind of code can't work anymore because it conflits with Symfony variables.
So I check directly on phpbb\session.php forum side to see how sessions work. I use the the session_begin function to help me, it's something like that I wrote on my website :

Code: Select all

if($request->cookies->get('phpbb3_shyco_sid') !== null or $request->cookies->get('phpbb3_shyco_u') !== null)
{
	$this->cookie_data['u'] = $request->cookies->get('phpbb3_shyco_u');
	$this->cookie_data['k'] = $request->cookies->get('phpbb3_shyco_k');
	$this->session_id = $request->cookies->get('phpbb3_shyco_sid');
	
	if (!empty($this->session_id))
	{
		$userPhpbb = $this->phpbbUserRepository->getPhpbbUser($this->session_id);
		
		...
And the getPhpbbUser is the equivalent of the SQL code from phpbb\session.php :

Code: Select all

$sql = 'SELECT u.*, s.*
FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u
WHERE s.session_id = '" . $db->sql_escape($this->session_id) . "'
AND u.user_id = s.session_user_id";
And it works, I manage to get my user object and do what I want to do. But it works temporarily. Indeed if we don't go back to the forum after a long time, I notice that the SESSIONS_TABLE drops the user_id so the SQL above doesn't return anything. We have to go back to the forum to generate a new user_id on SESSIONS_TABLE and go on.

It seems that this behavior is done here on phpbb\session.php, on session_create function :

Code: Select all

$sql_ary['session_id'] = (string) $this->session_id;
$sql_ary['session_page'] = (string) substr($this->page['page'], 0, 199);
$sql_ary['session_forum_id'] = $this->page['forum'];

$sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
But I really don't know how to incorporate that on the website side. I wonder if there is not a better solution than to recopy all phpbb function to manage the session from website side...

Thanks
Last edited by HiFiKabin on Sat Nov 07, 2020 1:28 pm, edited 1 time in total.
Reason: Moved to Custom Coding
rxu
Extensions Development Team
Posts: 3456
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Users variables integration to Symfony

Post by rxu »

EternalArcadia wrote:
Sat Nov 07, 2020 1:23 pm
this kind of code can't work anymore because it conflits with Symfony variables.
Depending on what particular variables conflict in what places. user and some more objects are actually services in phpBB 3.3 which can be got from the service container, so you should be able to do something like

Code: Select all

$my_renamed_user_object = $phpbb_container->get('user');
$my_renamed_user_object->session_begin();
and so on.

There was also a discussion related to that matter I recall viewtopic.php?p=14131621#p14131621
EternalArcadia
Registered User
Posts: 5
Joined: Sat Aug 05, 2017 8:18 pm

Re: Users variables integration to Symfony

Post by EternalArcadia »

Thank you for your reply.

Ok so I'm trying to build my own common.php step by step but when I write the last line to build the $phpbb_container :

Code: Select all

$phpbb_container = $phpbb_container_builder->get_container();
It fails :

Code: Select all

Compile Error: Declaration of ContainerLRgDC7H\App_KernelDevDebugContainer::getParameter(string $name)
must be compatible with Symfony\Component\DependencyInjection\Container::getParameter($name)
If I understood correctly, it means I cannot declare two different container on my project. I'm sorry I begin with Symfony and I'm not really advanced with that framework, is there a way to work with two containers ?
rxu
Extensions Development Team
Posts: 3456
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Users variables integration to Symfony

Post by rxu »

Well, that example is from phpBB 3.1 times which may not be compatible with 3.3.
You'd need to get common.php from the version 3.3 as an example. It's almost the same but several lines. F.e.

Code: Select all

define('IN_PHPBB', true);

define('PHPBB_ROOT_PATH', './phpBB/');

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

require($phpbb_root_path . 'includes/startup.' . $phpEx);
require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx);

$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
$phpbb_class_loader->register();

$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
extract($phpbb_config_php_file->get_all());

require($phpbb_root_path . 'includes/functions.' . $phpEx);

// Set PHP error handler to ours
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');

$phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx);
$phpbb_class_loader_ext->register();

// Set up container
$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx);
$phpbb_container = $phpbb_container_builder->with_config($phpbb_config_php_file)->get_container();

$phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));

$passwords_manager = $phpbb_container->get('passwords.manager');
 
var_dump($passwords_manager);
EternalArcadia
Registered User
Posts: 5
Joined: Sat Aug 05, 2017 8:18 pm

Re: Users variables integration to Symfony

Post by EternalArcadia »

Yes I know I based my code on the new one.

Because this is only the last line which generates error, $phpbb_container = $phpbb_container_builder->with_config($phpbb_config_php_file)->get_container();, I decided to put it as a service :

Code: Select all

class Phpbb
{
    public function getUserId()
    {
        global $phpbb_class_loader, $phpbb_container_builder, $phpbb_config_php_file;
        $phpbb_container = $phpbb_container_builder->with_config($phpbb_config_php_file)->get_container();
        $phpbb_class_loader->set_cache($phpbb_container->get('cache.driver'));
        $user = $phpbb_container->get('user');
        $user->session_begin();
        $user->setup();

        return $user->data['user_id'];
    }
}
It's better because phpbb is recognized. But it seems there is a conflict between twig's PhpBB and twig's website.

Code: Select all

Compile Error: Declaration of phpbb\template\twig\lexer::tokenize(Twig\Source $source)
must be compatible with Twig\Lexer::tokenize(Twig\Source $source): Twig\TokenStream
I don't really what to do with that...
rxu
Extensions Development Team
Posts: 3456
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Users variables integration to Symfony

Post by rxu »

phpBB uses Twig v2.13.1, your site is probably using newer one which is current phpBB not compatible with.
EternalArcadia
Registered User
Posts: 5
Joined: Sat Aug 05, 2017 8:18 pm

Re: Users variables integration to Symfony

Post by EternalArcadia »

Is there a way to get rid of that ? I don't need PhpBB Twig for this project.
rxu
Extensions Development Team
Posts: 3456
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Users variables integration to Symfony

Post by rxu »

I don't think so, unless you gonna fix all the stuff in phpbb\template\twig.
EternalArcadia
Registered User
Posts: 5
Joined: Sat Aug 05, 2017 8:18 pm

Re: Users variables integration to Symfony

Post by EternalArcadia »

Has anyone an idea to not include twig?
Post Reply

Return to “phpBB Custom Coding”