Skip to content

Commit d4beb91

Browse files
committed
Merge pull request #125 in PLUG_OPEN/swagpaymentpaypalunified from pt-9290/5.2/remove-setting-tables-uninstall to master
* commit 'b92d3e085271b65d6c97bd0e98077b3e8adadbea': PT-9290 - Remove setting tables on uninstall
2 parents ca52dc2 + b92d3e0 commit d4beb91

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

Setup/Uninstaller.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace SwagPaymentPayPalUnified\Setup;
1010

11+
use Doctrine\DBAL\Connection;
1112
use Shopware\Bundle\AttributeBundle\Service\CrudService;
1213
use Shopware\Components\Model\ModelManager;
1314
use 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
}

SwagPaymentPayPalUnified.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public function uninstall(UninstallContext $context)
5353
{
5454
$uninstaller = new Uninstaller(
5555
$this->container->get('shopware_attribute.crud_service'),
56-
$this->container->get('models')
56+
$this->container->get('models'),
57+
$this->container->get('dbal_connection')
5758
);
58-
$uninstaller->uninstall();
59+
$uninstaller->uninstall($context->keepUserData());
5960

6061
$context->scheduleClearCache(UninstallContext::CACHE_LIST_ALL);
6162
}

0 commit comments

Comments
 (0)