Skip to content

Commit 8b972b1

Browse files
committed
Merge branch '2.3-develop' of github.com:magento/magento2ce into 2.3-develop-PR
2 parents d9d8c93 + a8e5e30 commit 8b972b1

File tree

11 files changed

+141
-15
lines changed

11 files changed

+141
-15
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())

dev/tests/integration/testsuite/Magento/Security/Model/Plugin/AuthSessionTest.php

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class AuthSessionTest extends \PHPUnit\Framework\TestCase
4040
*/
4141
protected $dateTime;
4242

43+
/**
44+
* @var \Magento\Security\Model\ConfigInterface
45+
*/
46+
protected $securityConfig;
47+
4348
/**
4449
* Set up
4550
*/
@@ -54,8 +59,9 @@ protected function setUp()
5459
$this->authSession = $this->objectManager->create(\Magento\Backend\Model\Auth\Session::class);
5560
$this->adminSessionInfo = $this->objectManager->create(\Magento\Security\Model\AdminSessionInfo::class);
5661
$this->auth->setAuthStorage($this->authSession);
57-
$this->adminSessionsManager = $this->objectManager->create(\Magento\Security\Model\AdminSessionsManager::class);
62+
$this->adminSessionsManager = $this->objectManager->get(\Magento\Security\Model\AdminSessionsManager::class);
5863
$this->dateTime = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime::class);
64+
$this->securityConfig = $this->objectManager->create(\Magento\Security\Model\ConfigInterface::class);
5965
}
6066

6167
/**
@@ -73,7 +79,42 @@ protected function tearDown()
7379

7480
/**
7581
* Test of prolong user action
82+
* session manager will not trigger new prolong if previous prolong was less than X sec ago
83+
* X - is calculated based on current admin session lifetime
7684
*
85+
* @see \Magento\Security\Model\AdminSessionsManager::lastProlongIsOldEnough
86+
* @magentoDbIsolation enabled
87+
*/
88+
public function testConsecutiveProcessProlong()
89+
{
90+
$this->auth->login(
91+
\Magento\TestFramework\Bootstrap::ADMIN_NAME,
92+
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
93+
);
94+
$sessionId = $this->authSession->getSessionId();
95+
$prolongsDiff = log($this->securityConfig->getAdminSessionLifetime()) - 2; // X from comment above
96+
$dateInPast = $this->dateTime->formatDate($this->authSession->getUpdatedAt() - $prolongsDiff);
97+
$this->adminSessionsManager->getCurrentSession()
98+
->setData(
99+
'updated_at',
100+
$dateInPast
101+
)
102+
->save();
103+
$this->adminSessionInfo->load($sessionId, 'session_id');
104+
$oldUpdatedAt = $this->adminSessionInfo->getUpdatedAt();
105+
$this->authSession->prolong();
106+
$this->adminSessionInfo->load($sessionId, 'session_id');
107+
$updatedAt = $this->adminSessionInfo->getUpdatedAt();
108+
109+
$this->assertSame(strtotime($oldUpdatedAt), strtotime($updatedAt));
110+
}
111+
112+
/**
113+
* Test of prolong user action
114+
* session manager will trigger new prolong if previous prolong was more than X sec ago
115+
* X - is calculated based on current admin session lifetime
116+
*
117+
* @see \Magento\Security\Model\AdminSessionsManager::lastProlongIsOldEnough
77118
* @magentoDbIsolation enabled
78119
*/
79120
public function testProcessProlong()
@@ -83,7 +124,8 @@ public function testProcessProlong()
83124
\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD
84125
);
85126
$sessionId = $this->authSession->getSessionId();
86-
$dateInPast = $this->dateTime->formatDate($this->authSession->getUpdatedAt() - 100);
127+
$prolongsDiff = 4 * log($this->securityConfig->getAdminSessionLifetime()) + 2; // X from comment above
128+
$dateInPast = $this->dateTime->formatDate($this->authSession->getUpdatedAt() - $prolongsDiff);
87129
$this->adminSessionsManager->getCurrentSession()
88130
->setData(
89131
'updated_at',
@@ -95,6 +137,7 @@ public function testProcessProlong()
95137
$this->authSession->prolong();
96138
$this->adminSessionInfo->load($sessionId, 'session_id');
97139
$updatedAt = $this->adminSessionInfo->getUpdatedAt();
98-
$this->assertGreaterThan($oldUpdatedAt, $updatedAt);
140+
141+
$this->assertGreaterThan(strtotime($oldUpdatedAt), strtotime($updatedAt));
99142
}
100143
}

setup/performance-toolkit/benchmark.jmx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12981,6 +12981,9 @@ vars.put("admin_user", adminUser);
1298112981

1298212982
//Index of the current product from the cluster
1298312983
Random random = new Random();
12984+
if (${seedForRandom} > 0) {
12985+
random.setSeed(${seedForRandom} + ${__threadNum});
12986+
}
1298412987
int iterator = random.nextInt(clusterLength);
1298512988
if (iterator == 0) {
1298612989
iterator = 1;
@@ -32323,7 +32326,7 @@ vars.put("admin_user", adminUser);
3232332326
<stringProp name="RegexExtractor.regex">actions":\{"edit":\{"href":"(?:http|https):\\/\\/(.*?)\\/customer\\/index\\/edit\\/id\\/(\d+)\\/",</stringProp>
3232432327
<stringProp name="RegexExtractor.template">/customer/index/edit/id/$2$/</stringProp>
3232532328
<stringProp name="RegexExtractor.default"/>
32326-
<stringProp name="RegexExtractor.match_number">0</stringProp>
32329+
<stringProp name="RegexExtractor.match_number">1</stringProp>
3232732330
</RegexExtractor>
3232832331
<hashTree/>
3232932332
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Assert customer edit url" enabled="true">
@@ -34540,6 +34543,9 @@ vars.put("admin_user", adminUser);
3454034543

3454134544
//Index of the current product from the cluster
3454234545
Random random = new Random();
34546+
if (${seedForRandom} &gt; 0) {
34547+
random.setSeed(${seedForRandom} + ${__threadNum});
34548+
}
3454334549
int iterator = random.nextInt(clusterLength);
3454434550
if (iterator == 0) {
3454534551
iterator = 1;

setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9696
$indexerRegistry = $fixtureModel->getObjectManager()
9797
->create(\Magento\Framework\Indexer\IndexerRegistry::class);
9898

99+
$indexersState = [];
99100
foreach ($indexerListIds as $indexerId) {
100101
$indexer = $indexerRegistry->get($indexerId['indexer_id']);
102+
$indexersState[$indexerId['indexer_id']] = $indexer->isScheduled();
101103
$indexer->setScheduled(true);
102104
}
103105

@@ -107,6 +109,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
107109

108110
$this->clearChangelog();
109111

112+
foreach ($indexerListIds as $indexerId) {
113+
/** @var $indexer \Magento\Indexer\Model\Indexer */
114+
$indexer = $indexerRegistry->get($indexerId['indexer_id']);
115+
$indexer->setScheduled($indexersState[$indexerId['indexer_id']]);
116+
}
117+
110118
/** @var \Magento\Setup\Fixtures\IndexersStatesApplyFixture $indexerFixture */
111119
$indexerFixture = $fixtureModel
112120
->getFixtureByName(\Magento\Setup\Fixtures\IndexersStatesApplyFixture::class);

0 commit comments

Comments
 (0)