Skip to content

Commit

Permalink
Merge pull request #742 from mollie/PIPRES-180-order-status-soft-dele…
Browse files Browse the repository at this point in the history
…te-on-uninstall

PIPRES-180: Order status soft delete on uninstall
  • Loading branch information
mandan2 authored Jun 13, 2023
2 parents 91b83fb + 7ea7fb3 commit df65495
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public function uninstall()
{
/** @var \Mollie\Install\Uninstall $uninstall */
$uninstall = $this->getService(\Mollie\Install\Uninstall::class);

if (!$uninstall->uninstall()) {
$this->_errors[] = $uninstall->getErrors();

Expand Down
2 changes: 0 additions & 2 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ class Config
const MOLLIE_MAIL_WHEN_CANCELED = 'MOLLIE_MAIL_WHEN_CANCELED';
const MOLLIE_MAIL_WHEN_EXPIRED = 'MOLLIE_MAIL_WHEN_EXPIRED';
const MOLLIE_MAIL_WHEN_REFUNDED = 'MOLLIE_MAIL_WHEN_REFUNDED';
const MOLLIE_MAIL_WHEN_PARTIAL_REFUND = 'MOLLIE_MAIL_WHEN_PARTIAL_REFUND';
const MOLLIE_MAIL_WHEN_CHARGEBACK = 'MOLLIE_MAIL_WHEN_CHARGEBACK';
const PARTIAL_REFUND_CODE = 'partial_refund';
const MOLLIE_STATUS_INITIATED = 'MOLLIE_STATUS_INITIATED';
const MOLLIE_STATUS_PARTIALLY_SHIPPED = 'MOLLIE_PARTIALLY_SHIPPED';
const MOLLIE_STATUS_ORDER_COMPLETED = 'MOLLIE_STATUS_ORDER_COMPLETED';
const MOLLIE_STATUS_DEFAULT = 'MOLLIE_STATUS_DEFAULT';
Expand Down
7 changes: 7 additions & 0 deletions src/Factory/ModuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public function getModule(): ?Mollie

return $module;
}

public function getModuleName(): ?string
{
$module = $this->getModule();

return $module->name ?? null;
}
}
17 changes: 15 additions & 2 deletions src/Install/DatabaseTableUninstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@
namespace Mollie\Install;

use Db;
use Mollie\Factory\ModuleFactory;

final class DatabaseTableUninstaller implements UninstallerInterface
{
public function uninstall()
/** @var ModuleFactory */
private $moduleFactory;

public function __construct(ModuleFactory $moduleFactory)
{
$this->moduleFactory = $moduleFactory;
}

public function uninstall(): bool
{
foreach ($this->getCommands() as $query) {
if (false == Db::getInstance()->execute($query)) {
Expand All @@ -27,7 +36,7 @@ public function uninstall()
return true;
}

private function getCommands()
private function getCommands(): array
{
$sql = [];

Expand All @@ -41,6 +50,10 @@ private function getCommands()
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'mol_pending_order_cart_rule`;';
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'mol_payment_method_order_total_restriction`;';

if ($moduleName = $this->moduleFactory->getModuleName()) {
$sql[] = 'UPDATE ' . _DB_PREFIX_ . 'order_state SET deleted = 1 WHERE module_name = "' . pSQL($moduleName) . '";';
}

return $sql;
}
}
22 changes: 21 additions & 1 deletion src/Install/Uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,27 @@ private function deleteConfig()
Config::MOLLIE_API_KEY_TEST,
];

$this->deleteConfigurations($configurations);
$orderStateConfigurations = [
Config::MOLLIE_STATUS_PARTIAL_REFUND,
Config::MOLLIE_STATUS_AWAITING,
Config::MOLLIE_STATUS_PARTIALLY_SHIPPED,
Config::MOLLIE_STATUS_ORDER_COMPLETED,
Config::MOLLIE_STATUS_KLARNA_AUTHORIZED,
Config::MOLLIE_STATUS_KLARNA_SHIPPED,
Config::MOLLIE_STATUS_CHARGEBACK,
Config::MOLLIE_STATUS_OPEN,
Config::MOLLIE_STATUS_PAID,
Config::MOLLIE_STATUS_COMPLETED,
Config::MOLLIE_STATUS_CANCELED,
Config::MOLLIE_STATUS_EXPIRED,
Config::MOLLIE_STATUS_REFUNDED,
Config::MOLLIE_STATUS_SHIPPING,
Config::MOLLIE_STATUS_DEFAULT,
];

$this->deleteConfigurations(
array_merge($configurations, $orderStateConfigurations)
);
}

private function deleteConfigurations(array $configurations)
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider/BaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function register(Container $container)
$this->addService($container, MolCustomerRepository::class, MolCustomerRepository::class)
->withArgument('MolCustomer');

$this->addService($container, UninstallerInterface::class, Mollie\Install\DatabaseTableUninstaller::class);
$this->addService($container, UninstallerInterface::class, $container->get(Mollie\Install\DatabaseTableUninstaller::class));

$this->addService($container, InstallerInterface::class, Installer::class)
->withArguments([
Expand Down

0 comments on commit df65495

Please sign in to comment.