Skip to content

Commit 47c674e

Browse files
Merge MC-32145 into 2.3.5-bugfixes-031320
2 parents 7f91b90 + 5f3a94c commit 47c674e

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Wishlist\Setup\Patch\Data;
8+
9+
use Magento\Framework\DB\Select\QueryModifierFactory;
10+
use Magento\Framework\Serialize\Serializer\Json;
11+
use Magento\Framework\Setup\Patch\DataPatchInterface;
12+
use Magento\Framework\DB\Query\Generator;
13+
use Magento\Framework\App\ResourceConnection;
14+
use Magento\Framework\DB\Adapter\AdapterInterface;
15+
16+
/**
17+
* Class Clean Up Data Removes unused data
18+
*/
19+
class CleanUpData implements DataPatchInterface
20+
{
21+
/**
22+
* Batch size for query
23+
*/
24+
private const BATCH_SIZE = 1000;
25+
26+
/**
27+
* @var AdapterInterface
28+
*/
29+
private $adapter;
30+
31+
/**
32+
* @var Generator
33+
*/
34+
private $queryGenerator;
35+
36+
/**
37+
* @var Json
38+
*/
39+
private $json;
40+
/**
41+
* @var QueryModifierFactory
42+
*/
43+
private $queryModifierFactory;
44+
45+
/**
46+
* RemoveData constructor.
47+
* @param Json $json
48+
* @param Generator $queryGenerator
49+
* @param QueryModifierFactory $queryModifierFactory
50+
* @param ResourceConnection $resourceConnection
51+
*/
52+
public function __construct(
53+
Json $json,
54+
Generator $queryGenerator,
55+
QueryModifierFactory $queryModifierFactory,
56+
ResourceConnection $resourceConnection
57+
) {
58+
$this->json = $json;
59+
$this->queryGenerator = $queryGenerator;
60+
$this->queryModifierFactory = $queryModifierFactory;
61+
$this->adapter = $resourceConnection->getConnection();
62+
}
63+
64+
/**
65+
* @inheritdoc
66+
*/
67+
public function apply()
68+
{
69+
$wishListItemOptionTable = $this->adapter->getTableName('wishlist_item_option');
70+
$select = $this->adapter
71+
->select()
72+
->from(
73+
$wishListItemOptionTable,
74+
['option_id', 'value']
75+
);
76+
$iterator = $this->queryGenerator->generate('option_id', $select, self::BATCH_SIZE);
77+
foreach ($iterator as $selectByRange) {
78+
$optionRows = $this->adapter->fetchAll($selectByRange);
79+
foreach ($optionRows as $optionRow) {
80+
$rowValue = $this->json->unserialize($optionRow['value']);
81+
unset($rowValue['login']);
82+
$rowValue = $this->json->serialize($rowValue);
83+
$this->adapter->update(
84+
$wishListItemOptionTable,
85+
['value' => $rowValue],
86+
['option_id = ?' => $optionRow['option_id']]
87+
);
88+
}
89+
}
90+
91+
return $this;
92+
}
93+
94+
/**
95+
* @inheritdoc
96+
*/
97+
public static function getDependencies()
98+
{
99+
return [
100+
ConvertSerializedData::class
101+
];
102+
}
103+
104+
/**
105+
* @inheritdoc
106+
*/
107+
public function getAliases()
108+
{
109+
return [];
110+
}
111+
}

0 commit comments

Comments
 (0)