8
8
9
9
use Magento \Framework \DB \Select \QueryModifierFactory ;
10
10
use Magento \Framework \Serialize \Serializer \Json ;
11
- use Magento \Framework \Setup \ModuleDataSetupInterface ;
12
11
use Magento \Framework \Setup \Patch \DataPatchInterface ;
13
- use Magento \Framework \App \ObjectManager ;
14
12
use Magento \Framework \DB \Query \Generator ;
13
+ use Magento \Framework \App \ResourceConnection ;
14
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
15
15
16
16
/**
17
17
* Class Clean Up Data Removes unused data
@@ -24,9 +24,9 @@ class CleanUpData implements DataPatchInterface
24
24
private const BATCH_SIZE = 1000 ;
25
25
26
26
/**
27
- * @var ModuleDataSetupInterface
27
+ * @var AdapterInterface
28
28
*/
29
- private $ moduleDataSetup ;
29
+ private $ adapter ;
30
30
31
31
/**
32
32
* @var Generator
@@ -44,52 +44,51 @@ class CleanUpData implements DataPatchInterface
44
44
45
45
/**
46
46
* 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
51
51
*/
52
52
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
57
57
) {
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 ();
63
62
}
64
63
65
64
/**
66
65
* @inheritdoc
67
66
*/
68
67
public function apply ()
69
68
{
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
73
72
->select ()
74
73
->from (
75
74
$ wishListItemOptionTable ,
76
75
['option_id ' , 'value ' ]
77
76
);
78
77
$ iterator = $ this ->queryGenerator ->generate ('option_id ' , $ select , self ::BATCH_SIZE );
79
78
foreach ($ iterator as $ selectByRange ) {
80
- $ optionRows = $ this ->moduleDataSetup -> getConnection () ->fetchAll ($ selectByRange );
79
+ $ optionRows = $ this ->adapter ->fetchAll ($ selectByRange );
81
80
foreach ($ optionRows as $ optionRow ) {
82
81
$ rowValue = $ this ->json ->unserialize ($ optionRow ['value ' ]);
83
82
unset($ rowValue ['login ' ]);
84
83
$ rowValue = $ this ->json ->serialize ($ rowValue );
85
- $ this ->moduleDataSetup -> getConnection () ->update (
84
+ $ this ->adapter ->update (
86
85
$ wishListItemOptionTable ,
87
86
['value ' => $ rowValue ],
88
87
['option_id = ? ' => $ optionRow ['option_id ' ]]
89
88
);
90
89
}
91
90
}
92
- $ this ->moduleDataSetup -> getConnection () ->endSetup ();
91
+ $ this ->adapter ->endSetup ();
93
92
94
93
return $ this ;
95
94
}
0 commit comments