mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-02 08:09:19 +08:00
Symfony 6.4 - Update Session dependency with RequestStack dependency
This commit is contained in:
parent
57865bfc95
commit
6841cd8582
4 changed files with 84 additions and 31 deletions
|
@ -130,7 +130,7 @@ class UserHandler extends LegacyHandler
|
||||||
*/
|
*/
|
||||||
public function getSessionLanguage(): string
|
public function getSessionLanguage(): string
|
||||||
{
|
{
|
||||||
return $this->session->get('ui_language', '');
|
return $this->requestStack->get('ui_language', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,7 +142,7 @@ class UserHandler extends LegacyHandler
|
||||||
set_current_language($language);
|
set_current_language($language);
|
||||||
$this->close();
|
$this->close();
|
||||||
|
|
||||||
$this->session->set('ui_language', $language);
|
$this->requestStack->set('ui_language', $language);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,7 +34,12 @@ use RuntimeException;
|
||||||
use SugarApplication;
|
use SugarApplication;
|
||||||
use SugarController;
|
use SugarController;
|
||||||
use SugarThemeRegistry;
|
use SugarThemeRegistry;
|
||||||
|
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\Session;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
|
||||||
use User;
|
use User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +79,7 @@ abstract class LegacyHandler
|
||||||
/**
|
/**
|
||||||
* @var RequestStack
|
* @var RequestStack
|
||||||
*/
|
*/
|
||||||
protected $session;
|
protected $requestStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LegacyHandler constructor.
|
* LegacyHandler constructor.
|
||||||
|
@ -83,7 +88,7 @@ abstract class LegacyHandler
|
||||||
* @param string $legacySessionName
|
* @param string $legacySessionName
|
||||||
* @param string $defaultSessionName
|
* @param string $defaultSessionName
|
||||||
* @param LegacyScopeState $legacyScopeState
|
* @param LegacyScopeState $legacyScopeState
|
||||||
* @param RequestStack $session
|
* @param RequestStack $requestStack
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $projectDir,
|
string $projectDir,
|
||||||
|
@ -91,14 +96,14 @@ abstract class LegacyHandler
|
||||||
string $legacySessionName,
|
string $legacySessionName,
|
||||||
string $defaultSessionName,
|
string $defaultSessionName,
|
||||||
LegacyScopeState $legacyScopeState,
|
LegacyScopeState $legacyScopeState,
|
||||||
RequestStack $session
|
RequestStack $requestStack
|
||||||
) {
|
) {
|
||||||
$this->projectDir = $projectDir;
|
$this->projectDir = $projectDir;
|
||||||
$this->legacyDir = $legacyDir;
|
$this->legacyDir = $legacyDir;
|
||||||
$this->legacySessionName = $legacySessionName;
|
$this->legacySessionName = $legacySessionName;
|
||||||
$this->defaultSessionName = $defaultSessionName;
|
$this->defaultSessionName = $defaultSessionName;
|
||||||
$this->state = $legacyScopeState;
|
$this->state = $legacyScopeState;
|
||||||
$this->session = $session;
|
$this->requestStack = $requestStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -294,36 +299,40 @@ abstract class LegacyHandler
|
||||||
|
|
||||||
protected function startSymfonySession(): void
|
protected function startSymfonySession(): void
|
||||||
{
|
{
|
||||||
if ($this->session->isStarted()) {
|
$session = $this->getSession();
|
||||||
$this->session->save();
|
|
||||||
|
if ($session->isStarted()) {
|
||||||
|
$session->save();
|
||||||
session_write_close();
|
session_write_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->session->setName($this->defaultSessionName);
|
$session->setName($this->defaultSessionName);
|
||||||
|
|
||||||
if (isset($_COOKIE[$this->defaultSessionName])) {
|
if (isset($_COOKIE[$this->defaultSessionName])) {
|
||||||
$this->session->setId($_COOKIE[$this->defaultSessionName]);
|
$session->setId($_COOKIE[$this->defaultSessionName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->session->start();
|
$session->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function startLegacySession(): void
|
protected function startLegacySession(): void
|
||||||
{
|
{
|
||||||
if ($this->session->isStarted()) {
|
$session = $this->getSession();
|
||||||
$this->session->save();
|
|
||||||
|
if ($session->isStarted()) {
|
||||||
|
$session->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session_status() === PHP_SESSION_ACTIVE) {
|
if (session_status() === PHP_SESSION_ACTIVE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->session->setName($this->legacySessionName);
|
$session->setName($this->legacySessionName);
|
||||||
|
|
||||||
if (!isset($_COOKIE[$this->legacySessionName])) {
|
if (!isset($_COOKIE[$this->legacySessionName])) {
|
||||||
$_COOKIE[$this->legacySessionName] = session_create_id();
|
$_COOKIE[$this->legacySessionName] = session_create_id();
|
||||||
}
|
}
|
||||||
$this->session->setId($_COOKIE[$this->legacySessionName]);
|
$session->setId($_COOKIE[$this->legacySessionName]);
|
||||||
$this->session->start();
|
$session->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -341,4 +350,48 @@ abstract class LegacyHandler
|
||||||
|
|
||||||
$app_strings = disable_translations($app_strings);
|
$app_strings = disable_translations($app_strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return SessionInterface
|
||||||
|
*/
|
||||||
|
protected function getSession(): SessionInterface
|
||||||
|
{
|
||||||
|
$request = Request::createFromGlobals();
|
||||||
|
$requestSession = null;
|
||||||
|
try {
|
||||||
|
$requestSession = $request->getSession();
|
||||||
|
} catch (SessionNotFoundException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
$session = null;
|
||||||
|
|
||||||
|
if($requestSession === null || session_id() == '' || !isset($_SESSION) || session_status() === PHP_SESSION_NONE) {
|
||||||
|
// session isn't started
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// Get Symfony to interface with this existing session
|
||||||
|
$session = new Session(new PhpBridgeSessionStorage());
|
||||||
|
|
||||||
|
// symfony will now interface with the existing PHP session
|
||||||
|
$session->start();
|
||||||
|
$request->setSession($session);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$stack = $this->requestStack ?? null;
|
||||||
|
if ($stack === null) {
|
||||||
|
$stack = new RequestStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($requestSession === null) {
|
||||||
|
$stack->push($request);
|
||||||
|
return $session;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$session = $this->requestStack->getMainRequest()->getSession();
|
||||||
|
|
||||||
|
|
||||||
|
return $session;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ abstract class BaseCommand extends Command
|
||||||
/**
|
/**
|
||||||
* @var RequestStack
|
* @var RequestStack
|
||||||
*/
|
*/
|
||||||
protected $session;
|
protected $requestStack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -86,11 +86,11 @@ abstract class BaseCommand extends Command
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @required
|
* @required
|
||||||
* @param RequestStack $session
|
* @param RequestStack $requestStack
|
||||||
*/
|
*/
|
||||||
public function setSession(RequestStack $session): void
|
public function setRequestStack(RequestStack $requestStack): void
|
||||||
{
|
{
|
||||||
$this->session = $session;
|
$this->requestStack = $requestStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,13 +163,13 @@ abstract class BaseCommand extends Command
|
||||||
*/
|
*/
|
||||||
protected function startSession(): void
|
protected function startSession(): void
|
||||||
{
|
{
|
||||||
if ($this->session->isStarted()) {
|
if ($this->requestStack->getSession()->isStarted()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->session->setName($this->defaultSessionName);
|
$this->requestStack->getSession()->setName($this->defaultSessionName);
|
||||||
|
|
||||||
$this->session->start();
|
$this->requestStack->getSession()->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -78,17 +78,17 @@ class InstallHandler extends LegacyHandler
|
||||||
* @param string $legacySessionName
|
* @param string $legacySessionName
|
||||||
* @param string $defaultSessionName
|
* @param string $defaultSessionName
|
||||||
* @param LegacyScopeState $legacyScopeState
|
* @param LegacyScopeState $legacyScopeState
|
||||||
* @param RequestStack $session
|
* @param RequestStack $requestStack
|
||||||
* @param LoggerInterface $logger
|
* @param LoggerInterface $logger
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $projectDir,
|
string $projectDir,
|
||||||
string $legacyDir,
|
string $legacyDir,
|
||||||
string $legacySessionName,
|
string $legacySessionName,
|
||||||
string $defaultSessionName,
|
string $defaultSessionName,
|
||||||
LegacyScopeState $legacyScopeState,
|
LegacyScopeState $legacyScopeState,
|
||||||
RequestStack $session,
|
RequestStack $requestStack,
|
||||||
LoggerInterface $logger
|
LoggerInterface $logger
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
parent::__construct(
|
parent::__construct(
|
||||||
|
@ -97,7 +97,7 @@ class InstallHandler extends LegacyHandler
|
||||||
$legacySessionName,
|
$legacySessionName,
|
||||||
$defaultSessionName,
|
$defaultSessionName,
|
||||||
$legacyScopeState,
|
$legacyScopeState,
|
||||||
$session
|
$requestStack
|
||||||
);
|
);
|
||||||
$this->legacyDir = $legacyDir;
|
$this->legacyDir = $legacyDir;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue