Skip to content

Commit 4979ddd

Browse files
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - magento-engcom/import-export-improvements#99: product images with same name overwrite previous image fix (by @umarch06) - magento/magento2#13784: [Forwardport] Grid filtration doesn't work for mysql special characters (by @serhii-balko) - magento/magento2#13832: [Forwardport] Add option "lock-config" for shell command "config:set" (by @nmalevanec) - magento/magento2#11572: Add The Ability To Limit Autocomplete Results (by @mpchadwick)
2 parents b71c1f2 + ce047bd commit 4979ddd

File tree

24 files changed

+540
-69
lines changed

24 files changed

+540
-69
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ protected function _saveProducts()
17121712
foreach ($rowImages as $column => $columnImages) {
17131713
foreach ($columnImages as $columnImageKey => $columnImage) {
17141714
if (!isset($uploadedImages[$columnImage])) {
1715-
$uploadedFile = $this->uploadMediaFiles($columnImage, true);
1715+
$uploadedFile = $this->uploadMediaFiles($columnImage);
17161716
$uploadedFile = $uploadedFile ?: $this->getSystemFile($columnImage);
17171717
if ($uploadedFile) {
17181718
$uploadedImages[$columnImage] = $uploadedFile;

app/code/Magento/CatalogSearch/Model/Autocomplete/DataProvider.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010
use Magento\Search\Model\QueryFactory;
1111
use Magento\Search\Model\Autocomplete\DataProviderInterface;
1212
use Magento\Search\Model\Autocomplete\ItemFactory;
13+
use Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfig;
14+
use Magento\Store\Model\ScopeInterface;
1315

1416
class DataProvider implements DataProviderInterface
1517
{
18+
/**
19+
* Autocomplete limit
20+
*/
21+
const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit';
22+
1623
/**
1724
* Query factory
1825
*
@@ -27,16 +34,29 @@ class DataProvider implements DataProviderInterface
2734
*/
2835
protected $itemFactory;
2936

37+
/**
38+
* Limit
39+
*
40+
* @var int
41+
*/
42+
protected $limit;
43+
3044
/**
3145
* @param QueryFactory $queryFactory
3246
* @param ItemFactory $itemFactory
3347
*/
3448
public function __construct(
3549
QueryFactory $queryFactory,
36-
ItemFactory $itemFactory
50+
ItemFactory $itemFactory,
51+
ScopeConfig $scopeConfig
3752
) {
3853
$this->queryFactory = $queryFactory;
3954
$this->itemFactory = $itemFactory;
55+
56+
$this->limit = (int) $scopeConfig->getValue(
57+
self::CONFIG_AUTOCOMPLETE_LIMIT,
58+
ScopeInterface::SCOPE_STORE
59+
);
4060
}
4161

4262
/**
@@ -58,7 +78,7 @@ public function getItems()
5878
$result[] = $resultItem;
5979
}
6080
}
61-
return $result;
81+
return ($this->limit) ? array_splice($result, 0, $this->limit) : $result;
6282
}
6383

6484
/**

app/code/Magento/CatalogSearch/Test/Unit/Model/Autocomplete/DataProviderTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class DataProviderTest extends \PHPUnit\Framework\TestCase
3030
*/
3131
private $suggestCollection;
3232

33+
/**
34+
* @var integer
35+
*/
36+
private $limit = 3;
37+
3338
protected function setUp()
3439
{
3540
$helper = new ObjectManager($this);
@@ -60,11 +65,20 @@ protected function setUp()
6065
->setMethods(['create'])
6166
->getMock();
6267

68+
$scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
69+
->setMethods(['getValue'])
70+
->disableOriginalConstructor()
71+
->getMockForAbstractClass();
72+
$scopeConfig->expects($this->any())
73+
->method('getValue')
74+
->willReturn($this->limit);
75+
6376
$this->model = $helper->getObject(
6477
\Magento\CatalogSearch\Model\Autocomplete\DataProvider::class,
6578
[
6679
'queryFactory' => $queryFactory,
67-
'itemFactory' => $this->itemFactory
80+
'itemFactory' => $this->itemFactory,
81+
'scopeConfig' => $scopeConfig
6882
]
6983
);
7084
}
@@ -103,8 +117,10 @@ public function testGetItems()
103117
->will($this->returnValue($expected));
104118

105119
$this->itemFactory->expects($this->any())->method('create')->willReturn($itemMock);
120+
106121
$result = $this->model->getItems();
107122
$this->assertEquals($expected, $result[0]->toArray());
123+
$this->assertEquals($this->limit, count($result));
108124
}
109125

110126
private function buildCollection(array $data)

app/code/Magento/CatalogSearch/etc/adminhtml/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<comment>Number of popular search terms to be cached for faster response. Use “0” to cache all results after a term is searched for the second time.</comment>
3333
<validate>validate-digits</validate>
3434
</field>
35+
<field id="autocomplete_limit" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
36+
<label>Autocomplete Limit</label>
37+
<validate>validate-digits</validate>
38+
</field>
3539
</group>
3640
</section>
3741
</system>

app/code/Magento/CatalogSearch/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<min_query_length>1</min_query_length>
1717
<max_query_length>128</max_query_length>
1818
<max_count_cacheable_search_terms>100</max_count_cacheable_search_terms>
19+
<autocomplete_limit>8</autocomplete_limit>
1920
</search>
2021
</catalog>
2122
</default>

app/code/Magento/Config/Console/Command/ConfigSet/ConfigSetProcessorFactory.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ class ConfigSetProcessorFactory
2828
* lock - save and lock configuration
2929
*/
3030
const TYPE_DEFAULT = 'default';
31+
32+
/**
33+
* @deprecated
34+
* @see TYPE_LOCK_ENV or TYPE_LOCK_CONFIG
35+
*/
3136
const TYPE_LOCK = 'lock';
37+
const TYPE_LOCK_ENV = 'lock-env';
38+
const TYPE_LOCK_CONFIG = 'lock-config';
3239
/**#@-*/
3340

3441
/**#@-*/

app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function process($path, $value, $scope, $scopeCode)
7272
throw new CouldNotSaveException(
7373
__(
7474
'The value you set has already been locked. To change the value, use the --%1 option.',
75-
ConfigSetCommand::OPTION_LOCK
75+
ConfigSetCommand::OPTION_LOCK_ENV
7676
)
7777
);
7878
}

app/code/Magento/Config/Console/Command/ConfigSet/LockProcessor.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
/**
1818
* Processes file lock flow of config:set command.
19-
* This processor saves the value of configuration and lock it for editing in Admin interface.
19+
* This processor saves the value of configuration into app/etc/env.php
20+
* and locks it for editing in Admin interface.
2021
*
2122
* {@inheritdoc}
2223
*/
@@ -49,23 +50,30 @@ class LockProcessor implements ConfigSetProcessorInterface
4950
* @var ConfigPathResolver
5051
*/
5152
private $configPathResolver;
53+
/**
54+
* @var string
55+
*/
56+
private $target;
5257

5358
/**
5459
* @param PreparedValueFactory $preparedValueFactory The factory for prepared value
5560
* @param DeploymentConfig\Writer $writer The deployment configuration writer
5661
* @param ArrayManager $arrayManager An array manager for different manipulations with arrays
5762
* @param ConfigPathResolver $configPathResolver The resolver for configuration paths according to source type
63+
* @param string $target
5864
*/
5965
public function __construct(
6066
PreparedValueFactory $preparedValueFactory,
6167
DeploymentConfig\Writer $writer,
6268
ArrayManager $arrayManager,
63-
ConfigPathResolver $configPathResolver
69+
ConfigPathResolver $configPathResolver,
70+
$target = ConfigFilePool::APP_ENV
6471
) {
6572
$this->preparedValueFactory = $preparedValueFactory;
6673
$this->deploymentConfigWriter = $writer;
6774
$this->arrayManager = $arrayManager;
6875
$this->configPathResolver = $configPathResolver;
76+
$this->target = $target;
6977
}
7078

7179
/**
@@ -97,7 +105,7 @@ public function process($path, $value, $scope, $scopeCode)
97105
* we'll write value just after all validations are triggered.
98106
*/
99107
$this->deploymentConfigWriter->saveConfig(
100-
[ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $value)],
108+
[$this->target => $this->arrayManager->set($configPath, [], $value)],
101109
false
102110
);
103111
}

app/code/Magento/Config/Console/Command/ConfigSet/ProcessorFacade.php

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\Config\ScopeConfigInterface;
1010
use Magento\Framework\App\Scope\ValidatorInterface;
1111
use Magento\Config\Model\Config\PathValidator;
12+
use Magento\Framework\Config\File\ConfigFilePool;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\Exception\ConfigurationMismatchException;
1415
use Magento\Framework\Exception\CouldNotSaveException;
@@ -98,27 +99,60 @@ public function __construct(
9899
* @param boolean $lock The lock flag
99100
* @return string Processor response message
100101
* @throws ValidatorException If some validation is wrong
101-
* @throws CouldNotSaveException If cannot save config value
102-
* @throws ConfigurationMismatchException If processor can not be instantiated
103102
* @since 100.2.0
103+
* @deprecated
104+
* @see processWithLockTarget()
104105
*/
105106
public function process($path, $value, $scope, $scopeCode, $lock)
106107
{
108+
return $this->processWithLockTarget($path, $value, $scope, $scopeCode, $lock);
109+
}
110+
111+
/**
112+
* Processes config:set command with the option to set a target file.
113+
*
114+
* @param string $path The configuration path in format section/group/field_name
115+
* @param string $value The configuration value
116+
* @param string $scope The configuration scope (default, website, or store)
117+
* @param string $scopeCode The scope code
118+
* @param boolean $lock The lock flag
119+
* @param string $lockTarget
120+
* @return string Processor response message
121+
* @throws ValidatorException If some validation is wrong
122+
*/
123+
public function processWithLockTarget(
124+
$path,
125+
$value,
126+
$scope,
127+
$scopeCode,
128+
$lock,
129+
$lockTarget = ConfigFilePool::APP_ENV
130+
) {
107131
try {
108132
$this->scopeValidator->isValid($scope, $scopeCode);
109133
$this->pathValidator->validate($path);
110134
} catch (LocalizedException $exception) {
111135
throw new ValidatorException(__($exception->getMessage()), $exception);
112136
}
113137

114-
$processor = $lock
115-
? $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK)
116-
: $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_DEFAULT);
117-
$message = $lock
118-
? 'Value was saved and locked.'
119-
: 'Value was saved.';
138+
$processor =
139+
$lock
140+
? ( $lockTarget == ConfigFilePool::APP_ENV
141+
? $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK_ENV)
142+
: $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK_CONFIG)
143+
)
144+
: $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_DEFAULT)
145+
;
146+
147+
$message =
148+
$lock
149+
? ( $lockTarget == ConfigFilePool::APP_ENV
150+
? 'Value was saved in app/etc/env.php and locked.'
151+
: 'Value was saved in app/etc/config.php and locked.'
152+
)
153+
: 'Value was saved.';
120154

