Skip to content

Commit

Permalink
Merge pull request #78 from magento-engcom/todo-fixes
Browse files Browse the repository at this point in the history
Decrease number of TODO
  • Loading branch information
Valeriy Nayda authored Sep 4, 2017
2 parents d1f7820 + 074cba0 commit 30db59b
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 64 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Inventory/Indexer/IndexName.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Index Name object
* @api
*/
class IndexName // TODO: \Magento\Framework\Api\AbstractSimpleObject
class IndexName
{
/**
* @var string
Expand Down
26 changes: 16 additions & 10 deletions app/code/Magento/Inventory/Indexer/IndexNameBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@
* Index Name builder. It is Facade for simplifying IndexName object creation
* @api
*/
class IndexNameBuilder// TODO: \Magento\Framework\Api\AbstractSimpleObjectBuilder
class IndexNameBuilder
{
/**
* Index id parameter name
* Index id parameter name. Used internally in this object
*
* Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
*/
/* TODO: private only 7.1 */ const INDEX_ID = 'indexId';
private static $indexId = 'indexId';

/**
* Dimensions parameter name
* Dimensions parameter name. Used internally in this object
*
* Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
*/
const DIMENSIONS = 'dimensions';
private static $dimensions = 'dimensions';

/**
* Alias parameter name
* Alias parameter name. Used internally in this object
*
* Can not replace on private constant (feature of PHP 7.1) because we need to support PHP 7.0
*/
const ALIAS = 'alias';
private static $alias = 'alias';

/**
* @var IndexNameFactory
Expand Down Expand Up @@ -67,7 +73,7 @@ public function __construct(
*/
public function setIndexId(string $indexId): self
{
$this->data[self::INDEX_ID] = $indexId;
$this->data[self::$indexId] = $indexId;
return $this;
}

Expand All @@ -78,7 +84,7 @@ public function setIndexId(string $indexId): self
*/
public function addDimension(string $name, string $value): self
{
$this->data[self::DIMENSIONS][] = $this->dimensionFactory->create([
$this->data[self::$dimensions][] = $this->dimensionFactory->create([
'name' => $name,
'value' => $value,
]);
Expand All @@ -91,7 +97,7 @@ public function addDimension(string $name, string $value): self
*/
public function setAlias(string $alias): self
{
$this->data[self::ALIAS] = $this->aliasFactory->create(['value' => $alias]);
$this->data[self::$alias] = $this->aliasFactory->create(['value' => $alias]);
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
namespace Magento\Inventory\Indexer\StockItem;

use Magento\Framework\App\ResourceConnection;
use Magento\Inventory\Model\ResourceModel\StockSourceLink;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Api\Data\StockInterface;
use Magento\Inventory\Model\ResourceModel\StockSourceLink as StockSourceLinkResourceModel;
use Magento\Inventory\Model\StockSourceLink;

/**
* Returns all assigned stock ids by given sources ids
Expand Down Expand Up @@ -38,14 +37,14 @@ public function execute(array $sourceIds): array
{
$connection = $this->resourceConnection->getConnection();
$select = $connection->select()->from(
$connection->getTableName(StockSourceLink::TABLE_NAME_STOCK_SOURCE_LINK),
[StockInterface::STOCK_ID]
$connection->getTableName(StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK),
[StockSourceLink::STOCK_ID]
);

if (count($sourceIds)) {
$select->where(SourceInterface::SOURCE_ID . ' = ?', $sourceIds);
$select->where(StockSourceLink::SOURCE_ID . ' = ?', $sourceIds);
}
$select->group(StockInterface::STOCK_ID);
$select->group(StockSourceLink::STOCK_ID);
return $connection->fetchCol($select);
}
}
11 changes: 2 additions & 9 deletions app/code/Magento/Inventory/Indexer/StockItem/IndexHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public function saveIndex(IndexName $indexName, \Traversable $documents)
{
$tableName = $this->indexNameResolver->resolveName($indexName);

// TODO: stock item object for constants
$columns = ['sku', 'quantity', 'status'];
$columns = [IndexStructure::SKU, IndexStructure::QUANTITY, IndexStructure::STATUS];
foreach ($this->batch->getItems($documents, $this->batchSize) as $batchDocuments) {
$this->resourceConnection
->getConnection()
Expand All @@ -75,12 +74,6 @@ public function saveIndex(IndexName $indexName, \Traversable $documents)
*/
public function deleteIndex(IndexName $indexName, \Traversable $documents)
{
$tableName = $this->indexNameResolver->resolveName($indexName);

foreach ($this->batch->getItems($documents, $this->batchSize) as $batchDocuments) {
$this->resourceConnection
->getConnection()
->delete($tableName, ['stock_id IN (?)' => $batchDocuments]);
}
// TODO: implementation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function resolveName(IndexName $indexName): string
{
$tableName = $this->indexScopeResolver->resolve($indexName->getIndexId(), $indexName->getDimensions());

// TODO: LoD phly phly
if ($indexName->getAlias()->getValue() === Alias::ALIAS_REPLICA) {
$tableName = $this->activeTableSwitcher->getAdditionalTableName($tableName);
}
Expand Down
15 changes: 11 additions & 4 deletions app/code/Magento/Inventory/Indexer/StockItem/IndexStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Inventory\Indexer\StockItem;

use Magento\Framework\App\ResourceConnection;
Expand All @@ -17,6 +16,14 @@
*/
class IndexStructure implements IndexStructureInterface
{
/**
* Constants for represent fields in index table. Only for internal module using
*/
const SKU = 'sku';
const QUANTITY = 'quantity';
const STATUS = 'status';
/**#@-*/

/**
* @var ResourceConnection
*/
Expand Down Expand Up @@ -57,7 +64,7 @@ public function create(IndexName $indexName, string $connectionName = ResourceCo
)->setComment(
'Inventory Stock item Table'
)->addColumn(
'sku',
self::SKU,
Table::TYPE_TEXT,
64,
[
Expand All @@ -66,7 +73,7 @@ public function create(IndexName $indexName, string $connectionName = ResourceCo
],
'Sku'
)->addColumn(
'quantity',
self::QUANTITY,
Table::TYPE_DECIMAL,
null,
[
Expand All @@ -78,7 +85,7 @@ public function create(IndexName $indexName, string $connectionName = ResourceCo
],
'Quantity'
)->addColumn(
'status',
self::STATUS,
Table::TYPE_SMALLINT,
null,
[
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Inventory/Model/Source/Command/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function execute(SourceInterface $source)
throw new ValidationException($validationResult);
}

// TODO: check if exists?
try {
$this->sourceResource->save($source);
return $source->getSourceId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Magento\InventoryApi\Api\Data\SourceInterface;

/**
* TODO: more clear description
* Responsible for Source validation
* Extension point for base validation
*
* @api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Magento\InventoryApi\Api\Data\SourceInterface;

/**
* TODO: more clear description
* Chain of validators. Extension point for new validators via di configuration
*/
class ValidatorChain implements SourceValidatorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Magento\InventoryApi\Api\Data\StockInterface;

/**
* TODO: more clear description
* Responsible for Stock validation
* Extension point for base validation
*
* @api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Magento\InventoryApi\Api\Data\StockInterface;

/**
* TODO: more clear description
* Chain of validators. Extension point for new validators via di configuration
*/
class ValidatorChain implements StockValidatorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
*/
namespace Magento\Inventory\Model\StockSourceLink\Command;

use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Inventory\Model\ResourceModel\StockSourceLink\Collection;
use Magento\Inventory\Model\ResourceModel\StockSourceLink\CollectionFactory;
use Magento\Inventory\Model\ResourceModel\StockSourceLink as StockSourceLinkResourceModel;
use Magento\Inventory\Model\StockSourceLink;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Api\GetAssignedSourcesForStockInterface;
Expand All @@ -23,14 +22,9 @@
class GetAssignedSourcesForStock implements GetAssignedSourcesForStockInterface
{
/**
* @var CollectionProcessorInterface
* @var ResourceConnection
*/
private $collectionProcessor;

/**
* @var CollectionFactory
*/
private $stockLinkCollectionFactory;
private $resourceConnection;

/**
* @var SearchCriteriaBuilder
Expand All @@ -48,21 +42,18 @@ class GetAssignedSourcesForStock implements GetAssignedSourcesForStockInterface
private $logger;

/**
* @param CollectionProcessorInterface $collectionProcessor
* @param CollectionFactory $stockLinkCollectionFactory
* @param ResourceConnection $resourceConnection
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param SourceRepositoryInterface $sourceRepository
* @param LoggerInterface $logger
*/
public function __construct(
CollectionProcessorInterface $collectionProcessor,
CollectionFactory $stockLinkCollectionFactory,
ResourceConnection $resourceConnection,
SearchCriteriaBuilder $searchCriteriaBuilder,
SourceRepositoryInterface $sourceRepository,
LoggerInterface $logger
) {
$this->collectionProcessor = $collectionProcessor;
$this->stockLinkCollectionFactory = $stockLinkCollectionFactory;
$this->resourceConnection = $resourceConnection;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->sourceRepository = $sourceRepository;
$this->logger = $logger;
Expand Down Expand Up @@ -91,21 +82,21 @@ public function execute($stockId)
}

/**
* Get all linked SourceIds by given stockId.
* Get all linked SourceIds by given stockId
*
* @param int $stockId
* @return array
*/
private function getAssignedSourceIds($stockId)
{
// TODO: replace on direct SQL query
$searchCriteria = $this->searchCriteriaBuilder
->addFilter(StockSourceLink::STOCK_ID, (int)$stockId)
->create();
/** @var Collection $collection */
$collection = $this->stockLinkCollectionFactory->create();
$this->collectionProcessor->process($searchCriteria, $collection);
$data = $collection->getData();
return $data ? array_column($data, 'source_id') : [];
$connection = $this->resourceConnection->getConnection();
$select = $connection
->select()
->from(
$connection->getTableName(StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK),
[StockSourceLink::SOURCE_ID]
)
->where(StockSourceLink::STOCK_ID . ' = ?', $stockId);
return $connection->fetchCol($select);
}
}
1 change: 0 additions & 1 deletion app/code/Magento/Inventory/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<preference for="Magento\Inventory\Model\Stock\Command\GetInterface" type="Magento\Inventory\Model\Stock\Command\Get"/>
<preference for="Magento\Inventory\Model\Stock\Command\GetListInterface" type="Magento\Inventory\Model\Stock\Command\GetList"/>
<preference for="Magento\Inventory\Model\Stock\Command\SaveInterface" type="Magento\Inventory\Model\Stock\Command\Save"/>
<!-- TODO: describe bug -->
<preference for="Magento\Inventory\Model\Stock\Validator\StockValidatorInterface" type="Magento\Inventory\Model\Stock\Validator\ValidatorChain"/>
<type name="Magento\Inventory\Model\Stock\Validator\ValidatorChain">
<arguments>
Expand Down

0 comments on commit 30db59b

Please sign in to comment.