Skip to content

Commit b8c251e

Browse files
MAGETWO-52143: Make Redis session adapter changes backwards compatible in 2.1
1 parent 8bc4691 commit b8c251e

File tree

3 files changed

+52
-68
lines changed

3 files changed

+52
-68
lines changed

lib/internal/Magento/Framework/Session/Config.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ class Config implements ConfigInterface
7676
/** @var string */
7777
protected $lifetimePath;
7878

79-
/** @var string */
80-
private $saveHandlerName;
81-
8279
/** @var \Magento\Framework\ValidatorFactory */
8380
protected $_validatorFactory;
8481

@@ -110,20 +107,6 @@ public function __construct(
110107
$this->_scopeType = $scopeType;
111108
$this->lifetimePath = $lifetimePath;
112109

113-
/**
114-
* Session handler
115-
*
116-
* Save handler may be set to custom value in deployment config, which will override everything else.
117-
* Otherwise, try to read PHP settings for session.save_handler value. Otherwise, use 'files' as default.
118-
*/
119-
$defaultSaveHandler = $this->getStorageOption('session.save_handler')
120-
?: SaveHandlerInterface::DEFAULT_HANDLER;
121-
$saveMethod = $deploymentConfig->get(
122-
self::PARAM_SESSION_SAVE_METHOD,
123-
$defaultSaveHandler
124-
);
125-
$this->setSaveHandler($saveMethod);
126-
127110
/**
128111
* Session path
129112
*/
@@ -271,38 +254,6 @@ public function getName()
271254
return (string)$this->getOption('session.name');
272255
}
273256

274-
/**
275-
* {@inheritdoc}
276-
*/
277-
public function setSaveHandler($saveHandler)
278-
{
279-
$this->setSaveHandlerName($saveHandler);
280-
if ($saveHandler === 'db' || $saveHandler === 'redis') {
281-
$saveHandler = 'user';
282-
}
283-
$this->setOption('session.save_handler', $saveHandler);
284-
return $this;
285-
}
286-
287-
/**
288-
* Set save handler name
289-
*
290-
* @param string $saveHandlerName
291-
* @return void
292-
*/
293-
private function setSaveHandlerName($saveHandlerName)
294-
{
295-
$this->saveHandlerName = $saveHandlerName;
296-
}
297-
298-
/**
299-
* {@inheritdoc}
300-
*/
301-
public function getSaveHandlerName()
302-
{
303-
return $this->saveHandlerName;
304-
}
305-
306257
/**
307258
* Set session.save_path
308259
*

lib/internal/Magento/Framework/Session/Config/ConfigInterface.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,4 @@ public function setUseCookies($useCookies);
170170
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
171171
*/
172172
public function getUseCookies();
173-
174-
/**
175-
* Get save handler name
176-
*
177-
* @return string
178-
*/
179-
public function getSaveHandlerName();
180-
181-
/**
182-
* Set session.save_handler
183-
*
184-
* @param string $saveHandler
185-
* @return $this
186-
*/
187-
public function setSaveHandler($saveHandler);
188173
}

lib/internal/Magento/Framework/Session/SaveHandler.php

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Framework\Session;
77

8+
use Magento\Framework\App\DeploymentConfig;
89
use Magento\Framework\Exception\SessionException;
910
use Magento\Framework\Session\Config\ConfigInterface;
1011

@@ -20,24 +21,40 @@ class SaveHandler implements SaveHandlerInterface
2021
*/
2122
protected $saveHandlerAdapter;
2223

24+
/**
25+
* Config
26+
*
27+
* @var ConfigInterface
28+
*/
29+
private $config;
30+
2331
/**
2432
* Constructor
2533
*
2634
* @param SaveHandlerFactory $saveHandlerFactory
27-
* @param ConfigInterface $config
35+
* @param DeploymentConfig $deploymentConfig
2836
* @param string $default
2937
*/
3038
public function __construct(
3139
SaveHandlerFactory $saveHandlerFactory,
32-
ConfigInterface $config,
40+
DeploymentConfig $deploymentConfig,
3341
$default = self::DEFAULT_HANDLER
3442
) {
35-
$saveMethod = $config->getSaveHandlerName();
43+
/**
44+
* Session handler
45+
*
46+
* Save handler may be set to custom value in deployment config, which will override everything else.
47+
* Otherwise, try to read PHP settings for session.save_handler value. Otherwise, use 'files' as default.
48+
*/
49+
$defaultSaveHandler = ini_get('session.save_handler') ?: SaveHandlerInterface::DEFAULT_HANDLER;
50+
$saveMethod = $deploymentConfig->get(Config::PARAM_SESSION_SAVE_METHOD, $defaultSaveHandler);
51+
$this->setSaveHandler($saveMethod);
52+
3653
try {
3754
$connection = $saveHandlerFactory->create($saveMethod);
3855
} catch (SessionException $e) {
3956
$connection = $saveHandlerFactory->create($default);
40-
$config->setSaveHandler($default);
57+
$this->setSaveHandler($default);
4158
}
4259
$this->saveHandlerAdapter = $connection;
4360
}
@@ -110,4 +127,35 @@ public function gc($maxLifetime)
110127
{
111128
return $this->saveHandlerAdapter->gc($maxLifetime);
112129
}
130+
131+
/**
132+
* Get config
133+
*
134+
* @return ConfigInterface
135+
* @deprecated
136+
*/
137+
private function getConfig()
138+
{
139+
if (!($this->config instanceof ConfigInterface)) {
140+
return \Magento\Framework\App\ObjectManager::getInstance()->get(
141+
ConfigInterface::class
142+
);
143+
}
144+
return $this->config;
145+
}
146+
147+
/**
148+
* Set session.save_handler option in ini config
149+
*
150+
* @param string $saveHandler
151+
* @return $this
152+
*/
153+
private function setSaveHandler($saveHandler)
154+
{
155+
if ($saveHandler === 'db' || $saveHandler === 'redis') {
156+
$saveHandler = 'user';
157+
}
158+
$this->getConfig()->setOption('session.save_handler', $saveHandler);
159+
return $this;
160+
}
113161
}

0 commit comments

Comments
 (0)