Skip to content

Commit

Permalink
Merge pull request #557 from magento-extensibility/redis-session-adap…
Browse files Browse the repository at this point in the history
…ter-3

[Extensibility] Port Redis session adapter to Magento 2.0.6
  • Loading branch information
monkeysee committed May 4, 2016
2 parents 5702983 + 4539c23 commit a251866
Show file tree
Hide file tree
Showing 60 changed files with 1,155 additions and 1,307 deletions.
6 changes: 6 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

# SetEnv MAGE_MODE developer

############################################
## overrides default umask value to allow using different
## file permissions

# SetEnv MAGE_UMASK 022

############################################
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
Expand Down
6 changes: 6 additions & 0 deletions .htaccess.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

# SetEnv MAGE_MODE developer

############################################
## overrides default umask value to allow using different
## file permissions

# SetEnv MAGE_UMASK 022

############################################
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
Expand Down
5 changes: 4 additions & 1 deletion app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
*/
error_reporting(E_ALL);
#ini_set('display_errors', 1);
umask(0);

/* Custom umask value may be provided in MAGE_UMASK environment variable */
$mask = isset($_SERVER['MAGE_UMASK']) ? octdec($_SERVER['MAGE_UMASK']) : 002;
umask($mask);

/* PHP version validation */
if (version_compare(phpversion(), '5.5.0', '<') === true) {
Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/Backend/Model/Session/AdminConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

/**
* Magento Backend session configuration
*
* @method Config setSaveHandler()
*/
class AdminConfig extends Config
{
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Backup/Model/Fs/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ protected function _hideBackupsForApache()
$filename = '.htaccess';
if (!$this->_varDirectory->isFile($filename)) {
$this->_varDirectory->writeFile($filename, 'deny from all');
$this->_varDirectory->changePermissions($filename, 0640);
}
}

Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/Captcha/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ public function getImgDir($website = null)
$mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$captchaDir = '/captcha/' . $this->_getWebsiteCode($website);
$mediaDir->create($captchaDir);
$mediaDir->changePermissions($captchaDir, DriverInterface::WRITEABLE_DIRECTORY_MODE);

return $mediaDir->getAbsolutePath($captchaDir) . '/';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ public function addImage(
$storageHelper->saveFile($this->mediaConfig->getTmpMediaShortUrl($fileName));
} else {
$this->mediaDirectory->copyFile($file, $destinationFile);

$storageHelper->saveFile($this->mediaConfig->getTmpMediaShortUrl($fileName));
$this->mediaDirectory->changePermissions($destinationFile, DriverInterface::WRITEABLE_FILE_MODE);
}
} catch (\Exception $e) {
throw new LocalizedException(__('We couldn\'t move this file: %1.', $e->getMessage()));
Expand Down
16 changes: 8 additions & 8 deletions app/code/Magento/Deploy/Model/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class Filesystem
{
/**
* File access permissions
*
* @deprecated
*/
const PERMISSIONS_FILE = 0640;

/**
* Directory access permissions
*
* @deprecated
*/
const PERMISSIONS_DIR = 0750;

Expand Down Expand Up @@ -107,19 +111,11 @@ public function regenerateStatic(
DirectoryList::TMP_MATERIALIZATION_DIR
]
);
$this->changePermissions(
[
DirectoryList::STATIC_VIEW
],
self::PERMISSIONS_DIR,
self::PERMISSIONS_DIR
);

// Trigger static assets compilation and deployment
$this->deployStaticContent($output);
// Trigger code generation
$this->compile($output);
$this->lockStaticResources();
}

