Skip to content

Commit 9e16f80

Browse files
ACPT-820
Fixed a bug where setIds was missing in one of the AbstractEntity classes. Added a new interface, EntityInterface, for both of the AbstractEntity classes so to make it easier to avoid bugs.
1 parent f5fe742 commit 9e16f80

File tree

5 files changed

+247
-17
lines changed

5 files changed

+247
-17
lines changed

app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/Grouped/LinksTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
namespace Magento\GroupedImportExport\Test\Unit\Model\Import\Product\Type\Grouped;
1010

1111
use Magento\Catalog\Model\ResourceModel\Product\Link;
12+
use Magento\CatalogImportExport\Model\Import\Product as ProductImport;
1213
use Magento\Framework\App\ResourceConnection;
1314
use Magento\Framework\DB\Adapter\Pdo\Mysql;
1415
use Magento\Framework\DB\Select;
1516
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1617
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links;
17-
use Magento\ImportExport\Model\Import;
1818
use Magento\ImportExport\Model\ImportFactory;
1919
use Magento\ImportExport\Model\ResourceModel\Import\Data;
2020
use PHPUnit\Framework\MockObject\MockObject;
2121
use PHPUnit\Framework\TestCase;
22-
use Magento\CatalogImportExport\Model\Import\Product as ProductImport;
2322

2423
class LinksTest extends TestCase
2524
{
@@ -64,7 +63,7 @@ protected function setUp(): void
6463
]
6564
);
6665
$this->productImport = $this->createMock(ProductImport::class);
67-
$this->productImport->expects($this->any())->method('getIds')->willReturn(null);
66+
$this->productImport->expects($this->any())->method('getIds')->willReturn([]);
6867
}
6968

7069
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
use Magento\ImportExport\Model\Import\ConfigInterface;
2929
use Magento\ImportExport\Model\Import\Entity\AbstractEntity;
3030
use Magento\ImportExport\Model\Import\Entity\Factory;
31+
use Magento\ImportExport\Model\Import\EntityInterface;
3132
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
3233
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
33-
use Magento\ImportExport\Model\Import\Source\Base64EncodedCsvData;
3434
use Magento\ImportExport\Model\ResourceModel\Import\Data;
3535
use Magento\ImportExport\Model\Source\Import\AbstractBehavior;
3636
use Magento\ImportExport\Model\Source\Import\Behavior\Factory as BehaviorFactory;
@@ -123,7 +123,7 @@ class Import extends AbstractModel
123123
public const IMPORT_DIR = 'import/';
124124

125125
/**
126-
* @var AbstractEntity|ImportAbstractEntity
126+
* @var EntityInterface
127127
*/
128128
protected $_entityAdapter;
129129

