Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit bffe557

Browse files
committed
MSI: Update Magento 2 core to support MSI
1 parent 36098f4 commit bffe557

File tree

10 files changed

+211
-26
lines changed

10 files changed

+211
-26
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
536536

537537
/**
538538
* @var \Magento\CatalogInventory\Model\ResourceModel\Stock\ItemFactory
539+
* @deprecated
539540
*/
540541
protected $_stockResItemFac;
541542

@@ -707,7 +708,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
707708
/**
708709
* Stock Item Importer
709710
*
710-
* @var StockItemImporterInterface $stockItemImporter
711+
* @var StockItemImporterInterface
711712
*/
712713
private $stockItemImporter;
713714

@@ -759,13 +760,13 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
759760
* @param TransactionManagerInterface $transactionManager
760761
* @param Product\TaxClassProcessor $taxClassProcessor
761762
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
763+
* @param \Magento\Catalog\Model\Product\Url $productUrl
762764
* @param array $data
763765
* @param array $dateAttrCodes
764766
* @param CatalogConfig $catalogConfig
765-
* @param StockItemImporterInterface $stockItemImporter
766767
* @param ImageTypeProcessor $imageTypeProcessor
767768
* @param MediaGalleryProcessor $mediaProcessor
768-
* @throws \Magento\Framework\Exception\LocalizedException
769+
* @param StockItemImporterInterface|null $stockItemImporter
769770
*
770771
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
771772
*/

app/code/Magento/CatalogImportExport/Model/StockItemImporter.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ public function __construct(
4141
}
4242