/**
Expand Down Expand Up @@ -215,6 +211,8 @@ public function cleanupFilesystem($directoryCodeList)
* @param int $dirPermissions
* @param int $filePermissions
* @return void
*
* @deprecated
*/
protected function changePermissions($directoryCodeList, $dirPermissions, $filePermissions)
{
Expand All @@ -233,6 +231,8 @@ protected function changePermissions($directoryCodeList, $dirPermissions, $fileP
* Chenge permissions on static resources
*
* @return void
*
* @deprecated
*/
public function lockStaticResources()
{
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Deploy/Model/Mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function enableProductionMode()
*/
public function enableProductionModeMinimal()
{
$this->filesystem->lockStaticResources();
$this->setStoreMode(State::MODE_PRODUCTION);
}

Expand Down
37 changes: 21 additions & 16 deletions app/code/Magento/PageCache/Model/Cache/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
*/
namespace Magento\PageCache\Model\Cache;

use Zend\Uri\Uri;
use Magento\Framework\UrlInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Config\ConfigOptionsListConstants;
use Magento\Framework\App\RequestInterface;
use Zend\Uri\Uri;
use Zend\Uri\UriFactory;

class Server
{
/**
* @var \Magento\Framework\UrlInterface
* @var UrlInterface
*/
protected $urlBuilder;

Expand All @@ -33,12 +34,12 @@ class Server
/**
* Constructor
*
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param UrlInterface $urlBuilder
* @param DeploymentConfig $config
* @param RequestInterface $request
*/
public function __construct(
\Magento\Framework\UrlInterface $urlBuilder,
UrlInterface $urlBuilder,
DeploymentConfig $config,
RequestInterface $request
) {
Expand All @@ -56,21 +57,25 @@ public function getUris()
{
$servers = [];
$configuredHosts = $this->config->get(ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS);
if (null == $configuredHosts) {
$httpHost = $this->request->getHttpHost();
$servers[] = $httpHost ?
UriFactory::factory('')->setHost($httpHost)->setPort(self::DEFAULT_PORT)->setScheme('http') :
UriFactory::factory($this->urlBuilder->getUrl('*', ['_nosid' => true])) // Don't use SID in building URL
->setScheme('http')
->setPath(null)
->setQuery(null);

} else {
if (is_array($configuredHosts)) {
foreach ($configuredHosts as $host) {
$servers[] = UriFactory::factory('')->setHost($host['host'])
->setPort(isset($host['port']) ? $host['port'] : self::DEFAULT_PORT)
->setScheme('http');
$servers[] = UriFactory::factory('')
->setHost($host['host'])
->setPort(isset($host['port']) ? $host['port'] : self::DEFAULT_PORT);
}
} elseif ($this->request->getHttpHost()) {
$servers[] = UriFactory::factory('')
->setHost($this->request->getHttpHost())
->setPort(self::DEFAULT_PORT);
} else {
$servers[] = UriFactory::factory($this->urlBuilder->getUrl('*', ['_nosid' => true]));
}

foreach (array_keys($servers) as $key) {
$servers[$key]->setScheme('http')
->setPath('/')
->setQuery(null);
}
return $servers;
}
Expand Down
35 changes: 18 additions & 17 deletions app/code/Magento/PageCache/Test/Unit/Model/Cache/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
*/
namespace Magento\PageCache\Test\Unit\Model\Cache;

use \Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use \Magento\PageCache\Model\Cache\Server;
use \Zend\Uri\UriFactory;

class ServerTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\PageCache\Model\Cache\Server */
/** @var Server */
protected $model;

/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\DeploymentConfig */
Expand All @@ -30,7 +32,7 @@ public function setUp()
->disableOriginalConstructor()
->getMock();

$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$objectManager = new ObjectManager($this);
$this->model = $objectManager->getObject(
'Magento\PageCache\Model\Cache\Server',
[
Expand All @@ -56,12 +58,9 @@ public function testGetUris(
$url,
$hostConfig = null
) {
$this->configMock->expects($this->once())
->method('get')
->willReturn($hostConfig);
$this->requestMock->expects($this->exactly($getHttpHostCallCtr))
->method('getHttpHost')
->willReturn($httpHost);
$this->configMock->expects($this->once())->method('get')->willReturn($hostConfig);
$this->requestMock->expects($this->exactly($getHttpHostCallCtr))->method('getHttpHost')->willReturn($httpHost);

$this->urlBuilderMock->expects($this->exactly($getUrlCallCtr))
->method('getUrl')
->with('*', ['_nosid' => true])
Expand All @@ -70,30 +69,32 @@ public function testGetUris(
$uris = [];
if (null === $hostConfig) {
if (!empty($httpHost)) {
$uris[] = UriFactory::factory('')->setHost($httpHost)
->setPort(\Magento\PageCache\Model\Cache\Server::DEFAULT_PORT)
->setScheme('http');
$uris[] = UriFactory::factory('')->setHost($httpHost)->setPort(Server::DEFAULT_PORT);
}
if (!empty($url)) {
$uris[] = UriFactory::factory($url);
}
} else {
foreach ($hostConfig as $host) {
$port = isset($host['port']) ? $host['port'] : \Magento\PageCache\Model\Cache\Server::DEFAULT_PORT;
$uris[] = UriFactory::factory('')->setHost($host['host'])
->setPort($port)
->setScheme('http');
$port = isset($host['port']) ? $host['port'] : Server::DEFAULT_PORT;
$uris[] = UriFactory::factory('')->setHost($host['host'])->setPort($port);
}
}

foreach (array_keys($uris) as $key) {
$uris[$key]->setScheme('http')
->setPath('/')
->setQuery(null);
}

$this->assertEquals($uris, $this->model->getUris());
}

public function getUrisDataProvider()
{
return [
'http host' => [1, '127.0.0.1', 0, '',],
'url' => [1, '', 1, 'http://host',],
'http host' => [2, '127.0.0.1', 0, ''],
'url' => [1, '', 1, 'http://host'],
'config' => [
0,
'',
Expand Down
9 changes: 9 additions & 0 deletions app/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
<preference for="Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface" type="Magento\Framework\Stdlib\DateTime\DateTimeFormatter"/>
<preference for="Magento\Framework\Api\Search\SearchInterface" type="Magento\Framework\Search\Search"/>
<preference for="Magento\Framework\View\Design\FileResolution\Fallback\ResolverInterface" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple" />
<preference for="Cm\RedisSession\Handler\ConfigInterface" type="Magento\Framework\Session\SaveHandler\Redis\Config"/>
<preference for="Cm\RedisSession\Handler\LoggerInterface" type="Magento\Framework\Session\SaveHandler\Redis\Logger"/>
<type name="Magento\Framework\Model\ResourceModel\Db\TransactionManager" shared="false" />
<type name="Magento\Framework\Logger\Handler\Base">
<arguments>
Expand Down Expand Up @@ -186,9 +188,16 @@
<arguments>
<argument name="handlers" xsi:type="array">
<item name="db" xsi:type="string">Magento\Framework\Session\SaveHandler\DbTable</item>
<item name="redis" xsi:type="string">Magento\Framework\Session\SaveHandler\Redis</item>
</argument>
</arguments>
</type>
<type name="Magento\Framework\Session\SaveHandler\Redis">
<arguments>
<argument name="config" xsi:type="object">Cm\RedisSession\Handler\ConfigInterface</argument>
<argument name="logger" xsi:type="object">Cm\RedisSession\Handler\LoggerInterface</argument>
</arguments>
</type>
<virtualType name="interceptionConfigScope" type="Magento\Framework\Config\Scope">
<arguments>
<argument name="defaultScope" xsi:type="string">global</argument>
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"zendframework/zend-log": "~2.4.6",
"zendframework/zend-http": "~2.4.6",
"magento/zendframework1": "1.12.16",
"colinmollenhour/credis": "1.6",
"colinmollenhour/php-redis-session-abstract": "1.1",
"composer/composer": "1.0.0-alpha10",
"monolog/monolog": "1.16.0",
"oyejorge/less.php": "1.7.0.3",
Expand Down Expand Up @@ -188,7 +190,6 @@
"magento/framework": "100.0.7",
"trentrichardson/jquery-timepicker-addon": "1.4.3",
"colinmollenhour/cache-backend-redis": "1.8",
"colinmollenhour/credis": "1.5",
"components/jquery": "1.11.0",
"blueimp/jquery-file-upload": "5.6.14",
"components/jqueryui": "1.10.4",
Expand All @@ -199,7 +200,6 @@
"component_paths": {
"trentrichardson/jquery-timepicker-addon": "lib/web/jquery/jquery-ui-timepicker-addon.js",
"colinmollenhour/cache-backend-redis": "lib/internal/Cm/Cache/Backend/Redis.php",
"colinmollenhour/credis": "lib/internal/Credis",
"components/jquery": [
"lib/web/jquery.js",
"lib/web/jquery/jquery.min.js",
Expand Down
Loading

0 comments on commit a251866

Please sign in to comment.