Skip to content

Commit 62b37aa

Browse files
committed
Merge branch 'mainline-time_zone' into MAGETWO-45273
2 parents 02b9ddd + df7f428 commit 62b37aa

File tree

195 files changed

+3750
-2033
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+3750
-2033
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ protected function getTierPrices(array $listSku, $table)
345345
if (isset($exportFilter) && !empty($exportFilter)) {
346346
$date = $exportFilter[\Magento\Catalog\Model\Category::KEY_UPDATED_AT];
347347
if (isset($date[0]) && !empty($date[0])) {
348-
$updatedAtFrom = date('Y-m-d H:i:s', strtotime($date[0]));
348+
$updatedAtFrom = $this->_localeDate->date($date[0], null, false)->format('Y-m-d H:i:s');
349349
}
350350
if (isset($date[1]) && !empty($date[1])) {
351-
$updatedAtTo = date('Y-m-d H:i:s', strtotime($date[1]));
351+
$updatedAtTo = $this->_localeDate->date($date[1], null, false)->format('Y-m-d H:i:s');
352352
}
353353
}
354354
try {

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
143143
protected $_catalogProductEntity;
144144

145145
/**
146-
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
146+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
147147
*/
148-
protected $_localeDate;
148+
protected $dateTime;
149149

150150
/**
151151
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -157,7 +157,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
157157
* @param \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper
158158
* @param \Magento\Framework\Stdlib\StringUtils $string
159159
* @param ProcessingErrorAggregatorInterface $errorAggregator
160-
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
160+
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
161161
* @param \Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory
162162
* @param \Magento\Catalog\Model\Product $productModel
163163
* @param \Magento\Catalog\Helper\Data $catalogData
@@ -177,7 +177,7 @@ public function __construct(
177177
\Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper,
178178
\Magento\Framework\Stdlib\StringUtils $string,
179179
ProcessingErrorAggregatorInterface $errorAggregator,
180-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
180+
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
181181
\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory,
182182
\Magento\Catalog\Model\Product $productModel,
183183
\Magento\Catalog\Helper\Data $catalogData,
@@ -187,7 +187,7 @@ public function __construct(
187187
AdvancedPricing\Validator\Website $websiteValidator,
188188
AdvancedPricing\Validator\TierPrice $tierPriceValidator
189189
) {
190-
$this->_localeDate = $localeDate;
190+
$this->dateTime = $dateTime;
191191
$this->jsonHelper = $jsonHelper;
192192
$this->_importExportData = $importExportData;
193193
$this->_resourceHelper = $resourceHelper;
@@ -470,11 +470,11 @@ protected function deleteProductTierPrices(array $listSku, $tableName)
470470
*/
471471
protected function setUpdatedAt(array $listSku)
472472
{
473-
$updatedAt = $this->_localeDate->date(null, null, false)->format('Y-m-d H:i:s');
473+
$updatedAt = $this->dateTime->gmtDate('Y-m-d H:i:s');
474474
$this->_connection->update(
475475
$this->_catalogProductEntity,
476476
[\Magento\Catalog\Model\Category::KEY_UPDATED_AT => $updatedAt],
477-
$this->_connection->quoteInto('sku IN (?)', $listSku)
477+
$this->_connection->quoteInto('sku IN (?)', array_unique($listSku))
478478
);
479479
return $this;
480480
}

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricingTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class AdvancedPricingTest extends \Magento\ImportExport\Test\Unit\Model\Import\A
7979
/**
8080
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
8181
*/
82-
protected $localeDate;
82+
protected $dateTime;
8383

8484
/**
8585
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
@@ -249,14 +249,14 @@ public function setUp()
249249
false
250250
);
251251
$this->errorAggregator = $this->getErrorAggregatorObject();
252-
$this->localeDate = $this->getMock(
253-
'\Magento\Framework\Stdlib\DateTime\Timezone',
252+
$this->dateTime = $this->getMock(
253+
'\Magento\Framework\Stdlib\DateTime\DateTime',
254254
['date', 'format'],
255255
[],
256256
'',
257257
false
258258
);
259-
$this->localeDate->expects($this->any())->method('date')->willReturnSelf();
259+
$this->dateTime->expects($this->any())->method('date')->willReturnSelf();
260260

261261
$this->advancedPricing = $this->getAdvancedPricingMock([
262262
'retrieveOldSkus',
@@ -783,7 +783,7 @@ private function getAdvancedPricingMock($methods = [])
783783
$this->resourceHelper,
784784
$this->stringObject,
785785
$this->errorAggregator,
786-
$this->localeDate,
786+
$this->dateTime,
787787
$this->resourceFactory,
788788
$this->productModel,
789789
$this->catalogData,

app/code/Magento/Backend/App/Area/FrontNameResolver.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
2424
*/
2525
const AREA_CODE = 'adminhtml';
2626

27+
/**
28+
* @var array
29+
*/
30+
protected $standardPorts = ['http' => '80', 'https' => '443'];
31+
2732
/**
2833
* @var string
2934
*/
@@ -42,21 +47,21 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
4247
protected $deploymentConfig;
4348

4449
/** @var ScopeConfigInterface */
45-
private $configInterface;
50+
private $scopeConfig;
4651

4752
/**
4853
* @param \Magento\Backend\App\Config $config
4954
* @param DeploymentConfig $deploymentConfig
50-
* @param ScopeConfigInterface $configInterface
55+
* @param ScopeConfigInterface $scopeConfig
5156
*/
5257
public function __construct(
5358
\Magento\Backend\App\Config $config,
5459
DeploymentConfig $deploymentConfig,
55-
ScopeConfigInterface $configInterface
60+
ScopeConfigInterface $scopeConfig
5661
) {
5762
$this->config = $config;
5863
$this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME);
59-
$this->configInterface = $configInterface;
64+
$this->scopeConfig = $scopeConfig;
6065
}
6166

