88
99namespace SwagPaymentPayPalUnified \Setup ;
1010
11+ use Doctrine \DBAL \Connection ;
1112use Shopware \Bundle \AttributeBundle \Service \CrudService ;
1213use Shopware \Components \Model \ModelManager ;
1314use SwagPaymentPayPalUnified \Components \PaymentMethodProvider ;
@@ -24,22 +25,45 @@ class Uninstaller
2425 */
2526 private $ modelManager ;
2627
28+ /**
29+ * @var Connection
30+ */
31+ private $ connection ;
32+
2733 /**
2834 * @param CrudService $attributeCrudService
2935 * @param ModelManager $modelManager
36+ * @param Connection $connection
3037 */
31- public function __construct (CrudService $ attributeCrudService , ModelManager $ modelManager )
38+ public function __construct (CrudService $ attributeCrudService , ModelManager $ modelManager, Connection $ connection )
3239 {
3340 $ this ->attributeCrudService = $ attributeCrudService ;
3441 $ this ->modelManager = $ modelManager ;
42+ $ this ->connection = $ connection ;
43+ }
44+
45+ /**
46+ * @param bool $safeMode
47+ */
48+ public function uninstall ($ safeMode )
49+ {
50+ $ this ->deactivatePayments ();
51+ $ this ->removeAttributes ();
52+
53+ if (!$ safeMode ) {
54+ $ this ->removeSettingsTables ();
55+ }
3556 }
3657
37- public function uninstall ()
58+ private function deactivatePayments ()
3859 {
3960 $ paymentMethodProvider = new PaymentMethodProvider ($ this ->modelManager );
4061 $ paymentMethodProvider ->setPaymentMethodActiveFlag (false );
4162 $ paymentMethodProvider ->setPaymentMethodActiveFlag (false , PaymentMethodProvider::PAYPAL_INSTALLMENTS_PAYMENT_METHOD_NAME );
63+ }
4264
65+ private function removeAttributes ()
66+ {
4367 if ($ this ->attributeCrudService ->get ('s_core_paymentmeans_attributes ' , 'swag_paypal_unified_display_in_plus_iframe ' ) !== null ) {
4468 $ this ->attributeCrudService ->delete (
4569 's_core_paymentmeans_attributes ' ,
@@ -54,4 +78,14 @@ public function uninstall()
5478 }
5579 $ this ->modelManager ->generateAttributeModels (['s_core_paymentmeans_attributes ' ]);
5680 }
81+
82+ private function removeSettingsTables ()
83+ {
84+ $ sql = 'DROP TABLE IF EXISTS `swag_payment_paypal_unified_settings_express`;
85+ DROP TABLE IF EXISTS `swag_payment_paypal_unified_settings_general`;
86+ DROP TABLE IF EXISTS `swag_payment_paypal_unified_settings_installments`;
87+ DROP TABLE IF EXISTS `swag_payment_paypal_unified_settings_plus`; ' ;
88+
89+ $ this ->connection ->exec ($ sql );
90+ }
5791}
0 commit comments