Skip to content

Commit 6e6926e

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/2.3-develop' into MAGETWO-72487-signifyd
2 parents d06e21d + d1ebc31 commit 6e6926e

File tree

16 files changed

+143
-17
lines changed

16 files changed

+143
-17
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function build($productId)
8787
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
8888
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
8989
->order('t.min_price ' . Select::SQL_ASC)
90+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
9091
->limit(1);
9192
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
9293

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function build($productId)
9595
->where('t.attribute_id = ?', $priceAttribute->getAttributeId())
9696
->where('t.value IS NOT NULL')
9797
->order('t.value ' . Select::SQL_ASC)
98+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
9899
->limit(1);
99100
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
100101

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function build($productId)
139139
'special_to.value IS NULL OR ' . $connection->getDatePartSql('special_to.value') .' >= ?',
140140
$currentDate
141141
)->order('t.value ' . Select::SQL_ASC)
142+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
142143
->limit(1);
143144
$specialPrice = $this->baseSelectProcessor->process($specialPrice);
144145

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function build($productId)
9797
->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())
9898
->where('t.qty = ?', 1)
9999
->order('t.value ' . Select::SQL_ASC)
100+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
100101
->limit(1);
101102
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
102103

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPriceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testBuild()
8484
$select->expects($this->any())->method('from')->willReturnSelf();
8585
$select->expects($this->any())->method('joinInner')->willReturnSelf();
8686
$select->expects($this->any())->method('where')->willReturnSelf();
87-
$select->expects($this->once())->method('order')->willReturnSelf();
87+
$select->expects($this->exactly(2))->method('order')->willReturnSelf();
8888
$select->expects($this->once())->method('limit')->willReturnSelf();
8989
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($connection);
9090
$this->metadataPoolMock->expects($this->once())->method('getMetadata')->willReturn($metadata);

app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function build($productId)
105105
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
106106
->where('t.rule_date = ?', $currentDate)
107107
->order('t.rule_price ' . Select::SQL_ASC)
108+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
108109
->limit(1);
109110
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
110111

app/code/Magento/Security/Model/AdminSessionsManager.php

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ class AdminSessionsManager
6666
*/
6767
private $remoteAddress;
6868

69+
/**
70+
* Max lifetime for session prolong to be valid (sec)
71+
*
72+
* Means that after session was prolonged
73+
* all other prolongs will be ignored within this period
74+
*/
75+
private $maxIntervalBetweenConsecutiveProlongs = 60;
76+
6977
/**
7078
* @param ConfigInterface $securityConfig
7179
* @param \Magento\Backend\Model\Auth\Session $authSession
@@ -124,11 +132,16 @@ public function processLogin()
124132
*/
125133
public function processProlong()
126134
{
127-
$this->getCurrentSession()->setData(
128-
'updated_at',
129-
$this->authSession->getUpdatedAt()
130-
);
131-
$this->getCurrentSession()->save();
135+
if ($this->lastProlongIsOldEnough()) {
136+
$this->getCurrentSession()->setData(
137+
'updated_at',
138+
date(
139+
\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT,
140+
$this->authSession->getUpdatedAt()
141+
)
142+
);
143+
$this->getCurrentSession()->save();
144+
}
132145

133146
return $this;
134147
}
@@ -298,4 +311,45 @@ protected function createAdminSessionInfoCollection()
298311
{
299312
return $this->adminSessionInfoCollectionFactory->create();
300313
}
314+
315+
/**
316+
* Calculates diff between now and last session updated_at
317+
* and decides whether new prolong must be triggered or not
318+
*
319+
* This is done to limit amount of session prolongs and updates to database
320+
* within some period of time - X
321+
* X - is calculated in getIntervalBetweenConsecutiveProlongs()
322+
*
323+
* @see getIntervalBetweenConsecutiveProlongs()
324+
* @return bool
325+
*/
326+
private function lastProlongIsOldEnough()
327+
{
328+
$lastProlongTimestamp = strtotime($this->getCurrentSession()->getUpdatedAt());
329+
$nowTimestamp = $this->authSession->getUpdatedAt();
330+
331+
$diff = $nowTimestamp - $lastProlongTimestamp;
332+
333+
return (float) $diff > $this->getIntervalBetweenConsecutiveProlongs();
334+
}
335+
336+
/**
337+
* Calculates lifetime for session prolong to be valid
338+
*
339+
* Calculation is based on admin session lifetime
340+
* Calculated result is in seconds and is in the interval
341+
* between 1 (including) and MAX_INTERVAL_BETWEEN_CONSECUTIVE_PROLONGS (including)
342+
*
343+
* @return float
344+
*/
345+
private function getIntervalBetweenConsecutiveProlongs()
346+
{
347+
return (float) max(
348+
1,
349+
min(
350+
4 * log((float)$this->securityConfig->getAdminSessionLifetime()),
351+
$this->maxIntervalBetweenConsecutiveProlongs
352+
)
353+
);
354+
}
301355
}

app/code/Magento/Security/Test/Unit/Model/AdminSessionsManagerTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public function setUp()
9999
'setIsOtherSessionsTerminated',
100100
'save',
101101
'getUserId',
102-
'getSessionId'
102+
'getSessionId',
103+
'getUpdatedAt'
103104
]);
104105

105106
$this->securityConfigMock = $this->getMockBuilder(\Magento\Security\Model\ConfigInterface::class)
@@ -216,7 +217,8 @@ public function testProcessLogin()
216217
public function testProcessProlong()
217218
{
218219
$sessionId = 50;
219-
$updatedAt = '2015-12-31 23:59:59';
220+
$lastUpdatedAt = '2015-12-31 23:59:59';
221+
$newUpdatedAt = '2016-01-01 00:00:30';
220222

221223
$this->adminSessionInfoFactoryMock->expects($this->any())
222224
->method('create')
@@ -230,13 +232,21 @@ public function testProcessProlong()
230232
->method('load')
231233
->willReturnSelf();
232234

233-
$this->authSessionMock->expects($this->once())
235+
$this->currentSessionMock->expects($this->once())
236+
->method('getUpdatedAt')
237+
->willReturn($lastUpdatedAt);
238+
239+
$this->authSessionMock->expects($this->exactly(2))
234240
->method('getUpdatedAt')
235-
->willReturn($updatedAt);
241+
->willReturn(strtotime($newUpdatedAt));
242+
243+
$this->securityConfigMock->expects($this->once())
244+
->method('getAdminSessionLifetime')
245+
->willReturn(100);
236246

237247
$this->currentSessionMock->expects($this->once())
238248
->method('setData')
239-
->with('updated_at', $updatedAt)
249+
->with('updated_at', $newUpdatedAt)
240250
->willReturnSelf();
241251

242252
$this->currentSessionMock->expects($this->once())

0 commit comments

Comments
 (0)