6267
/**
@@ -79,13 +84,30 @@ public function getFrontName($checkHost = false)
7984

8085
/**
8186
* Return whether the host from request is the backend host
87+
*
8288
* @return bool
8389
*/
8490
public function isHostBackend()
8591
{
86-
$backendUrl = $this->configInterface->getValue(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE);
87-
$backendHost = parse_url(trim($backendUrl), PHP_URL_HOST);
92+
$backendUrl = $this->scopeConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE);
8893
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
89-
return (strcasecmp($backendHost, $host) === 0);
94+
return stripos($this->getHostWithPort($backendUrl), $host) !== false;
95+
}
96+
97+
/**
98+
* Get host with port
99+
*
100+
* @param string $url
101+
* @return mixed|string
102+
*/
103+
private function getHostWithPort($url)
104+
{
105+
$scheme = parse_url(trim($url), PHP_URL_SCHEME);
106+
$host = parse_url(trim($url), PHP_URL_HOST);
107+
$port = parse_url(trim($url), PHP_URL_PORT);
108+
if (!$port) {
109+
$port = isset($this->standardPorts[$scheme]) ? $this->standardPorts[$scheme] : null;
110+
}
111+
return isset($port) ? $host . ':' . $port : $host;
90112
}
91113
}

app/code/Magento/Backend/Block/Widget/Grid/Column.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public function setFilterType($type, $className)
447447
*/
448448
protected function _getFilterByType()
449449
{
450-
$type = strtolower($this->getType());
450+
$type = $this->getFilterType() ? strtolower($this->getFilterType()) : strtolower($this->getType());
451451
$filterClass = isset($this->_filterTypes[$type]) ? $this->_filterTypes[$type] : $this->_filterTypes['default'];
452452

453453
return $filterClass;

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ public function setValue($value)
200200
protected function _convertDate($date)
201201
{
202202
$adminTimeZone = new \DateTimeZone(
203-
$this->_scopeConfig->getValue(
204-
$this->_localeDate->getDefaultTimezonePath(),
205-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
206-
)
203+
$this->_localeDate->getConfigTimezone()
207204
);
208205
$formatter = new \IntlDateFormatter(
209206
$this->localeResolver->getLocale(),

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ protected function _convertDate($date)
6969
if ($this->getColumn()->getFilterTime()) {
7070
try {
7171
$adminTimeZone = new \DateTimeZone(
72-
$this->_scopeConfig->getValue(
73-
$this->_localeDate->getDefaultTimezonePath(),
74-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
75-
)
72+
$this->_localeDate->getConfigTimezone()
7673
);
7774
$simpleRes = new \DateTime($date, $adminTimeZone);
7875
$simpleRes->setTimezone(new \DateTimeZone('UTC'));

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Date.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ protected function _getFormat()
7575
public function render(\Magento\Framework\DataObject $row)
7676
{
7777
if ($data = $row->getData($this->getColumn()->getIndex())) {
78+
$timezone = $this->getColumn()->getTimezone() !== false ? $this->_localeDate->getConfigTimezone() : 'UTC';
7879
return $this->dateTimeFormatter->formatObject(
7980
$this->_localeDate->date(
80-
new \DateTime($data, new \DateTimeZone($this->_localeDate->getConfigTimezone()))
81+
new \DateTime(
82+
$data,
83+
new \DateTimeZone($timezone)
84+
)
8185
),
8286
$this->_getFormat()
8387
);

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Datetime.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Abstra
2020
public function render(\Magento\Framework\DataObject $row)
2121
{
2222
$format = $this->getColumn()->getFormat();
23-
if ($data = $this->_getValue($row)) {
23+
if ($date = $this->_getValue($row)) {
2424
return $this->_localeDate->formatDateTime(
25-
$data instanceof \DateTimeInterface ? $data : new \DateTime($data),
25+
$date instanceof \DateTimeInterface ? $date : new \DateTime($date),
2626
$format ?: \IntlDateFormatter::MEDIUM,
27-
$format ?: \IntlDateFormatter::MEDIUM
27+
$format ?: \IntlDateFormatter::MEDIUM,
28+
null,
29+
$this->getColumn()->getTimezone() !== false ? null : 'UTC'
2830
);
2931
}
3032
return $this->getColumn()->getDefault();

app/code/Magento/Backend/Model/Session/AdminConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function __construct(
8484
$adminPath = $this->extractAdminPath();
8585
$this->setCookiePath($adminPath);
8686
$this->setName($sessionName);
87+
$this->setCookieSecure($this->_httpRequest->isSecure());
8788
}
8889

8990
/**

app/code/Magento/Backend/Test/Unit/App/Area/FrontNameResolverTest.php

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@
77

88
use Magento\Backend\App\Area\FrontNameResolver;
99
use Magento\Backend\Setup\ConfigOptionsList;
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magento\Store\Model\Store;
1013

1114
class FrontNameResolverTest extends \PHPUnit_Framework_TestCase
1215
{
1316
/**
1417
* @var \Magento\Backend\App\Area\FrontNameResolver
1518
*/
16-
protected $_model;
19+
protected $model;
1720

1821
/**
19-
* @var \PHPUnit_Framework_MockObject_MockObject
22+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\App\Config
2023
*/
21-
protected $_configMock;
24+
protected $configMock;
25+
26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
28+
*/
29+
protected $scopeConfigMock;
2230

2331
/**
2432
* @var string
@@ -27,19 +35,20 @@ class FrontNameResolverTest extends \PHPUnit_Framework_TestCase
2735

2836
protected function setUp()
2937
{
30-
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
38+
/** @var \PHPUnit_Framework_MockObject_MockObject|DeploymentConfig $deploymentConfigMock */
39+
$deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
3140
$deploymentConfigMock->expects($this->once())
3241
->method('get')
3342
->with(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME)
3443
->will($this->returnValue($this->_defaultFrontName));
35-
$this->_configMock = $this->getMock('\Magento\Backend\App\Config', [], [], '', false);
36-
$configMock = $this->getMock('\Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
37-
$this->_model = new FrontNameResolver($this->_configMock, $deploymentConfigMock, $configMock);
44+
$this->configMock = $this->getMock('Magento\Backend\App\Config', [], [], '', false);
45+
$this->scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
46+
$this->model = new FrontNameResolver($this->configMock, $deploymentConfigMock, $this->scopeConfigMock);
3847
}
3948

4049
public function testIfCustomPathUsed()
4150
{
42-
$this->_configMock->expects(
51+
$this->configMock->expects(
4352
$this->at(0)
4453
)->method(
4554
'getValue'
@@ -48,7 +57,7 @@ public function testIfCustomPathUsed()
4857
)->will(
4958
$this->returnValue(true)
5059
);
51-
$this->_configMock->expects(
60+
$this->configMock->expects(
5261
$this->at(1)
5362
)->method(
5463
'getValue'
@@ -57,12 +66,12 @@ public function testIfCustomPathUsed()
5766
)->will(
5867
$this->returnValue('expectedValue')
5968
);
60-
$this->assertEquals('expectedValue', $this->_model->getFrontName());
69+
$this->assertEquals('expectedValue', $this->model->getFrontName());
6170
}
6271

6372
public function testIfCustomPathNotUsed()
6473
{
65-
$this->_configMock->expects(
74+
$this->configMock->expects(
6675
$this->once()
6776
)->method(
6877
'getValue'
@@ -71,6 +80,58 @@ public function testIfCustomPathNotUsed()
7180
)->will(
7281
$this->returnValue(false)
7382
);
74-
$this->assertEquals($this->_defaultFrontName, $this->_model->getFrontName());
83+
$this->assertEquals($this->_defaultFrontName, $this->model->getFrontName());
84+
}
85+
86+
/**
87+
* @param $url
88+
* @param $host
89+
* @dataProvider hostsDataProvider
90+
*/
91+
public function testIsHostBackend($url, $host, $expectedValue)
92+
{
93+
$backendUrl = $url;
94+
$_SERVER['HTTP_HOST'] = $host;
95+
$this->scopeConfigMock->expects($this->once())
96+
->method('getValue')
97+
->with(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE)
98+
->willReturn($backendUrl);
99+
$this->assertEquals($this->model->isHostBackend(), $expectedValue);
100+
}
101+
102+
public function hostsDataProvider()
103+
{
104+
return [
105+
'withoutPort' => [
106+
'url' => 'http://magento2.loc/',
107+
'host' => 'magento2.loc',
108+
'expectedValue' => true
109+
],
110+
'withPort' => [
111+
'url' => 'http://magento2.loc:8080/',
112+
'host' => 'magento2.loc:8080',
113+
'expectedValue' => true
114+
],
115+
'withStandartPortInUrlWithoutPortInHost' => [
116+
'url' => 'http://magento2.loc:80/',
117+
'host' => 'magento2.loc',
118+
'expectedValue' => true
119+
],
120+
'withoutStandartPortInUrlWithPortInHost' => [
121+
'url' => 'https://magento2.loc/',
122+
'host' => 'magento2.loc:443',
123+
'expectedValue' => true
124+
],
125+
'differentHosts' => [
126+
'url' => 'http://m2.loc/',
127+
'host' => 'magento2.loc',
128+
'expectedValue' => false
129+
],
130+
'differentPortsOnOneHost' => [
131+
'url' => 'http://magento2.loc/',
132+
'host' => 'magento2.loc:8080',
133+
'expectedValue' => false
134+
]
135+
];
75136
}
76137
}

0 commit comments

Comments
 (0)