Skip to content

Commit 84cf488

Browse files
author
Igor Melnikov
committed
MAGETWO-66331: Implement solution to update duplicate rows at once and add environment variable to control batch size
- refactoring object manager initialization, environment variable validation
1 parent 1a208f2 commit 84cf488

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

lib/internal/Magento/Framework/DB/FieldDataConverter.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ class FieldDataConverter
2626
*/
2727
const DEFAULT_BATCH_SIZE = 50000;
2828

29-
/**
30-
* Min batch size
31-
*/
32-
const MIN_BATCH_SIZE = 25000;
33-
34-
/**
35-
* Max batch size
36-
*/
37-
const MAX_BATCH_SIZE = 500000;
38-
3929
/**
4030
* @var Generator
4131
*/
@@ -141,10 +131,10 @@ private function getBatchSize()
141131
{
142132
if (null !== $this->envBatchSize) {
143133
$batchSize = (int) $this->envBatchSize;
144-
if ($batchSize < self::MIN_BATCH_SIZE || $batchSize > self::MAX_BATCH_SIZE) {
134+
if (bccomp($this->envBatchSize, PHP_INT_MAX, 0) === 1 || $batchSize < 1) {
145135
throw new \InvalidArgumentException(
146136
'Invalid value for environment variable ' . self::BATCH_SIZE_VARIABLE_NAME . '. '
147-
. 'Should be integer and be > ' . self::MIN_BATCH_SIZE . ', < ' . self::MAX_BATCH_SIZE
137+
. 'Should be integer, >= 1 and < value of PHP_INT_MAX'
148138
);
149139
}
150140
return $batchSize;

lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function convertBatchSizeFromEnvDataProvider()
209209
* @param string|int $batchSize
210210
* @expectedException \InvalidArgumentException
211211
* @codingStandardsIgnoreStart
212-
* @expectedExceptionMessage Invalid value for environment variable DATA_CONVERTER_BATCH_SIZE. Should be integer and be > 25000, < 500000
212+
* @expectedExceptionMessage Invalid value for environment variable DATA_CONVERTER_BATCH_SIZE. Should be integer, >= 1 and < value of PHP_INT_MAX
213213
* @codingStandardsIgnoreEnd
214214
* @dataProvider convertBatchSizeFromEnvInvalidDataProvider
215215
*/
@@ -258,7 +258,7 @@ public function convertBatchSizeFromEnvInvalidDataProvider()
258258
{
259259
return [
260260
['value'],
261-
[500001],
261+
[bcadd(PHP_INT_MAX, 1)],
262262
];
263263
}
264264
}

setup/config/autoload/global.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
1010

1111
return [
12-
InitParamListener::BOOTSTRAP_PARAM => [
13-
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => [DirectoryList::ROOT => [DirectoryList::PATH => BP]],
14-
]
12+
InitParamListener::BOOTSTRAP_PARAM => array_merge(
13+
$_SERVER,
14+
[
15+
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => [
16+
DirectoryList::ROOT => [
17+
DirectoryList::PATH => BP
18+
]
19+
]
20+
]
21+
)
1522
];

setup/src/Magento/Setup/Model/ObjectManagerProvider.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ public function __construct(
5757
public function get()
5858
{
5959
if (null === $this->objectManager) {
60-
$initParams = array_merge(
61-
$this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM),
62-
$_SERVER
63-
);
60+
$initParams = $this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM);
6461
$factory = $this->getObjectManagerFactory($initParams);
6562
$this->objectManager = $factory->create($initParams);
6663
if (PHP_SAPI == 'cli') {

setup/src/Magento/Setup/Test/Unit/Model/ObjectManagerProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function setUp()
4646

4747
public function testGet()
4848
{
49-
$initParams = array_merge(['param' => 'value'], $_SERVER);
49+
$initParams = ['param' => 'value'];
5050

5151
$this->serviceLocatorMock
5252
->expects($this->atLeastOnce())

0 commit comments

Comments
 (0)