From a623694a9454bc01313641e1b9596b0ebc66c18d Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Thu, 15 Aug 2024 14:30:51 +0200 Subject: [PATCH 1/6] refs #47377 removing redundant files --- classes/Form/TechnicalChecklistForm.php | 2 + controllers/admin/AdminPaypalDiagnostic.php | 15 ++++++ paypal.php | 29 +++++++++++ services/{Kit.php => ToolKit.php} | 2 +- translations/fr.php | 1 + upgrade/Upgrade-6.4.3.php | 52 ++++--------------- .../templates/admin/_partials/statusBlock.tpl | 10 ++++ .../admin/diagnostic/file_integrity.tpl | 8 +++ 8 files changed, 75 insertions(+), 44 deletions(-) rename services/{Kit.php => ToolKit.php} (99%) diff --git a/classes/Form/TechnicalChecklistForm.php b/classes/Form/TechnicalChecklistForm.php index 25ee02ef..94131722 100644 --- a/classes/Form/TechnicalChecklistForm.php +++ b/classes/Form/TechnicalChecklistForm.php @@ -71,6 +71,8 @@ public function getDescription() 'accountConfigured' => $this->method == null ? false : $this->method->isConfigured(), 'sslActivated' => $this->module->isSslActive(), 'localizationUrl' => $this->context->link->getAdminLink('AdminLocalization', true), + 'numberRedundantFiles' => count($this->module->getRedundantFiles()), + 'diagnosticPage' => $this->context->link->getAdminLink('AdminPaypalDiagnostic', true), ]; if ($this->webhookOption->isEligibleContext()) { diff --git a/controllers/admin/AdminPaypalDiagnostic.php b/controllers/admin/AdminPaypalDiagnostic.php index e593a9e6..315b0091 100644 --- a/controllers/admin/AdminPaypalDiagnostic.php +++ b/controllers/admin/AdminPaypalDiagnostic.php @@ -31,6 +31,7 @@ require_once _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php'; +use PaypalAddons\services\ToolKit; use PaypalPPBTlib\Extensions\Diagnostic\Controllers\Admin\AdminDiagnosticController; class AdminPaypalDiagnosticController extends AdminDiagnosticController @@ -40,4 +41,18 @@ public function initPageHeaderToolbar() parent::initPageHeaderToolbar(); $this->context->smarty->clearAssign('help_link'); } + + public function initProcess() + { + parent::initProcess(); + + if (Tools::isSubmit('remove_redundant_files')) { + $kit = new ToolKit(); + $baseDir = _PS_MODULE_DIR_ . 'paypal/'; + + foreach ($this->module->getRedundantFiles() as $file) { + $kit->unlink($baseDir . $file); + } + } + } } diff --git a/paypal.php b/paypal.php index 3a53cc5a..c98b73fc 100755 --- a/paypal.php +++ b/paypal.php @@ -71,6 +71,7 @@ use PaypalAddons\services\WebhookService; use PaypalPPBTlib\Extensions\AbstractModuleExtension; use PaypalPPBTlib\Extensions\Diagnostic\DiagnosticExtension; +use PaypalPPBTlib\Extensions\Diagnostic\Stubs\Concrete\FileIntegrityStub; use PaypalPPBTlib\Extensions\ProcessLogger\ProcessLoggerExtension; use PaypalPPBTlib\Extensions\ProcessLogger\ProcessLoggerHandler; use PaypalPPBTlib\Install\ModuleInstaller; @@ -3089,4 +3090,32 @@ public function isConsiderGiftProductAsDiscount() { return version_compare(_PS_VERSION_, '1.7.4.4', '>=') && version_compare(_PS_VERSION_, '1.7.6', '<'); } + + public function getDiagnosticSettings() + { + return include _PS_MODULE_DIR_ . 'paypal/diagnostic.php'; + } + + public function getRedundantFiles() + { + $diagnosticConf = $this->getDiagnosticSettings(); + + if (empty($diagnosticConf[0]['stubs'][FileIntegrityStub::class])) { + return []; + } + + $stub = new FileIntegrityStub($diagnosticConf[0]['stubs'][FileIntegrityStub::class]); + $stub->setModule($this); + $response = $stub->getHandler()->handle(); + + if (empty($response['created'])) { + return []; + } + + return array_filter( + $response['created'], + function ($file) { + return !preg_match('/^config_[a-z]+\.xml$/', $file); + }); + } } diff --git a/services/Kit.php b/services/ToolKit.php similarity index 99% rename from services/Kit.php rename to services/ToolKit.php index 9b94187c..d9e7daf0 100644 --- a/services/Kit.php +++ b/services/ToolKit.php @@ -30,7 +30,7 @@ use Exception; use Throwable; -class Kit +class ToolKit { public function rrmdir($dir) { diff --git a/translations/fr.php b/translations/fr.php index cb2b70cd..be104a95 100644 --- a/translations/fr.php +++ b/translations/fr.php @@ -190,6 +190,7 @@ $_MODULE['<{paypal}prestashop>statusblock_b0fb9d7e6d4ed47cb12f3092943fafc2'] = 'Le protocole SSL doit être activé sur votre site.'; $_MODULE['<{paypal}prestashop>statusblock_ba54b8645ec3d87e95b4da1b5baad66f'] = 'L\'extension cURL PHP doit être activée sur votre serveur.'; $_MODULE['<{paypal}prestashop>statusblock_5914be43ea057f2fd9fa49180f5db5bf'] = 'Vous devez vous connecter à votre compte PayPal.'; +$_MODULE['<{paypal}prestashop>statusblock_82f36de89dc4b257c6fcf250404c295a'] = 'Vous avez des fichiers dans votre module PayPal qui ne sont pas présentes dans le contenu officiel. Voir plus de détails sur [a @href1@]page de diagnostic.[/a]'; $_MODULE['<{paypal}prestashop>helperoptioninfo_36c23650a89439d28101b389567fe2f5'] = 'Les logs avec ID de commande ne seront pas effacés.'; $_MODULE['<{paypal}prestashop>headerlogo_536b624906878dc3954749a6cef3b0fa'] = 'Activation en 2 étapes simples'; $_MODULE['<{paypal}prestashop>headerlogo_e269d95cbf9105896810d64a7307acdd'] = 'Activez le module PayPal pour commencer à vendre à plus de 300 millions de clients PayPal dans le monde entier'; diff --git a/upgrade/Upgrade-6.4.3.php b/upgrade/Upgrade-6.4.3.php index 478fe13f..910fa66f 100644 --- a/upgrade/Upgrade-6.4.3.php +++ b/upgrade/Upgrade-6.4.3.php @@ -29,56 +29,22 @@ exit; } +include _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php'; + /** * @param $module PayPal * * @return bool */ -function upgrade_module_6_4_3($module) +function upgrade_module_6_4_3(PayPal $module) { - $kit = new \PaypalAddons\services\Kit(); - $baseDir = _PS_ROOT_DIR_ . '/modules/paypal/'; - $dirs = [ - '_dev', - 'classes/APM', - 'views/templates/apm', - 'views/templates/admin/_partials/paypalBanner', - 'views/templates/admin/_partials/form/fields', - ]; - $files = [ - 'controllers/admin/AdminPayPalCustomizeCheckoutController.php', - 'controllers/admin/AdminPayPalHelpController.php', - 'controllers/admin/AdminPayPalInstallmentController.php', - 'controllers/admin/AdminPayPalLogsController.php', - 'controllers/admin/AdminPayPalPUIListenerController.php', - 'controllers/admin/AdminPayPalSetupController.php', - 'controllers/admin/AdminPaypalGetCredentialsController.php', - 'views/templates/admin/customizeCheckout.tpl', - 'views/templates/admin/help.tpl', - 'views/templates/admin/installment.tpl', - 'views/templates/admin/setup.tpl', - 'views/templates/admin/_partials/accountSettingsBlock.tpl', - 'views/templates/admin/_partials/blockPreviewButtonContext.tpl', - 'views/templates/admin/_partials/block_info.tpl', - 'views/templates/admin/_partials/carrierMap.tpl', - 'views/templates/admin/_partials/ecCredentialFields.tpl', - 'views/templates/admin/_partials/headerLogo.tpl', - 'views/templates/admin/_partials/helperOptionInfo.tpl', - 'views/templates/admin/_partials/mbCredentialsForm.tpl', - 'views/templates/admin/_partials/pppCredentialsForm.tpl', - 'views/templates/admin/_partials/roundingSettings.tpl', - 'views/templates/admin/_partials/switchSandboxBlock.tpl', - 'views/templates/admin/_partials/white-list.tpl', - 'views/templates/admin/_partials/form/colorDescriptions.tpl', - 'views/templates/admin/_partials/form/customizeStyleSection.tpl', - 'views/templates/admin/_partials/form/sectionTitle.tpl', - ]; + if (class_exists('\PaypalAddons\services\ToolKit')) { + $kit = new \PaypalAddons\services\ToolKit(); + $baseDir = _PS_MODULE_DIR_ . 'paypal/'; - foreach ($dirs as $dir) { - $kit->rrmdir($baseDir . $dir); - } - foreach ($files as $file) { - $kit->unlink($baseDir . $file); + foreach ($module->getRedundantFiles() as $file) { + $kit->unlink($baseDir . $file); + } } return true; diff --git a/views/templates/admin/_partials/statusBlock.tpl b/views/templates/admin/_partials/statusBlock.tpl index a0331a42..3c39114e 100644 --- a/views/templates/admin/_partials/statusBlock.tpl +++ b/views/templates/admin/_partials/statusBlock.tpl @@ -97,6 +97,16 @@ {/if} {/if} + + {if isset($vars.numberRedundantFiles) && $vars.numberRedundantFiles} +
  • + {include + file=$moduleFullDir|cat:"/views/templates/admin/_partials/icon-status.tpl" + isSuccess=false + } +
    {{l s='You have files in your PayPal module that are not included in the official content. See more detail on [a @href1@]diagnostic page.[/a]' mod='paypal'}|paypalreplace:['@href1@' =>{$vars.diagnosticPage|default:'#'}, '@target@' => {'target="blank"'}]}
    +
  • + {/if} diff --git a/views/templates/admin/diagnostic/file_integrity.tpl b/views/templates/admin/diagnostic/file_integrity.tpl index 3b8d608b..827454ea 100644 --- a/views/templates/admin/diagnostic/file_integrity.tpl +++ b/views/templates/admin/diagnostic/file_integrity.tpl @@ -87,6 +87,14 @@ {/foreach} {/if} + + {if !empty($created)} +
    + + {l s='Remove redundant files' mod='paypal'} + +
    + {/if} From da3f48178aed7ffe6fa4ee41b306f2284e6c050d Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Fri, 16 Aug 2024 17:14:39 +0200 Subject: [PATCH 2/6] refs #47377 error class not found during first upgrade --- paypal.php | 2 +- upgrade/Upgrade-6.4.3.php | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/paypal.php b/paypal.php index c98b73fc..7622456e 100755 --- a/paypal.php +++ b/paypal.php @@ -3115,7 +3115,7 @@ public function getRedundantFiles() return array_filter( $response['created'], function ($file) { - return !preg_match('/^config_[a-z]+\.xml$/', $file); + return !preg_match('/^config_[a-z]+\.xml$/', $file) && $file !== 'config.xml'; }); } } diff --git a/upgrade/Upgrade-6.4.3.php b/upgrade/Upgrade-6.4.3.php index 910fa66f..e8a6235b 100644 --- a/upgrade/Upgrade-6.4.3.php +++ b/upgrade/Upgrade-6.4.3.php @@ -25,12 +25,12 @@ * */ +use PaypalPPBTlib\Extensions\Diagnostic\Stubs\Concrete\FileIntegrityStub; + if (!defined('_PS_VERSION_')) { exit; } -include _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php'; - /** * @param $module PayPal * @@ -38,12 +38,32 @@ */ function upgrade_module_6_4_3(PayPal $module) { - if (class_exists('\PaypalAddons\services\ToolKit')) { - $kit = new \PaypalAddons\services\ToolKit(); - $baseDir = _PS_MODULE_DIR_ . 'paypal/'; + $baseDir = _PS_MODULE_DIR_ . 'paypal/'; + $diagnosticConf = include _PS_MODULE_DIR_ . 'paypal/diagnostic.php'; + + if (empty($diagnosticConf[0]['stubs'][FileIntegrityStub::class])) { + return true; + } + + $stub = new FileIntegrityStub($diagnosticConf[0]['stubs'][FileIntegrityStub::class]); + $stub->setModule($module); + $response = $stub->getHandler()->handle(); + + if (empty($response['created'])) { + return true; + } + + $files = array_filter( + $response['created'], + function ($file) { + return !preg_match('/^config_[a-z]+\.xml$/', $file) && $file !== 'config.xml'; + }); - foreach ($module->getRedundantFiles() as $file) { - $kit->unlink($baseDir . $file); + foreach ($files as $file) { + try { + unlink($baseDir . $file); + } catch (Exception $e) { + } catch (Throwable $e) { } } From ebb158ad4f69747d0ce695ebb319e743585a232a Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Fri, 16 Aug 2024 17:31:06 +0200 Subject: [PATCH 3/6] vendor/.htaccess --- vendor/.htaccess | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 vendor/.htaccess diff --git a/vendor/.htaccess b/vendor/.htaccess new file mode 100644 index 00000000..633bc3c6 --- /dev/null +++ b/vendor/.htaccess @@ -0,0 +1,16 @@ +# Apache 2.2 + + Order deny,allow + Deny from all + + Allow from all + + + +# Apache 2.4 + + Require all denied + + Require all granted + + From 1e1677a840b3116181ddc2d0459e1c6c1b2cdcdf Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Fri, 16 Aug 2024 18:00:01 +0200 Subject: [PATCH 4/6] refs #47377 visibility of button "remove redundant files" --- controllers/admin/AdminPaypalDiagnostic.php | 6 ++++++ views/templates/admin/diagnostic/file_integrity.tpl | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/controllers/admin/AdminPaypalDiagnostic.php b/controllers/admin/AdminPaypalDiagnostic.php index 315b0091..f23608cd 100644 --- a/controllers/admin/AdminPaypalDiagnostic.php +++ b/controllers/admin/AdminPaypalDiagnostic.php @@ -42,6 +42,12 @@ public function initPageHeaderToolbar() $this->context->smarty->clearAssign('help_link'); } + public function initContent() + { + $this->context->smarty->assign('isRedundantFileExist', count($this->module->getRedundantFiles()) > 0); + parent::initContent(); + } + public function initProcess() { parent::initProcess(); diff --git a/views/templates/admin/diagnostic/file_integrity.tpl b/views/templates/admin/diagnostic/file_integrity.tpl index 827454ea..e93a2079 100644 --- a/views/templates/admin/diagnostic/file_integrity.tpl +++ b/views/templates/admin/diagnostic/file_integrity.tpl @@ -88,7 +88,7 @@ {/if} - {if !empty($created)} + {if isset($isRedundantFileExist) && $isRedundantFileExist}
    {l s='Remove redundant files' mod='paypal'} From 2faf6e6f7ae2ac49ec2178b5d97d32ed4e051561 Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Fri, 16 Aug 2024 18:19:59 +0200 Subject: [PATCH 5/6] texts --- translations/fr.php | 2 +- views/templates/admin/_partials/statusBlock.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/translations/fr.php b/translations/fr.php index be104a95..5dacd49d 100644 --- a/translations/fr.php +++ b/translations/fr.php @@ -190,7 +190,7 @@ $_MODULE['<{paypal}prestashop>statusblock_b0fb9d7e6d4ed47cb12f3092943fafc2'] = 'Le protocole SSL doit être activé sur votre site.'; $_MODULE['<{paypal}prestashop>statusblock_ba54b8645ec3d87e95b4da1b5baad66f'] = 'L\'extension cURL PHP doit être activée sur votre serveur.'; $_MODULE['<{paypal}prestashop>statusblock_5914be43ea057f2fd9fa49180f5db5bf'] = 'Vous devez vous connecter à votre compte PayPal.'; -$_MODULE['<{paypal}prestashop>statusblock_82f36de89dc4b257c6fcf250404c295a'] = 'Vous avez des fichiers dans votre module PayPal qui ne sont pas présentes dans le contenu officiel. Voir plus de détails sur [a @href1@]page de diagnostic.[/a]'; +$_MODULE['<{paypal}prestashop>statusblock_85e650a9b75ce606496731a086c28d0b'] = 'Vous avez des fichiers dans votre module PayPal qui ne sont pas présentes dans le contenu officiel. Voir plus de détails sur [a @href1@]page de diagnostic.[/a]'; $_MODULE['<{paypal}prestashop>helperoptioninfo_36c23650a89439d28101b389567fe2f5'] = 'Les logs avec ID de commande ne seront pas effacés.'; $_MODULE['<{paypal}prestashop>headerlogo_536b624906878dc3954749a6cef3b0fa'] = 'Activation en 2 étapes simples'; $_MODULE['<{paypal}prestashop>headerlogo_e269d95cbf9105896810d64a7307acdd'] = 'Activez le module PayPal pour commencer à vendre à plus de 300 millions de clients PayPal dans le monde entier'; diff --git a/views/templates/admin/_partials/statusBlock.tpl b/views/templates/admin/_partials/statusBlock.tpl index 3c39114e..80119bbf 100644 --- a/views/templates/admin/_partials/statusBlock.tpl +++ b/views/templates/admin/_partials/statusBlock.tpl @@ -104,7 +104,7 @@ file=$moduleFullDir|cat:"/views/templates/admin/_partials/icon-status.tpl" isSuccess=false } -
    {{l s='You have files in your PayPal module that are not included in the official content. See more detail on [a @href1@]diagnostic page.[/a]' mod='paypal'}|paypalreplace:['@href1@' =>{$vars.diagnosticPage|default:'#'}, '@target@' => {'target="blank"'}]}
    +
    {{l s='You have files in your PayPal module that are not included in the official content. See more details on [a @href1@]diagnostic page.[/a]' mod='paypal'}|paypalreplace:['@href1@' =>{$vars.diagnosticPage|default:'#'}, '@target@' => {'target="blank"'}]}
    {/if} From b8bdf04ffbff7894189d935181efdba7c3e58482 Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Wed, 21 Aug 2024 10:21:43 +0200 Subject: [PATCH 6/6] small text modif --- translations/fr.php | 2 +- vendor/.htaccess | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/translations/fr.php b/translations/fr.php index 5dacd49d..ee7fbf43 100644 --- a/translations/fr.php +++ b/translations/fr.php @@ -190,7 +190,7 @@ $_MODULE['<{paypal}prestashop>statusblock_b0fb9d7e6d4ed47cb12f3092943fafc2'] = 'Le protocole SSL doit être activé sur votre site.'; $_MODULE['<{paypal}prestashop>statusblock_ba54b8645ec3d87e95b4da1b5baad66f'] = 'L\'extension cURL PHP doit être activée sur votre serveur.'; $_MODULE['<{paypal}prestashop>statusblock_5914be43ea057f2fd9fa49180f5db5bf'] = 'Vous devez vous connecter à votre compte PayPal.'; -$_MODULE['<{paypal}prestashop>statusblock_85e650a9b75ce606496731a086c28d0b'] = 'Vous avez des fichiers dans votre module PayPal qui ne sont pas présentes dans le contenu officiel. Voir plus de détails sur [a @href1@]page de diagnostic.[/a]'; +$_MODULE['<{paypal}prestashop>statusblock_85e650a9b75ce606496731a086c28d0b'] = 'Vous avez des fichiers dans votre module PayPal qui ne sont pas présents dans le contenu officiel. Voir plus de détails sur [a @href1@]page de diagnostic.[/a]'; $_MODULE['<{paypal}prestashop>helperoptioninfo_36c23650a89439d28101b389567fe2f5'] = 'Les logs avec ID de commande ne seront pas effacés.'; $_MODULE['<{paypal}prestashop>headerlogo_536b624906878dc3954749a6cef3b0fa'] = 'Activation en 2 étapes simples'; $_MODULE['<{paypal}prestashop>headerlogo_e269d95cbf9105896810d64a7307acdd'] = 'Activez le module PayPal pour commencer à vendre à plus de 300 millions de clients PayPal dans le monde entier'; diff --git a/vendor/.htaccess b/vendor/.htaccess index 633bc3c6..3de9e400 100644 --- a/vendor/.htaccess +++ b/vendor/.htaccess @@ -2,15 +2,9 @@ Order deny,allow Deny from all - - Allow from all - # Apache 2.4 Require all denied - - Require all granted -