Skip to content

Commit

Permalink
Fix #14958 - move two methods from resource models to private methods…
Browse files Browse the repository at this point in the history
… of DeleteByStore
  • Loading branch information
Bartlomiejsz committed Jun 7, 2019
1 parent 7c078cf commit 76b2085
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 349 deletions.
48 changes: 0 additions & 48 deletions app/code/Magento/SalesSequence/Model/ResourceModel/Meta/Ids.php

This file was deleted.

43 changes: 0 additions & 43 deletions app/code/Magento/SalesSequence/Model/ResourceModel/Profile/Ids.php

This file was deleted.

62 changes: 41 additions & 21 deletions app/code/Magento/SalesSequence/Model/Sequence/DeleteByStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Magento\Framework\App\ResourceConnection as AppResource;
use Magento\SalesSequence\Model\MetaFactory;
use Magento\SalesSequence\Model\ResourceModel\Meta as ResourceMetadata;
use Magento\SalesSequence\Model\ResourceModel\Meta\Ids as ResourceMetadataIds;
use Magento\SalesSequence\Model\ResourceModel\Profile\Ids as ResourceProfileIds;
use Magento\Store\Api\Data\StoreInterface;

/**
Expand All @@ -24,16 +22,6 @@ class DeleteByStore
*/
private $resourceMetadata;

/**
* @var ResourceMetadataIds
*/
private $resourceMetadataIds;

/**
* @var ResourceProfileIds
*/
private $resourceProfileIds;

/**
* @var MetaFactory
*/
Expand All @@ -46,21 +34,15 @@ class DeleteByStore

/**
* @param ResourceMetadata $resourceMetadata
* @param ResourceMetadataIds $resourceMetadataIds
* @param ResourceProfileIds $resourceProfileIds
* @param MetaFactory $metaFactory
* @param AppResource $appResource
*/
public function __construct(
ResourceMetadata $resourceMetadata,
ResourceMetadataIds $resourceMetadataIds,
ResourceProfileIds $resourceProfileIds,
MetaFactory $metaFactory,
AppResource $appResource
) {
$this->resourceMetadata = $resourceMetadata;
$this->resourceMetadataIds = $resourceMetadataIds;
$this->resourceProfileIds = $resourceProfileIds;
$this->metaFactory = $metaFactory;
$this->appResource = $appResource;
}
Expand All @@ -70,12 +52,12 @@ public function __construct(
*
* @param StoreInterface $store
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Exception
*/
public function execute(StoreInterface $store): void
{
$metadataIds = $this->resourceMetadataIds->getByStoreId($store->getId());
$profileIds = $this->resourceProfileIds->getByMetadataIds($metadataIds);
$metadataIds = $this->getMetadataIdsByStoreId($store->getId());
$profileIds = $this->getProfileIdsByMetadataIds($metadataIds);

$this->appResource->getConnection()->delete(
$this->appResource->getTableName('sales_sequence_profile'),
Expand All @@ -95,4 +77,42 @@ public function execute(StoreInterface $store): void
$this->resourceMetadata->delete($metadata);
}
}

/**
* Retrieves Metadata Ids by store id
*
* @param int $storeId
* @return int[]
*/
private function getMetadataIdsByStoreId($storeId)
{
$connection = $this->appResource->getConnection();
$bind = ['store_id' => $storeId];
$select = $connection->select()->from(
$this->appResource->getTableName('sales_sequence_meta'),
['meta_id']
)->where(
'store_id = :store_id'
);

return $connection->fetchCol($select, $bind);
}

/**
* Retrieves Profile Ids by metadata ids
*
* @param int[] $metadataIds
* @return int[]
*/
private function getProfileIdsByMetadataIds(array $metadataIds)
{
$connection = $this->appResource->getConnection();
$select = $connection->select()
->from(
$this->appResource->getTableName('sales_sequence_profile'),
['profile_id']
)->where('meta_id IN (?)', $metadataIds);

return $connection->fetchCol($select);
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 76b2085

Please sign in to comment.