From 7effec966d66af65feece9905f3fc3aacef09e0f Mon Sep 17 00:00:00 2001 From: Tadas Labutis Date: Wed, 29 Jul 2026 15:41:15 +0300 Subject: [PATCH] Remove files deleted in 2.1.0 during the module upgrade A ZIP upgrade overwrites files but never removes the ones a new version dropped, so all 46 files deleted in 2.1.0 stayed on disk and stayed reachable: the leftover admin controller was re-registered as a tab on the next module reset, and the leftover iframe front controllers kept answering, one of them still reaching the checkout processor with the payment method taken from the request. The upgrade script now unlinks an explicit list of those 46 paths, removes the directories that become empty, drops the obsolete SAFERPAY_HOSTED_FIELDS_TEMPLATE setting and clears the Smarty cache. The list is explicit rather than directory based because views/js/front/hosted-templates/ still holds the live hosted_fields.js. --- changelog.md | 1 + upgrade/install-2.1.0.php | 115 +++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 3c5e71b8..3d6bf121 100644 --- a/changelog.md +++ b/changelog.md @@ -216,3 +216,4 @@ - API update to V1.50: added WERO and GIFTCARD payment methods, removed deprecated GIROPAY/PAYDIREKT/SOFORT - BO : Fixed issue when a freshly installed module logged an account error before any API credentials were entered - BO : Fixed issue when the "Could not reach your Saferpay account" warning kept showing after payment methods had loaded successfully +- Fixed issue when files removed in this version stayed on disk after an upgrade, leaving obsolete iframe checkout controllers reachable and re-creating obsolete menu tabs on module reset diff --git a/upgrade/install-2.1.0.php b/upgrade/install-2.1.0.php index d38ba19b..1fbb4f6d 100644 --- a/upgrade/install-2.1.0.php +++ b/upgrade/install-2.1.0.php @@ -26,6 +26,17 @@ } function upgrade_module_2_1_0() +{ + saferpayofficial_2_1_0_delete_removed_tabs(); + saferpayofficial_2_1_0_delete_removed_files(); + saferpayofficial_2_1_0_delete_removed_configuration(); + + Tools::clearSmartyCache(); + + return true; +} + +function saferpayofficial_2_1_0_delete_removed_tabs() { $removedTabs = ['AdminSaferPayOfficialPayment', 'AdminSaferPayOfficialFields']; @@ -38,6 +49,108 @@ function upgrade_module_2_1_0() $tab = new Tab($tabId); $tab->delete(); } +} - return true; +/** + * A ZIP upgrade overwrites files but never removes the ones a new version dropped, + * so everything deleted in 2.1.0 stays on disk and stays reachable: + * the leftover admin controller is re-registered as a tab by PrestaShop on the next + * module reset, and the leftover iframe front controllers keep answering, one of them + * still reaching the checkout processor with the payment method taken from the request. + * Both fatal on removed class constants, so they can only be cleaned up from here. + */ +function saferpayofficial_2_1_0_delete_removed_files() +{ + $moduleDir = dirname(__DIR__) . DIRECTORY_SEPARATOR; + + $removedFiles = [ + 'controllers/admin/AdminSaferPayOfficialFieldsController.php', + 'controllers/front/failIFrame.php', + 'controllers/front/hostedIframe.php', + 'controllers/front/iframe.php', + 'controllers/front/successIFrame.php', + 'src/Entity/index.php', + 'src/Service/SaferPayTerminalService.php', + 'views/css/admin/saferpay_fields.css', + 'views/css/front/hosted-templates/index.php', + 'views/css/front/hosted-templates/template1.css', + 'views/css/front/hosted-templates/template2.css', + 'views/css/front/hosted-templates/template3.css', + 'views/css/front/saferpay_iframe.css', + 'views/img/example-card/credit-card-back-cvc.png', + 'views/img/example-card/credit-card-back.png', + 'views/img/example-card/credit-card-front-card-number.png', + 'views/img/example-card/credit-card-front-expiration.png', + 'views/img/example-card/credit-card-front.png', + 'views/img/example-card/index.php', + 'views/img/hosted-templates/index.php', + 'views/img/hosted-templates/template1.jpg', + 'views/img/hosted-templates/template2.jpg', + 'views/img/hosted-templates/template3.jpg', + 'views/js/front/hosted-templates/template1.js', + 'views/js/front/hosted-templates/template2.js', + 'views/js/front/hosted-templates/template3.js', + 'views/js/front/hosted-templates/template_submit.js', + 'views/js/front/saferpay_iframe.js', + 'views/templates/admin/field-option-settings/helpers/index.php', + 'views/templates/admin/field-option-settings/helpers/options/index.php', + 'views/templates/admin/field-option-settings/helpers/options/options.tpl', + 'views/templates/admin/field-option-settings/index.php', + 'views/templates/admin/partials/field-hosted-field-template-desc.tpl', + 'views/templates/admin/partials/field-terminal-id.tpl', + 'views/templates/front/hosted-templates/index.php', + 'views/templates/front/hosted-templates/partials/all_errors.tpl', + 'views/templates/front/hosted-templates/partials/all_errors_16.tpl', + 'views/templates/front/hosted-templates/partials/index.php', + 'views/templates/front/hosted-templates/partials/initialize_error.tpl', + 'views/templates/front/hosted-templates/partials/internal_error.tpl', + 'views/templates/front/hosted-templates/partials/submission_error.tpl', + 'views/templates/front/hosted-templates/partials/validation_error.tpl', + 'views/templates/front/hosted-templates/template1.tpl', + 'views/templates/front/hosted-templates/template2.tpl', + 'views/templates/front/hosted-templates/template3.tpl', + 'views/templates/front/saferpay_iframe.tpl', + ]; + + $parentDirectories = []; + + foreach ($removedFiles as $removedFile) { + $path = $moduleDir . str_replace('/', DIRECTORY_SEPARATOR, $removedFile); + + if (!is_file($path)) { + continue; + } + + @unlink($path); + $parentDirectories[dirname($path)] = true; + } + + $parentDirectories = array_keys($parentDirectories); + + usort($parentDirectories, function ($first, $second) { + return strlen($second) - strlen($first); + }); + + foreach ($parentDirectories as $parentDirectory) { + saferpayofficial_2_1_0_delete_empty_directory($parentDirectory, $moduleDir); + } +} + +function saferpayofficial_2_1_0_delete_empty_directory($directory, $moduleDir) +{ + while (strpos($directory, $moduleDir) === 0 && is_dir($directory)) { + $entries = scandir($directory); + + if ($entries === false || count($entries) > 2) { + return; + } + + @rmdir($directory); + $directory = dirname($directory); + } +} + +function saferpayofficial_2_1_0_delete_removed_configuration() +{ + Configuration::deleteByName('SAFERPAY_HOSTED_FIELDS_TEMPLATE'); }