Skip to content

Commit 1585723

Browse files
authored
Added delete legacy data patch (#176)
1 parent 90c20c0 commit 1585723

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Meta\BusinessExtension\Setup\Patch\Data;
6+
7+
use Magento\Framework\Setup\Patch\DataPatchInterface;
8+
use Magento\Framework\Setup\ModuleDataSetupInterface;
9+
10+
class DeleteLegacyData implements DataPatchInterface
11+
{
12+
/**
13+
* @var ModuleDataSetupInterface
14+
*/
15+
private ModuleDataSetupInterface $moduleDataSetup;
16+
17+
/**
18+
* @param ModuleDataSetupInterface $moduleDataSetup
19+
*/
20+
public function __construct(
21+
ModuleDataSetupInterface $moduleDataSetup
22+
) {
23+
$this->moduleDataSetup = $moduleDataSetup;
24+
}
25+
26+
/**
27+
* Get dependencies for the data patch
28+
*
29+
* @return array
30+
*/
31+
public static function getDependencies(): array
32+
{
33+
return [];
34+
}
35+
36+
/**
37+
* Get alias for the data patch
38+
*
39+
* @return array
40+
*/
41+
public function getAliases(): array
42+
{
43+
return [];
44+
}
45+
46+
/**
47+
* Delete unnecessary data from the legacy version of the extension
48+
*
49+
* @return void
50+
*/
51+
public function apply(): void
52+
{
53+
$productAttributesToDelete = [
54+
'facebook_age_group',
55+
'facebook_gender',
56+
'facebook_pattern',
57+
'facebook_decor_style',
58+
'facebook_color',
59+
'facebook_capacity',
60+
'facebook_material',
61+
'facebook_size',
62+
'facebook_style',
63+
'facebook_brand',
64+
'facebook_product_length',
65+
'facebook_product_width',
66+
'facebook_product_height',
67+
'facebook_model',
68+
'facebook_product_depth',
69+
'facebook_ingredients',
70+
'facebook_resolution',
71+
'facebook_age_range',
72+
'facebook_screen_size',
73+
'facebook_maximum_weight',
74+
'facebook_minimum_weight',
75+
'facebook_display_technology',
76+
'facebook_operating_system',
77+
'facebook_is_assembly_required',
78+
'facebook_storage_capacity',
79+
'facebook_number_of_licenses',
80+
'facebook_product_form',
81+
'facebook_compatible_devices',
82+
'facebook_video_game_platform',
83+
'facebook_system_requirements',
84+
'facebook_baby_food_stage',
85+
'facebook_recommended_use',
86+
'facebook_digital_zoom',
87+
'facebook_scent',
88+
'facebook_health_concern',
89+
'facebook_megapixels',
90+
'facebook_thread_count',
91+
'facebook_gemstone',
92+
'facebook_optical_zoom',
93+
'facebook_package_quantity',
94+
'facebook_shoe_width',
95+
'facebook_finish',
96+
'facebook_product_weight',
97+
];
98+
99+
$connection = $this->moduleDataSetup->getConnection();
100+
101+
$connection->startSetup();
102+
103+
// drop legacy facebook_business_extension_config table
104+
$connection->dropTable('facebook_business_extension_config');
105+
106+
// delete legacy product attributes
107+
$eavAttributeTable = $connection->getTableName('eav_attribute');
108+
foreach ($productAttributesToDelete as $attributeCode) {
109+
$connection->delete($eavAttributeTable, ['attribute_code = ?' => $attributeCode]);
110+
}
111+
112+
// delete legacy attribute group
113+
$eavAttributeGroupTable = $connection->getTableName('eav_attribute_group');
114+
$connection->delete($eavAttributeGroupTable, ['attribute_group_name = ?' => 'Facebook Attribute Group']);
115+
116+
$connection->endSetup();
117+
}
118+
}

app/code/Meta/BusinessExtension/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"magento/module-backend": "*",
1111
"magento/module-catalog": "*",
1212
"magento/module-config": "*",
13+
"magento/module-eav": "*",
1314
"magento/module-security": "*",
1415
"magento/module-store": "*",
1516
"magento/module-newsletter": "*",

app/code/Meta/BusinessExtension/etc/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<module name="Magento_Backend"/>
77
<module name="Magento_Catalog"/>
88
<module name="Magento_Config"/>
9+
<module name="Magento_Eav"/>
910
<module name="Magento_Security"/>
1011
<module name="Magento_Store"/>
1112
<module name="Magento_Newsletter"/>

0 commit comments

Comments
 (0)