121-
// The processing flow depends on --lock option.
155+
// The processing flow depends on --lock and --share options.
122156
$processor->process($path, $value, $scope, $scopeCode);
123157

124158
$this->hash->regenerate(System::CONFIG_TYPE);

app/code/Magento/Config/Console/Command/ConfigSetCommand.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Config\Console\Command;
78

89
use Magento\Config\App\Config\Type\System;
910
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
1011
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
1112
use Magento\Framework\App\DeploymentConfig;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\Config\File\ConfigFilePool;
1315
use Magento\Framework\Console\Cli;
1416
use Symfony\Component\Console\Command\Command;
1517
use Symfony\Component\Console\Input\InputArgument;
@@ -34,6 +36,8 @@ class ConfigSetCommand extends Command
3436
const OPTION_SCOPE = 'scope';
3537
const OPTION_SCOPE_CODE = 'scope-code';
3638
const OPTION_LOCK = 'lock';
39+
const OPTION_LOCK_ENV = 'lock-env';
40+
const OPTION_LOCK_CONFIG = 'lock-config';
3741
/**#@-*/
3842

3943
/**#@-*/
@@ -108,11 +112,24 @@ protected function configure()
108112
InputArgument::OPTIONAL,
109113
'Scope code (required only if scope is not \'default\')'
110114
),
115+
new InputOption(
116+
static::OPTION_LOCK_ENV,
117+
'le',
118+
InputOption::VALUE_NONE,
119+
'Lock value which prevents modification in the Admin (will be saved in app/etc/env.php)'
120+
),
121+
new InputOption(
122+
static::OPTION_LOCK_CONFIG,
123+
'lc',
124+
InputOption::VALUE_NONE,
125+
'Lock and share value with other installations, prevents modification in the Admin '
126+
. '(will be saved in app/etc/config.php)'
127+
),
111128
new InputOption(
112129
static::OPTION_LOCK,
113130
'l',
114131
InputOption::VALUE_NONE,
115-
'Lock value which prevents modification in the Admin'
132+
'Deprecated, use the --' . static::OPTION_LOCK_ENV . ' option instead.'
116133
),
117134
]);
118135

@@ -146,12 +163,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
146163

147164
try {
148165
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
149-
return $this->processorFacadeFactory->create()->process(
166+
167+
$lock = $input->getOption(static::OPTION_LOCK_ENV)
168+
|| $input->getOption(static::OPTION_LOCK_CONFIG)
169+
|| $input->getOption(static::OPTION_LOCK);
170+
171+
$lockTargetPath = ConfigFilePool::APP_ENV;
172+
if ($input->getOption(static::OPTION_LOCK_CONFIG)) {
173+
$lockTargetPath = ConfigFilePool::APP_CONFIG;
174+
}
175+
176+
return $this->processorFacadeFactory->create()->processWithLockTarget(
150177
$input->getArgument(static::ARG_PATH),
151178
$input->getArgument(static::ARG_VALUE),
152179
$input->getOption(static::OPTION_SCOPE),
153180
$input->getOption(static::OPTION_SCOPE_CODE),
154-
$input->getOption(static::OPTION_LOCK)
181+
$lock,
182+
$lockTargetPath
155183
);
156184
});
157185

0 commit comments

Comments
 (0)