4343
/**
44-
* Handle Import of Stock Item Data
45-
*
46-
* @param array $stockData
47-
* @return void
48-
* @throws CouldNotSaveException
44+
* @inheritdoc
4945
*/
5046
public function import(array $stockData)
5147
{

app/code/Magento/ImportExport/Controller/Adminhtml/Import/Download.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Framework\Component\ComponentRegistrar;
10+
use Magento\Framework\Controller\Result\Redirect;
1011
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\ImportExport\Controller\Adminhtml\Import as ImportController;
1213

@@ -43,14 +44,12 @@ class Download extends ImportController
4344
private $sampleFileProvider;
4445

4546
/**
46-
* Constructor
47-
*
4847
* @param \Magento\Backend\App\Action\Context $context
4948
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
5049
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
5150
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
52-
* @param \Magento\ImportExport\Model\Import\SampleFileProvider $sampleFileProvider
5351
* @param ComponentRegistrar $componentRegistrar
52+
* @param \Magento\ImportExport\Model\Import\SampleFileProvider|null $sampleFileProvider
5453
*/
5554
public function __construct(
5655
\Magento\Backend\App\Action\Context $context,
@@ -81,14 +80,19 @@ public function execute()
8180
{
8281
$entityName = $this->getRequest()->getParam('filename');
8382

83+
if (preg_match('/^\w+$/', $entityName) == 0) {
84+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
85+
$this->messageManager->addErrorMessage(__('Incorrect file name.'));
86+
87+
return $this->getResultRedirect(); }
88+
8489
try {
8590
$fileContents = $this->sampleFileProvider->getFileContents($entityName);
8691
} catch (NoSuchEntityException $e) {
8792
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
8893
$this->messageManager->addError(__('There is no sample file for this entity.'));
89-
$resultRedirect = $this->resultRedirectFactory->create();
90-
$resultRedirect->setPath('*/import');
91-
return $resultRedirect;
94+
95+
return $this->getResultRedirect();
9296
}
9397

9498
$fileSize = $this->sampleFileProvider->getSize($entityName);
@@ -107,4 +111,15 @@ public function execute()
107111
$resultRaw->setContents($fileContents);
108112
return $resultRaw;
109113
}
114+
115+
/**
116+
* @return Redirect
117+
*/
118+
private function getResultRedirect(): Redirect
119+
{
120+
$resultRedirect = $this->resultRedirectFactory->create();
121+
$resultRedirect->setPath('*/import');
122+
123+
return $resultRedirect;
124+
}
110125
}

app/code/Magento/ImportExport/Model/Import/SampleFileProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
use Magento\Framework\Filesystem\Directory\ReadInterface;
1111

1212
/**
13-
* Import Sample File Provider model
13+
* Import Sample File Provider model.
14+
* This class support only *.csv.
1415
*/
1516
class SampleFileProvider
1617
{
@@ -78,7 +79,7 @@ public function getFileContents(string $entityName): string
7879
}
7980

8081
/**
81-
* @param $entityName
82+
* @param string $entityName
8283
* @return string $entityName
8384
* @throws NoSuchEntityException
8485
*/

dev/tests/api-functional/phpunit_rest.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
<exclude>testsuite/Magento/GraphQl</exclude>
2222
<directory suffix="Test.php">../../../app/code/*/*/Test/Api</directory>
2323
</testsuite>
24-
<testsuite name="msi">
25-
<directory suffix="Test.php">../../../app/code/*/*/Test/Api</directory>
26-
</testsuite>
2724
</testsuites>
2825

2926
<!-- PHP INI settings and constants definition -->
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Model\ResourceModel;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Model\AbstractModel;
12+
13+
/**
14+
* Provides possibility of saving entity with predefined/pre-generated id
15+
*
16+
* The choice to use trait instead of inheritance was made to prevent the introduction of new layer super type on
17+
* the module basis as well as better code reusability, as potentially current trait not coupled to Inventory module
18+
* and other modules could re-use this approach.
19+
*/
20+
trait PredefinedId
21+
{
22+
/**
23+
* Overwrite default \Magento\Framework\Model\ResourceModel\Db\AbstractDb implementation of the isObjectNew
24+
* @see \Magento\Framework\Model\ResourceModel\Db\AbstractDb::isObjectNew()
25+
*
26+
* Adding the possibility to check whether record already exists in DB or not
27+
*
28+
* @param AbstractModel $object
29+
* @return bool
30+
*/
31+
protected function isObjectNotNew(AbstractModel $object)
32+
{
33+
$connection = $this->getConnection();
34+
$select = $connection->select()
35+
->from($this->getMainTable(), [$this->getIdFieldName()])
36+
->where($this->getIdFieldName() . ' = ?', $object->getId())
37+
->limit(1);
38+
return (bool)$connection->fetchOne($select);
39+
}
40+
41+
/**
42+
* Save New Object
43+
*
44+
* Overwrite default \Magento\Framework\Model\ResourceModel\Db\AbstractDb implementation of the saveNewObject
45+
* @see \Magento\Framework\Model\ResourceModel\Db\AbstractDb::saveNewObject()
46+
*
47+
* @param \Magento\Framework\Model\AbstractModel $object
48+
* @throws LocalizedException
49+
* @return void
50+
*/
51+
protected function saveNewObject(\Magento\Framework\Model\AbstractModel $object)
52+
{
53+
$bind = $this->_prepareDataForSave($object);
54+
$this->getConnection()->insert($this->getMainTable(), $bind);
55+
56+
if ($this->_isPkAutoIncrement) {
57+
$object->setId($this->getConnection()->lastInsertId($this->getMainTable()));
58+
}
59+
60+
if ($this->_useIsObjectNew) {
61+
$object->isObjectNew(false);
62+
}
63+
}
64+
}

lib/internal/Magento/Framework/MultiDimensionalIndexer/IndexName.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Framework\MultiDimensionalIndexer;
99

10+
use Magento\Framework\Exception\LocalizedException;
11+
1012
/**
1113
* Index Name object
1214
*
@@ -33,9 +35,19 @@ class IndexName
3335
* @param string $indexId
3436
* @param Dimension[] $dimensions
3537
* @param Alias $alias
38+
*
39+
* @throws LocalizedException
3640
*/
3741
public function __construct(string $indexId, array $dimensions, Alias $alias)
3842
{
43+
foreach ($dimensions as $dimension) {
44+
if (!$dimension instanceof Dimension) {
45+
throw new LocalizedException(
46+
__('Dimension have to be instance of Dimension class.')
47+
);
48+
}
49+
}
50+
3951
$this->indexId = $indexId;
4052
$this->dimensions = $dimensions;
4153
$this->alias = $alias;

lib/internal/Magento/Framework/MultiDimensionalIndexer/IndexNameBuilder.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,16 @@ class IndexNameBuilder
1818
{
1919
/**
2020
* Index id parameter name. Used internally in this object
21-
*
22-
* Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
2321
*/
2422
private static $indexId = 'indexId';
2523

2624
/**
2725
* Dimensions parameter name. Used internally in this object
28-
*
29-
* Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
3026
*/
3127
private static $dimensions = 'dimensions';
3228

3329
/**
3430
* Alias parameter name. Used internally in this object
35-
*
36-
* Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
3731
*/
3832
private static $alias = 'alias';
3933

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
MultiDimensionalIndexer
1+
A library for multi dimensional indexing processing
2+
3+
it's supposed to split indexes by the Dimensional (Scope). Builds independent index table per each Dimensional.
4+
Dimension and Alias objects help to resolve correct index.
5+
6+
Contains switchable indexes to switch from an old index (current index, which exists before full reindex operation
7+
has been launched) to a new index (created when the full reindex operation finished) with zero downtime to make
8+
Front-End responsive while Full Reindex being worked.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Test\Unit\MultiDimensionalIndexer;
8+
9+
use Magento\Framework\App\ResourceConnection;
10+
use Magento\Framework\DB\Adapter\AdapterInterface;
11+
use Magento\Framework\MultiDimensionalIndexer\IndexName;
12+
use Magento\Framework\MultiDimensionalIndexer\IndexNameResolverInterface;
13+
use Magento\Framework\MultiDimensionalIndexer\IndexTableSwitcher;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Test for @see IndexTableSwitcher.
19+
*/
20+
class IndexTableSwitcherTest extends TestCase
21+
{
22+
/**
23+
* @var IndexTableSwitcher|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $indexTableSwitcher;
26+
27+
/**
28+
* @var IndexName|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $indexName;
31+
32+
/**
33+
* @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $resourceConnection;
36+
37+
/**
38+
* @var IndexNameResolverInterface|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $indexNameResolver;
41+
42+
/**
43+
* @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
44+
*/
45+
private $adapter;
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
protected function setUp()
51+
{
52+
parent::setUp();
53+
54+
$objectManager = new ObjectManager($this);
55+
$this->indexName = $this->createMock(IndexName::class);
56+
$this->resourceConnection = $this->createMock(ResourceConnection::class);
57+
$this->indexNameResolver = $this->createMock(IndexNameResolverInterface::class);
58+
$this->adapter = $this->createMock(AdapterInterface::class);
59+
60+
$this->indexTableSwitcher = $objectManager->getObject(
61+
IndexTableSwitcher::class,
62+
[
63+
'resourceConnection' => $this->resourceConnection,
64+
'indexNameResolver' => $this->indexNameResolver,
65+
]
66+
);
67+
}
68+
69+
public function testSwitch()
70+
{
71+
$connectionName = 'testConnection';
72+
$tableName = 'some_table_name';
73+
$toRename =
74+
[
75+
[
76+
'oldName' => $tableName,
77+
'newName' => $tableName . '_outdated',
78+
],
79+
[
80+
'oldName' => $tableName . '_replica',
81+
'newName' => $tableName,
82+
],
83+
[
84+
'oldName' => $tableName . '_outdated',
85+
'newName' => $tableName . '_replica',
86+
],
87+
];
88+
89+
$this->resourceConnection->expects($this->once())->method('getConnection')
90+
->with($connectionName)->willReturn($this->adapter);
91+
$this->indexNameResolver->expects($this->once())->method('resolveName')
92+
->with($this->indexName)->willReturn($tableName);
93+
$this->adapter->expects($this->once())->method('renameTablesBatch')
94+
->with($toRename);
95+
96+
$this->indexTableSwitcher->switch($this->indexName, $connectionName);
97+
}
98+
}

0 commit comments

Comments
 (0)