Skip to content

Commit 5347b08

Browse files
author
Hwashiang Yu
committed
MC-32145: Wishlist upgrade db update
- Added data patch
1 parent 7f91b90 commit 5347b08

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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\Serialize\Serializer\Json;
10+
use Magento\Framework\Setup\ModuleDataSetupInterface;
11+
use Magento\Framework\Setup\Patch\DataPatchInterface;
12+
13+
/**
14+
* Class Clean Up Data Removes unused data
15+
*/
16+
class CleanUpData implements DataPatchInterface
17+
{
18+
/**
19+
* @var ModuleDataSetupInterface
20+
*/
21+
private $moduleDataSetup;
22+
23+
/**
24+
* @var Json
25+
*/
26+
private $json;
27+
28+
/**
29+
* RemoveData constructor.
30+
* @param ModuleDataSetupInterface $moduleDataSetup
31+
* @param Json $json
32+
*/
33+
public function __construct(
34+
ModuleDataSetupInterface $moduleDataSetup,
35+
Json $json
36+
) {
37+
$this->moduleDataSetup = $moduleDataSetup;
38+
$this->json = $json;
39+
}
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
public function apply()
45+
{
46+
$this->moduleDataSetup->getConnection()->startSetup();
47+
$wishListItemOptionTable = $this->moduleDataSetup->getTable('wishlist_item_option');
48+
$select = $this->moduleDataSetup->getConnection()->select()->from($wishListItemOptionTable);
49+
foreach ($this->moduleDataSetup->getConnection()->fetchAll($select) as $optionRow) {
50+
$rowValue = $this->json->unserialize($optionRow['value']);
51+
unset($rowValue['login']);
52+
$rowValue = $this->json->serialize($rowValue);
53+
$this->moduleDataSetup->getConnection()->update(
54+
$wishListItemOptionTable,
55+
['value' => $rowValue],
56+
['option_id = ?' => $optionRow['option_id']]
57+
);
58+
}
59+
$this->moduleDataSetup->getConnection()->endSetup();
60+
61+
return $this;
62+
}
63+
64+
/**
65+
* @inheritdoc
66+
*/
67+
public static function getDependencies()
68+
{
69+
return [
70+
ConvertSerializedData::class
71+
];
72+
}
73+
74+
/**
75+
* @inheritdoc
76+
*/
77+
public function getAliases()
78+
{
79+
return [];
80+
}
81+
}

0 commit comments

Comments
 (0)