Skip to content

Commit

Permalink
PIPRES-180: Order status soft delete on uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
mandan2 committed Jun 13, 2023
1 parent 91b83fb commit 4978374
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
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
10 changes: 10 additions & 0 deletions src/Factory/ModuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ public function getModule(): ?Mollie

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

if (!$module) {
return null;
}

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
3 changes: 2 additions & 1 deletion src/ServiceProvider/BaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ 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, Mollie\Install\DatabaseTableUninstaller::class)
->withArgument($container->get(ModuleFactory::class));

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

0 comments on commit 4978374

Please sign in to comment.