Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
115 changes: 114 additions & 1 deletion upgrade/install-2.1.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -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');
}
Loading