Skip to content

Commit cd34e81

Browse files
author
Valeriy Nayda
committed
MSI: slight refactoring
1 parent 77a1059 commit cd34e81

File tree

16 files changed

+37
-37
lines changed

16 files changed

+37
-37
lines changed

app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ public function process($stockId, array $stockSourceLinksData)
8888
}
8989

9090
if ($sourceIdsForSave) {
91-
$this->assignSourcesToStock->execute($stockId, array_keys($sourceIdsForSave));
91+
$this->assignSourcesToStock->execute(array_keys($sourceIdsForSave), $stockId);
9292
}
9393
if ($sourceIdsForDelete) {
9494
foreach ($sourceIdsForDelete as $sourceIdForDelete) {
95-
$this->unassignSourceFromStock->execute($stockId, $sourceIdForDelete);
95+
$this->unassignSourceFromStock->execute($sourceIdForDelete, $stockId);
9696
}
9797
}
9898
}

app/code/Magento/Inventory/Model/ResourceModel/StockSourceLink/SaveMultiple.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
* @param array $sourceIds
3737
* @return void
3838
*/
39-
public function execute($stockId, array $sourceIds)
39+
public function execute(array $sourceIds, $stockId)
4040
{
4141
$connection = $this->connection->getConnection();
4242
$tableName = $connection->getTableName(StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK);

app/code/Magento/Inventory/Model/Source/Command/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function execute(SourceInterface $source)
5555
$validationResult = $this->sourceValidator->validate($source);
5656

5757
if (!$validationResult->isValid()) {
58-
throw new ValidationException($validationResult->getErrors());
58+
throw new ValidationException($validationResult);
5959
}
6060

6161
// TODO: check if exists?

app/code/Magento/Inventory/Model/SourceItemSave.php renamed to app/code/Magento/Inventory/Model/SourceItem/Command/SourceItemsSave.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Inventory\Model;
6+
namespace Magento\Inventory\Model\SourceItem\Command;
77

88
use Magento\Framework\Exception\CouldNotSaveException;
99
use Magento\Framework\Exception\InputException;
1010
use Magento\Inventory\Model\ResourceModel\SourceItem\SaveMultiple;
11-
use Magento\InventoryApi\Api\SourceItemSaveInterface;
11+
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
1212
use Psr\Log\LoggerInterface;
1313

1414
/**
1515
* @inheritdoc
1616
*/
17-
class SourceItemSave implements SourceItemSaveInterface
17+
class SourceItemsSave implements SourceItemsSaveInterface
1818
{
1919
/**
2020
* @var SaveMultiple

app/code/Magento/Inventory/Model/Stock/Command/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function execute(StockInterface $stock)
5454
{
5555
$validationResult = $this->stockValidator->validate($stock);
5656
if (!$validationResult->isValid()) {
57-
throw new ValidationException($validationResult->getErrors());
57+
throw new ValidationException($validationResult);
5858
}
5959

6060
try {

app/code/Magento/Inventory/Model/AssignSourcesToStock.php renamed to app/code/Magento/Inventory/Model/StockSourceLink/Command/AssignSourcesToStock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Inventory\Model;
6+
namespace Magento\Inventory\Model\StockSourceLink\Command;
77

88
use Magento\Framework\Exception\CouldNotSaveException;
99
use Magento\Framework\Exception\InputException;
@@ -41,13 +41,13 @@ public function __construct(
4141
/**
4242
* @inheritdoc
4343
*/
44-
public function execute($stockId, array $sourceIds)
44+
public function execute(array $sourceIds, $stockId)
4545
{
4646
if (!is_numeric($stockId) || empty($sourceIds)) {
4747
throw new InputException(__('Input data is invalid'));
4848
}
4949
try {
50-
$this->saveMultiple->execute($stockId, $sourceIds);
50+
$this->saveMultiple->execute($sourceIds, $stockId);
5151
} catch (\Exception $e) {
5252
$this->logger->error($e->getMessage());
5353
throw new CouldNotSaveException(__('Could not assign Sources to Stock'), $e);

app/code/Magento/Inventory/Model/GetAssignedSourcesForStock.php renamed to app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Inventory\Model;
6+
namespace Magento\Inventory\Model\StockSourceLink\Command;
77

88
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
99
use Magento\Framework\Api\SearchCriteriaBuilder;

app/code/Magento/Inventory/Model/UnassignSourceFromStock.php renamed to app/code/Magento/Inventory/Model/StockSourceLink/Command/UnassignSourceFromStock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Inventory\Model;
6+
namespace Magento\Inventory\Model\StockSourceLink\Command;
77

88
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
99
use Magento\Framework\Api\SearchCriteriaBuilder;
@@ -69,9 +69,9 @@ public function __construct(
6969
/**
7070
* @inheritdoc
7171
*/
72-
public function execute($stockId, $sourceId)
72+
public function execute($sourceId, $stockId)
7373
{
74-
if (!is_numeric($stockId) || !is_numeric($sourceId)) {
74+
if (!is_numeric($sourceId) || !is_numeric($stockId)) {
7575
throw new InputException(__('Input data is invalid'));
7676
}
7777

app/code/Magento/Inventory/Observer/SourceItemsProcessor.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\InventoryApi\Api\Data\SourceItemInterface;
1414
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory;
1515
use Magento\InventoryApi\Api\SourceItemRepositoryInterface;
16-
use Magento\InventoryApi\Api\SourceItemSaveInterface;
16+
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
1717

1818
/**
1919
* At the time of processing Product save form this class used to save source items correctly
@@ -42,9 +42,9 @@ class SourceItemsProcessor
4242
private $dataObjectHelper;
4343

4444
/**
45-
* @var SourceItemSaveInterface
45+
* @var SourceItemsSaveInterface
4646
*/
47-
private $sourceItemSave;
47+
private $sourceItemsSave;
4848

4949
/**
5050
* SourceItemsProcessor constructor
@@ -53,20 +53,20 @@ class SourceItemsProcessor
5353
* @param SourceItemRepositoryInterface $sourceItemRepository
5454
* @param SourceItemInterfaceFactory $sourceItemFactory
5555
* @param DataObjectHelper $dataObjectHelper
56-
* @param SourceItemSaveInterface $sourceItemSave
56+
* @param SourceItemsSaveInterface $sourceItemsSave
5757
*/
5858
public function __construct(
5959
SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
6060
SourceItemRepositoryInterface $sourceItemRepository,
6161
SourceItemInterfaceFactory $sourceItemFactory,
6262
DataObjectHelper $dataObjectHelper,
63-
SourceItemSaveInterface $sourceItemSave
63+
SourceItemsSaveInterface $sourceItemsSave
6464
) {
6565
$this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory;
6666
$this->sourceItemRepository = $sourceItemRepository;
6767
$this->sourceItemFactory = $sourceItemFactory;
6868
$this->dataObjectHelper = $dataObjectHelper;
69-
$this->sourceItemSave = $sourceItemSave;
69+
$this->sourceItemsSave = $sourceItemsSave;
7070
}
7171

7272
/**
@@ -98,7 +98,7 @@ public function process($sku, array $sourceItemsData)
9898
unset($sourceItemsForDelete[$sourceId]);
9999
}
100100
if ($sourceItemsForSave) {
101-
$this->sourceItemSave->execute($sourceItemsForSave);
101+
$this->sourceItemsSave->execute($sourceItemsForSave);
102102
}
103103
if ($sourceItemsForDelete) {
104104
$this->deleteSourceItems($sourceItemsForDelete);

app/code/Magento/Inventory/etc/di.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</type>
3535
<!-- Source Item -->
3636
<preference for="Magento\InventoryApi\Api\SourceItemRepositoryInterface" type="Magento\Inventory\Model\SourceItemRepository"/>
37-
<preference for="Magento\InventoryApi\Api\SourceItemSaveInterface" type="Magento\Inventory\Model\SourceItemSave"/>
37+
<preference for="Magento\InventoryApi\Api\SourceItemsSaveInterface" type="Magento\Inventory\Model\SourceItem\Command\SourceItemsSave"/>
3838
<preference for="Magento\InventoryApi\Api\Data\SourceItemInterface" type="Magento\Inventory\Model\SourceItem"/>
3939
<preference for="Magento\InventoryApi\Api\Data\SourceItemSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>
4040
<preference for="Magento\Inventory\Model\SourceItem\Command\DeleteInterface" type="Magento\Inventory\Model\SourceItem\Command\Delete"/>
@@ -62,7 +62,7 @@
6262
</arguments>
6363
</type>
6464
<!-- StockSourceLink -->
65-
<preference for="Magento\InventoryApi\Api\AssignSourcesToStockInterface" type="Magento\Inventory\Model\AssignSourcesToStock"/>
66-
<preference for="Magento\InventoryApi\Api\GetAssignedSourcesForStockInterface" type="Magento\Inventory\Model\GetAssignedSourcesForStock"/>
67-
<preference for="Magento\InventoryApi\Api\UnassignSourceFromStockInterface" type="Magento\Inventory\Model\UnassignSourceFromStock"/>
65+
<preference for="Magento\InventoryApi\Api\AssignSourcesToStockInterface" type="Magento\Inventory\Model\StockSourceLink\Command\AssignSourcesToStock"/>
66+
<preference for="Magento\InventoryApi\Api\GetAssignedSourcesForStockInterface" type="Magento\Inventory\Model\StockSourceLink\Command\GetAssignedSourcesForStock"/>
67+
<preference for="Magento\InventoryApi\Api\UnassignSourceFromStockInterface" type="Magento\Inventory\Model\StockSourceLink\Command\UnassignSourceFromStock"/>
6868
</config>

app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ interface AssignSourcesToStockInterface
1717
/**
1818
* Assign source id list by stock id
1919
*
20-
* @param int $stockId
2120
* @param int[] $sourceIds
21+
* @param int $stockId
2222
* @return void
2323
* @throws \Magento\Framework\Exception\InputException
2424
* @throws \Magento\Framework\Exception\CouldNotSaveException
2525
*/
26-
public function execute($stockId, array $sourceIds);
26+
public function execute(array $sourceIds, $stockId);
2727
}

app/code/Magento/InventoryApi/Api/GetAssignedSourcesForStockInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\InventoryApi\Api;
77

88
/**
9-
* Get assigned Sources for Stock command
9+
* Get assigned Sources for Stock
1010
*
1111
* Used fully qualified namespaces in annotations for proper work of WebApi request parser
1212
*

app/code/Magento/InventoryApi/Api/SourceItemRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* considered as SPI - Interfaces that you should extend and implement to customize current behaviour
2222
*
2323
* The method save is absent, due to different semantic (save multiple)
24-
* @see SourceItemSaveInterface
24+
* @see SourceItemsSaveInterface
2525
*
2626
* There is no get method because SourceItem identifies by compound identifier (sku and source_id),
2727
* so need to use getList() method

app/code/Magento/InventoryApi/Api/SourceItemSaveInterface.php renamed to app/code/Magento/InventoryApi/Api/SourceItemsSaveInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @api
1515
*/
16-
interface SourceItemSaveInterface
16+
interface SourceItemsSaveInterface
1717
{
1818
/**
1919
* Save Multiple Source item data

app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\InventoryApi\Api;
77

88
/**
9-
* Unassign source from stock command
9+
* Unassign source from stock
1010
*
1111
* Used fully qualified namespaces in annotations for proper work of WebApi request parser
1212
*
@@ -17,10 +17,10 @@ interface UnassignSourceFromStockInterface
1717
/**
1818
* Unassign source from stock
1919
*
20-
* @param int $stockId
2120
* @param int $sourceId
21+
* @param int $stockId
2222
* @return void
2323
* @throws \Magento\Framework\Exception\InputException
2424
*/
25-
public function execute($stockId, $sourceId);
25+
public function execute($sourceId, $stockId);
2626
}

lib/internal/Magento/Framework/Validation/ValidationException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
class ValidationException extends AbstractAggregateException
1616
{
1717
/**
18-
* @param array $errors
18+
* @param ValidationResult $validationResult
1919
* @param \Exception $cause
2020
* @param int $code
2121
*/
22-
public function __construct(array $errors = [], \Exception $cause = null, $code = 0)
22+
public function __construct(ValidationResult $validationResult, \Exception $cause = null, $code = 0)
2323
{
24-
foreach ($errors as $error) {
24+
foreach ($validationResult->getErrors() as $error) {
2525
$this->addError($error);
2626
}
2727
parent::__construct($this->phrase, $cause, $code);

0 commit comments

Comments
 (0)