Skip to content

Commit d0d343e

Browse files
[EngCom] Public Pull Requests - 2.1-develop
- merged latest code from mainline branch
2 parents e0c47c5 + 1240bed commit d0d343e

File tree

72 files changed

+24268
-21939
lines changed

Some content is hidden

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

72 files changed

+24268
-21939
lines changed

app/code/Magento/Catalog/Block/Product/ImageBuilder.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22
/**
3-
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
* Copyright © 2013-2018 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Catalog\Block\Product;
77

88
use Magento\Catalog\Helper\ImageFactory as HelperFactory;
9+
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
910

1011
class ImageBuilder
1112
{
@@ -129,7 +130,11 @@ public function create()
129130
? 'Magento_Catalog::product/image.phtml'
130131
: 'Magento_Catalog::product/image_with_borders.phtml';
131132

132-
$imagesize = $helper->getResizedImageInfo();
133+
try {
134+
$imagesize = $helper->getResizedImageInfo();
135+
} catch (NotLoadInfoImageException $exception) {
136+
$imagesize = [$helper->getWidth(), $helper->getHeight()];
137+
}
133138

134139
$data = [
135140
'data' => [
@@ -140,8 +145,8 @@ public function create()
140145
'label' => $helper->getLabel(),
141146
'ratio' => $this->getRatio($helper),
142147
'custom_attributes' => $this->getCustomAttributes(),
143-
'resized_image_width' => !empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth(),
144-
'resized_image_height' => !empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight(),
148+
'resized_image_width' => $imagesize[0],
149+
'resized_image_height' => $imagesize[1],
145150
],
146151
];
147152

app/code/Magento/Catalog/Model/Product/Image.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
* Copyright © 2013-2018 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

@@ -11,6 +11,7 @@
1111
*/
1212
namespace Magento\Catalog\Model\Product;
1313

