Skip to content

Commit 8907203

Browse files
author
Hwashiang Yu
committed
MC-32145: Wishlist upgrade db update
- Updated clean up data patch to not use moduledatasetup interface
1 parent 93c790e commit 8907203

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

app/code/Magento/Wishlist/Setup/Patch/Data/CleanUpData.php

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
use Magento\Framework\DB\Select\QueryModifierFactory;
1010
use Magento\Framework\Serialize\Serializer\Json;
11-
use Magento\Framework\Setup\ModuleDataSetupInterface;
1211
use Magento\Framework\Setup\Patch\DataPatchInterface;
13-
use Magento\Framework\App\ObjectManager;
1412
use Magento\Framework\DB\Query\Generator;
13+
use Magento\Framework\App\ResourceConnection;
14+
use Magento\Framework\DB\Adapter\AdapterInterface;
1515

1616
/**
1717
* Class Clean Up Data Removes unused data
@@ -24,9 +24,9 @@ class CleanUpData implements DataPatchInterface
2424
private const BATCH_SIZE = 1000;
2525

2626
/**
27-
* @var ModuleDataSetupInterface
27+
* @var AdapterInterface
2828
*/
29-
private $moduleDataSetup;
29+
private $adapter;
3030

3131
/**
3232
* @var Generator
@@ -44,52 +44,51 @@ class CleanUpData implements DataPatchInterface
4444

4545
/**
4646
* RemoveData constructor.
47-
* @param ModuleDataSetupInterface $moduleDataSetup
48-
* @param Json|null $json
49-
* @param Generator|null $queryGenerator
50-
* @param QueryModifierFactory|null $queryModifierFactory
47+
* @param Json $json
48+
* @param Generator $queryGenerator
49+
* @param QueryModifierFactory $queryModifierFactory
50+
* @param ResourceConnection $resourceConnection
5151
*/
5252
public function __construct(
53-
ModuleDataSetupInterface $moduleDataSetup,
54-
Json $json = null,
55-
Generator $queryGenerator = null,
56-
QueryModifierFactory $queryModifierFactory = null
53+
Json $json,
54+
Generator $queryGenerator,
55+
QueryModifierFactory $queryModifierFactory,
56+
ResourceConnection $resourceConnection
5757
) {
58-
$this->moduleDataSetup = $moduleDataSetup;
59-
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
60-
$this->queryGenerator = $queryGenerator ?: ObjectManager::getInstance()->get(Generator::class);
61-
$this->queryModifierFactory = $queryModifierFactory
62-
?: ObjectManager::getInstance()->get(QueryModifierFactory::class);
58+
$this->json = $json;
59+
$this->queryGenerator = $queryGenerator;
60+
$this->queryModifierFactory = $queryModifierFactory;
61+
$this->adapter = $resourceConnection->getConnection();
6362
}
6463

6564
/**
6665
* @inheritdoc
6766
*/
6867
public function apply()
6968
{
70-
$this->moduleDataSetup->getConnection()->startSetup();
71-
$wishListItemOptionTable = $this->moduleDataSetup->getTable('wishlist_item_option');
72-
$select = $this->moduleDataSetup->getConnection()
69+
$this->adapter->startSetup();
70+
$wishListItemOptionTable = $this->adapter->getTableName('wishlist_item_option');
71+
$select = $this->adapter
7372
->select()
7473
->from(
7574
$wishListItemOptionTable,
7675
['option_id', 'value']
7776
);
7877
$iterator = $this->queryGenerator->generate('option_id', $select, self::BATCH_SIZE);
7978
foreach ($iterator as $selectByRange) {
80-
$optionRows = $this->moduleDataSetup->getConnection()->fetchAll($selectByRange);
79+
$optionRows = $this->adapter->fetchAll($selectByRange);
8180
foreach ($optionRows as $optionRow) {
8281
$rowValue = $this->json->unserialize($optionRow['value']);
8382
unset($rowValue['login']);
8483
$rowValue = $this->json->serialize($rowValue);
85-
$this->moduleDataSetup->getConnection()->update(
84+
$this->adapter->update(
8685
$wishListItemOptionTable,
8786
['value' => $rowValue],
8887
['option_id = ?' => $optionRow['option_id']]
8988
);
9089
}
9190
}
92-
$this->moduleDataSetup->getConnection()->endSetup();
91+
$this->adapter->endSetup();
9392

9493
return $this;
9594
}

0 commit comments

Comments
 (0)