@@ -277,7 +277,7 @@ public function __construct(
277277
* Create instance of entity adapter and return it
278278
*
279279
* @throws LocalizedException
280-
* @return AbstractEntity|ImportAbstractEntity
280+
* @return EntityInterface
281281
*/
282282
protected function _getEntityAdapter()
283283
{

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use Magento\ImportExport\Model\Import;
1515
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
1616
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
17-
use Magento\ImportExport\Model\Import\Source\Base64EncodedCsvData;
1817
use Magento\ImportExport\Model\ImportFactory;
1918
use Magento\ImportExport\Model\ResourceModel\Helper;
19+
use Magento\ImportExport\Model\ResourceModel\Import\Data as DataSourceModel;
2020
use Magento\Store\Model\ScopeInterface;
2121

2222
/**
@@ -28,7 +28,7 @@
2828
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2929
* @since 100.0.2
3030
*/
31-
abstract class AbstractEntity
31+
abstract class AbstractEntity implements EntityInterface
3232
{
3333
/**
3434
* Custom row import behavior column name
@@ -121,7 +121,7 @@ abstract class AbstractEntity
121121
/**
122122
* DB data source model
123123
*
124-
* @var \Magento\ImportExport\Model\ResourceModel\Import\Data
124+
* @var DataSourceModel
125125
*/
126126
protected $_dataSourceModel;
127127

@@ -912,8 +912,29 @@ public function getValidColumnNames()
912912
*
913913
* @return array
914914
*/
915-
public function getIds()
915+
public function getIds() : array
916916
{
917917
return $this->ids;
918918
}
919+
920+
/**
921+
* Set Ids of Validated Rows
922+
*
923+
* @param array $ids
924+
* @return void
925+
*/
926+
public function setIds(array $ids)
927+
{
928+
$this->ids = $ids;
929+
}
930+
931+
/**
932+
* Gets the currently used DataSourceModel
933+
*
934+
* @return DataSourceModel
935+
*/
936+
public function getDataSourceModel() : DataSourceModel
937+
{
938+
return $this->_dataSourceModel;
939+
}
919940
}

app/code/Magento/ImportExport/Model/Import/Entity/AbstractEntity.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
use Magento\Framework\App\ResourceConnection;
1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\Serialize\Serializer\Json;
12-
use Magento\ImportExport\Model\Import\AbstractSource;
1312
use Magento\ImportExport\Model\Import as ImportExport;
13+
use Magento\ImportExport\Model\Import\AbstractSource;
14+
use Magento\ImportExport\Model\Import\EntityInterface;
1415
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
1516
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
16-
use Magento\ImportExport\Model\Import\Source\Base64EncodedCsvData;
17+
use Magento\ImportExport\Model\ResourceModel\Import\Data as DataSourceModel;
1718

1819
/**
1920
* Import entity abstract model
@@ -25,7 +26,7 @@
2526
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2627
* @since 100.0.2
2728
*/
28-
abstract class AbstractEntity
29+
abstract class AbstractEntity implements EntityInterface
2930
{
3031
/**
3132
* Database constants
@@ -102,7 +103,7 @@ abstract class AbstractEntity
102103
/**
103104
* DB data source model.
104105
*
105-
* @var \Magento\ImportExport\Model\ResourceModel\Import\Data
106+
* @var DataSourceModel
106107
*/
107108
protected $_dataSourceModel;
108109

@@ -902,7 +903,7 @@ protected function getMetadataPool()
902903
*
903904
* @return array
904905
*/
905-
public function getIds()
906+
public function getIds() : array
906907
{
907908
return $this->ids;
908909
}
@@ -921,9 +922,9 @@ public function setIds(array $ids)
921922
/**
922923
* Gets the currently used DataSourceModel
923924
*
924-
* @return array
925+
* @return DataSourceModel
925926
*/
926-
public function getDataSourceModel()
927+
public function getDataSourceModel() : DataSourceModel
927928
{
928929
return $this->_dataSourceModel;
929930
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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\ImportExport\Model\Import;
9+
10+
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
11+
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
12+
use Magento\ImportExport\Model\ResourceModel\Import\Data as DataSourceModel;
13+
14+
/**
15+
* Import entity interface
16+
*
17+
* @api
18+
*/
19+
interface EntityInterface
20+
{
21+
22+
/**
23+
* Returns Error aggregator
24+
*
25+
* @return ProcessingErrorAggregatorInterface
26+
*/
27+
public function getErrorAggregator();
28+
29+
/**
30+
* Imported entity type code getter
31+
*
32+
* @abstract
33+
* @return string
34+
*/
35+
public function getEntityTypeCode();
36+
37+
/**
38+
* Add error with corresponding current data source row number.
39+
*
40+
* @param string $errorCode Error code or simply column name
41+
* @param int $errorRowNum Row number.
42+
* @param string $colName OPTIONAL Column name.
43+
* @param string $errorMessage OPTIONAL Column name.
44+
* @param string $errorLevel
45+
* @param string $errorDescription
46+
* @return $this
47+
*/
48+
public function addRowError(
49+
$errorCode,
50+
$errorRowNum,
51+
$colName = null,
52+
$errorMessage = null,
53+
$errorLevel = ProcessingError::ERROR_LEVEL_CRITICAL,
54+
$errorDescription = null
55+
);
56+
57+
/**
58+
* Add message template for specific error code from outside
59+
*
60+
* @param string $errorCode Error code
61+
* @param string $message Message template
62+
* @return $this
63+
*/
64+
public function addMessageTemplate($errorCode, $message);
65+
66+
/**
67+
* Returns number of checked entities
68+
*
69+
* @return int
70+
*/
71+
public function getProcessedEntitiesCount();
72+
73+
/**
74+
* Returns number of checked rows
75+
*
76+
* @return int
77+
*/
78+
public function getProcessedRowsCount();
79+
80+
/**
81+
* Source object getter
82+
*
83+
* @return AbstractSource
84+
* @throws \Magento\Framework\Exception\LocalizedException
85+
*/
86+
public function getSource();
87+
88+
/**
89+
* Import process start
90+
*
91+
* @return bool Result of operation
92+
*/
93+
public function importData();
94+
95+
/**
96+
* Is attribute contains particular data (not plain entity attribute)
97+
*
98+
* @param string $attributeCode
99+
* @return bool
100+
*/
101+
public function isAttributeParticular($attributeCode);
102+
103+
/**
104+
* Import possibility getter
105+
*
106+
* @return bool
107+
*/
108+
public function isImportAllowed();
109+
110+
/**
111+
* Returns TRUE if row is valid and not in skipped rows array
112+
*
113+
* @param array $rowData
114+
* @param int $rowNumber
115+
* @return bool
116+
*/
117+
public function isRowAllowedToImport(array $rowData, $rowNumber);
118+
119+
/**
120+
* Is import need to log in history.
121+
*
122+
* @return bool
123+
*/
124+
public function isNeedToLogInHistory();
125+
126+
/**
127+
* Validate data row
128+
*
129+
* @param array $rowData
130+
* @param int $rowNumber
131+
* @return bool
132+
*/
133+
public function validateRow(array $rowData, $rowNumber);
134+
135+
/**
136+
* Set data from outside to change behavior
137+
*
138+
* @param array $parameters
139+
* @return $this
140+
*/
141+
public function setParameters(array $parameters);
142+
143+
/**
144+
* Source model setter
145+
*
146+
* @param AbstractSource $source
147+
* @return $this
148+
*/
149+
public function setSource(AbstractSource $source);
150+
151+
/**
152+
* Validate data
153+
*
154+
* @return ProcessingErrorAggregatorInterface
155+
* @throws \Magento\Framework\Exception\LocalizedException
156+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
157+
*/
158+
public function validateData();
159+
160+
/**
161+
* Get count of created items
162+
*
163+
* @return int
164+
*/
165+
public function getCreatedItemsCount();
166+
167+
/**
168+
* Get count of updated items
169+
*
170+
* @return int
171+
*/
172+
public function getUpdatedItemsCount();
173+
174+
/**
175+
* Get count of deleted items
176+
*
177+
* @return int
178+
*/
179+
public function getDeletedItemsCount();
180+
181+
/**
182+
* Retrieve valid column names
183+
*
184+
* @return array
185+
*/
186+
public function getValidColumnNames();
187+
188+
/**
189+
* Retrieve Ids of Validated Rows
190+
*
191+
* @return array
192+
*/
193+
public function getIds() : array;
194+
195+
/**
196+
* Set Ids of Validated Rows
197+
*
198+
* @param array $ids
199+
* @return void
200+
*/
201+
public function setIds(array $ids);
202+
203+
/**
204+
* Gets the currently used DataSourceModel
205+
*
206+
* @return array
207+
*/
208+
public function getDataSourceModel() : DataSourceModel;
209+
}

0 commit comments

Comments
 (0)