From c874117604f424c85c579d732e39b946d0655cfe Mon Sep 17 00:00:00 2001 From: tomjas1997 Date: Mon, 27 Mar 2023 16:23:10 +0300 Subject: [PATCH] SL-151 uninstall action --- src/Install/Uninstaller.php | 56 +++++++++++++++---------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/src/Install/Uninstaller.php b/src/Install/Uninstaller.php index ba1e997e0..5baa68825 100755 --- a/src/Install/Uninstaller.php +++ b/src/Install/Uninstaller.php @@ -39,14 +39,18 @@ public function getErrors() public function uninstall() { - if (!$this->uninstallConfiguration()) { - $this->errors[] = $this->module->l('Failed to uninstall configuration', __CLASS__); - return false; + foreach (SaferPayConfig::getUninstallConfiguration() as $configuration) { + if (!Configuration::deleteByName($configuration)) { + $this->errors[] = $this->module->l('Failed to uninstall configuration', __CLASS__); + return false; + } } - if (!$this->uninstallDatabase()) { - $this->errors[] = $this->module->l('Failed to uninstall database tables', __CLASS__); - return false; + foreach ($this->getCommands() as $tableName => $command) { + if (false === \Db::getInstance()->execute($command)) { + $this->errors[] = sprintf($this->module->l('Failed to uninstall database table [%s]' , __CLASS__), $tableName); + return false; + } } if (!SaferPayConfig::isVersion17()) { @@ -59,34 +63,20 @@ public function uninstall() return true; } - private function uninstallConfiguration() - { - $configurations = SaferPayConfig::getUninstallConfiguration(); - - foreach ($configurations as $configuration) { - if (!Configuration::deleteByName($configuration)) { - return false; - } - } - - return true; - } - - private function uninstallDatabase() + private function getCommands() { - return Db::getInstance()->execute( - 'DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_payment; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_logo; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_country; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_currency; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_order; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_assert; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_card_alias; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_log; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_field; - DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'saferpay_order_refund; - ' - ); + return [ + \SaferPayPayment::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayPayment::$definition['table']) . '`;', + \SaferPayLogo::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayLogo::$definition['table']) . '`;', + \SaferPayCountry::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayCountry::$definition['table']) . '`;', + \SaferPayCurrency::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayCurrency::$definition['table']) . '`;', + \SaferPayOrder::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayOrder::$definition['table']) . '`;', + \SaferPayAssert::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayAssert::$definition['table']) . '`;', + \SaferPayCardAlias::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayCardAlias::$definition['table']) . '`;', + \SaferPayLog::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayLog::$definition['table']) . '`;', + \SaferPayField::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayField::$definition['table']) . '`;', + \SaferPayOrderRefund::$definition['table'] => 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . pSQL(\SaferPayOrderRefund::$definition['table']) . '`;', + ]; } private function uninstallTabs()