14+
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
1415
use Magento\Framework\App\Filesystem\DirectoryList;
1516
use Magento\Framework\Image as MagentoImage;
1617
use Magento\Store\Model\Store;
@@ -936,21 +937,29 @@ protected function _fileExists($filename)
936937
* Return resized product image information
937938
*
938939
* @return array
940+
* @throws NotLoadInfoImageException
939941
*/
940942
public function getResizedImageInfo()
941943
{
942-
$fileInfo = null;
943-
if ($this->_newFile === true) {
944-
$asset = $this->_assetRepo->createAsset(
945-
"Magento_Catalog::images/product/placeholder/{$this->getDestinationSubdir()}.jpg"
946-
);
947-
$img = $asset->getSourceFile();
948-
$fileInfo = getimagesize($img);
949-
} else {
950-
if ($this->_mediaDirectory->isFile($this->_mediaDirectory->getAbsolutePath($this->_newFile))) {
951-
$fileInfo = getimagesize($this->_mediaDirectory->getAbsolutePath($this->_newFile));
944+
try {
945+
$fileInfo = null;
946+
if ($this->_newFile === true) {
947+
$asset = $this->_assetRepo->createAsset(
948+
"Magento_Catalog::images/product/placeholder/{$this->getDestinationSubdir()}.jpg"
949+
);
950+
$image = $asset->getSourceFile();
951+
$fileInfo = getimagesize($image);
952+
} else {
953+
$image = $this->_mediaDirectory->getAbsolutePath($this->_newFile);
954+
if ($this->_mediaDirectory->isFile($image)) {
955+
$fileInfo = getimagesize($image);
956+
}
957+
}
958+
return $fileInfo;
959+
} finally {
960+
if (empty($fileInfo)) {
961+
throw new NotLoadInfoImageException(__('Can\'t get information about the picture: %1', $image));
952962
}
953963
}
954-
return $fileInfo;
955964
}
956965
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2018 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Product\Image;
7+
8+
class NotLoadInfoImageException extends \Exception
9+
{
10+
}

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

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

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/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/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
5656
/**
5757
* @var string|null
5858
*/
59-
private $order = null;
59+
private $relevanceOrderDirection = null;
6060

6161
/**
6262
* @var string
@@ -345,9 +345,19 @@ protected function _renderFiltersBefore()
345345

346346
$this->_totalRecords = $this->searchResult->getTotalCount();
347347

348-
if ($this->order && 'relevance' === $this->order['field']) {
349-
$this->getSelect()->order('search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
348+
if ($this->relevanceOrderDirection) {
349+
$this->getSelect()->order(
350+
'search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->relevanceOrderDirection
351+
);
350352
}
353+
354+
/*
355+
* This order is required to force search results be the same
356+
* for the same requests and products with the same relevance
357+
* NOTE: this does not replace existing orders but ADDs one more
358+
*/
359+
$this->setOrder('entity_id');
360+
351361
return parent::_renderFiltersBefore();
352362
}
353363

@@ -369,10 +379,12 @@ protected function _renderFilters()
369379
*/
370380
public function setOrder($attribute, $dir = Select::SQL_DESC)
371381
{
372-
$this->order = ['field' => $attribute, 'dir' => $dir];
373-
if ($attribute != 'relevance') {
382+
if ($attribute === 'relevance') {
383+
$this->relevanceOrderDirection = $dir;
384+
} else {
374385
parent::setOrder($attribute, $dir);
375386
}
387+
376388
return $this;
377389
}
378390

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

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class AdminSessionsManager
5858
*/
5959
private $remoteAddress;
6060

61+
/**
62+
* Max lifetime for session prolong to be valid (sec)
63+
*
64+
* Means that after session was prolonged
65+
* all other prolongs will be ignored within this period
66+
*/
67+
private $maxIntervalBetweenConsecutiveProlongs = 60;
68+
6169
/**
6270
* @param ConfigInterface $securityConfig
6371
* @param \Magento\Backend\Model\Auth\Session $authSession
@@ -114,11 +122,16 @@ public function processLogin()
114122
*/
115123
public function processProlong()
116124
{
117-
$this->getCurrentSession()->setData(
118-
'updated_at',
119-
$this->authSession->getUpdatedAt()
120-
);
121-
$this->getCurrentSession()->save();
125+
if ($this->lastProlongIsOldEnough()) {
126+
$this->getCurrentSession()->setData(
127+
'updated_at',
128+
date(
129+
\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT,
130+
$this->authSession->getUpdatedAt()
131+
)
132+
);
133+
$this->getCurrentSession()->save();
134+
}
122135

123136
return $this;
124137
}
@@ -279,4 +292,45 @@ protected function createAdminSessionInfoCollection()
279292
{
280293
return $this->adminSessionInfoCollectionFactory->create();
281294
}
295+
296+
/**
297+
* Calculates diff between now and last session updated_at
298+
* and decides whether new prolong must be triggered or not
299+
*
300+
* This is done to limit amount of session prolongs and updates to database
301+
* within some period of time - X
302+
* X - is calculated in getIntervalBetweenConsecutiveProlongs()
303+
*
304+
* @see getIntervalBetweenConsecutiveProlongs()
305+
* @return bool
306+
*/
307+
private function lastProlongIsOldEnough()
308+
{
309+
$lastProlongTimestamp = strtotime($this->getCurrentSession()->getUpdatedAt());
310+
$nowTimestamp = $this->authSession->getUpdatedAt();
311+
312+
$diff = $nowTimestamp - $lastProlongTimestamp;
313+
314+
return (float) $diff > $this->getIntervalBetweenConsecutiveProlongs();
315+
}
316+
317+
/**
318+
* Calculates lifetime for session prolong to be valid
319+
*
320+
* Calculation is based on admin session lifetime
321+
* Calculated result is in seconds and is in the interval
322+
* between 1 (including) and MAX_INTERVAL_BETWEEN_CONSECUTIVE_PROLONGS (including)
323+
*
324+
* @return float
325+
*/
326+
private function getIntervalBetweenConsecutiveProlongs()
327+
{
328+
return (float) max(
329+
1,
330+
min(
331+
log((float)$this->securityConfig->getAdminSessionLifetime()),
332+
$this->maxIntervalBetweenConsecutiveProlongs
333+
)
334+
);
335+
}
282336
}

0 commit comments

Comments
 (0)