Skip to content

Commit c36624d

Browse files
authored
Merge pull request #359 from 202ecommerce/feature/47377-remove_redundant_files
refs #47377 removing redundant files
2 parents 260a6a0 + b8bdf04 commit c36624d

File tree

9 files changed

+109
-42
lines changed

9 files changed

+109
-42
lines changed

classes/Form/TechnicalChecklistForm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function getDescription()
7171
'accountConfigured' => $this->method == null ? false : $this->method->isConfigured(),
7272
'sslActivated' => $this->module->isSslActive(),
7373
'localizationUrl' => $this->context->link->getAdminLink('AdminLocalization', true),
74+
'numberRedundantFiles' => count($this->module->getRedundantFiles()),
75+
'diagnosticPage' => $this->context->link->getAdminLink('AdminPaypalDiagnostic', true),
7476
];
7577

7678
if ($this->webhookOption->isEligibleContext()) {

controllers/admin/AdminPaypalDiagnostic.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
require_once _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php';
3333

34+
use PaypalAddons\services\ToolKit;
3435
use PaypalPPBTlib\Extensions\Diagnostic\Controllers\Admin\AdminDiagnosticController;
3536

3637
class AdminPaypalDiagnosticController extends AdminDiagnosticController
@@ -40,4 +41,24 @@ public function initPageHeaderToolbar()
4041
parent::initPageHeaderToolbar();
4142
$this->context->smarty->clearAssign('help_link');
4243
}
44+
45+
public function initContent()
46+
{
47+
$this->context->smarty->assign('isRedundantFileExist', count($this->module->getRedundantFiles()) > 0);
48+
parent::initContent();
49+
}
50+
51+
public function initProcess()
52+
{
53+
parent::initProcess();
54+
55+
if (Tools::isSubmit('remove_redundant_files')) {
56+
$kit = new ToolKit();
57+
$baseDir = _PS_MODULE_DIR_ . 'paypal/';
58+
59+
foreach ($this->module->getRedundantFiles() as $file) {
60+
$kit->unlink($baseDir . $file);
61+
}
62+
}
63+
}
4364
}

paypal.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
use PaypalAddons\services\WebhookService;
7272
use PaypalPPBTlib\Extensions\AbstractModuleExtension;
7373
use PaypalPPBTlib\Extensions\Diagnostic\DiagnosticExtension;
74+
use PaypalPPBTlib\Extensions\Diagnostic\Stubs\Concrete\FileIntegrityStub;
7475
use PaypalPPBTlib\Extensions\ProcessLogger\ProcessLoggerExtension;
7576
use PaypalPPBTlib\Extensions\ProcessLogger\ProcessLoggerHandler;
7677
use PaypalPPBTlib\Install\ModuleInstaller;
@@ -3098,4 +3099,32 @@ public function isConsiderGiftProductAsDiscount()
30983099
{
30993100
return version_compare(_PS_VERSION_, '1.7.4.4', '>=') && version_compare(_PS_VERSION_, '1.7.6', '<');
31003101
}
3102+
3103+
public function getDiagnosticSettings()
3104+
{
3105+
return include _PS_MODULE_DIR_ . 'paypal/diagnostic.php';
3106+
}
3107+
3108+
public function getRedundantFiles()
3109+
{
3110+
$diagnosticConf = $this->getDiagnosticSettings();
3111+
3112+
if (empty($diagnosticConf[0]['stubs'][FileIntegrityStub::class])) {
3113+
return [];
3114+
}
3115+
3116+
$stub = new FileIntegrityStub($diagnosticConf[0]['stubs'][FileIntegrityStub::class]);
3117+
$stub->setModule($this);
3118+
$response = $stub->getHandler()->handle();
3119+
3120+
if (empty($response['created'])) {
3121+
return [];
3122+
}
3123+
3124+
return array_filter(
3125+
$response['created'],
3126+
function ($file) {
3127+
return !preg_match('/^config_[a-z]+\.xml$/', $file) && $file !== 'config.xml';
3128+
});
3129+
}
31013130
}

services/Kit.php renamed to services/ToolKit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use Exception;
3131
use Throwable;
3232

33-
class Kit
33+
class ToolKit
3434
{
3535
public function rrmdir($dir)
3636
{

translations/fr.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
$_MODULE['<{paypal}prestashop>statusblock_b0fb9d7e6d4ed47cb12f3092943fafc2'] = 'Le protocole SSL doit être activé sur votre site.';
191191
$_MODULE['<{paypal}prestashop>statusblock_ba54b8645ec3d87e95b4da1b5baad66f'] = 'L\'extension cURL PHP doit être activée sur votre serveur.';
192192
$_MODULE['<{paypal}prestashop>statusblock_5914be43ea057f2fd9fa49180f5db5bf'] = 'Vous devez vous connecter à votre compte PayPal.';
193+
$_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]';
193194
$_MODULE['<{paypal}prestashop>helperoptioninfo_36c23650a89439d28101b389567fe2f5'] = 'Les logs avec ID de commande ne seront pas effacés.';
194195
$_MODULE['<{paypal}prestashop>headerlogo_536b624906878dc3954749a6cef3b0fa'] = 'Activation en 2 étapes simples';
195196
$_MODULE['<{paypal}prestashop>headerlogo_e269d95cbf9105896810d64a7307acdd'] = 'Activez le module PayPal pour commencer à vendre à plus de 300 millions de clients PayPal dans le monde entier';

upgrade/Upgrade-6.4.3.php

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*
2626
*/
2727

28+
use PaypalPPBTlib\Extensions\Diagnostic\Stubs\Concrete\FileIntegrityStub;
29+
2830
if (!defined('_PS_VERSION_')) {
2931
exit;
3032
}
@@ -34,51 +36,35 @@
3436
*
3537
* @return bool
3638
*/
37-
function upgrade_module_6_4_3($module)
39+
function upgrade_module_6_4_3(PayPal $module)
3840
{
39-
$kit = new \PaypalAddons\services\Kit();
40-
$baseDir = _PS_ROOT_DIR_ . '/modules/paypal/';
41-
$dirs = [
42-
'_dev',
43-
'classes/APM',
44-
'views/templates/apm',
45-
'views/templates/admin/_partials/paypalBanner',
46-
'views/templates/admin/_partials/form/fields',
47-
];
48-
$files = [
49-
'controllers/admin/AdminPayPalCustomizeCheckoutController.php',
50-
'controllers/admin/AdminPayPalHelpController.php',
51-
'controllers/admin/AdminPayPalInstallmentController.php',
52-
'controllers/admin/AdminPayPalLogsController.php',
53-
'controllers/admin/AdminPayPalPUIListenerController.php',
54-
'controllers/admin/AdminPayPalSetupController.php',
55-
'controllers/admin/AdminPaypalGetCredentialsController.php',
56-
'views/templates/admin/customizeCheckout.tpl',
57-
'views/templates/admin/help.tpl',
58-
'views/templates/admin/installment.tpl',
59-
'views/templates/admin/setup.tpl',
60-
'views/templates/admin/_partials/accountSettingsBlock.tpl',
61-
'views/templates/admin/_partials/blockPreviewButtonContext.tpl',
62-
'views/templates/admin/_partials/block_info.tpl',
63-
'views/templates/admin/_partials/carrierMap.tpl',
64-
'views/templates/admin/_partials/ecCredentialFields.tpl',
65-
'views/templates/admin/_partials/headerLogo.tpl',
66-
'views/templates/admin/_partials/helperOptionInfo.tpl',
67-
'views/templates/admin/_partials/mbCredentialsForm.tpl',
68-
'views/templates/admin/_partials/pppCredentialsForm.tpl',
69-
'views/templates/admin/_partials/roundingSettings.tpl',
70-
'views/templates/admin/_partials/switchSandboxBlock.tpl',
71-
'views/templates/admin/_partials/white-list.tpl',
72-
'views/templates/admin/_partials/form/colorDescriptions.tpl',
73-
'views/templates/admin/_partials/form/customizeStyleSection.tpl',
74-
'views/templates/admin/_partials/form/sectionTitle.tpl',
75-
];
41+
$baseDir = _PS_MODULE_DIR_ . 'paypal/';
42+
$diagnosticConf = include _PS_MODULE_DIR_ . 'paypal/diagnostic.php';
43+
44+
if (empty($diagnosticConf[0]['stubs'][FileIntegrityStub::class])) {
45+
return true;
46+
}
7647

77-
foreach ($dirs as $dir) {
78-
$kit->rrmdir($baseDir . $dir);
48+
$stub = new FileIntegrityStub($diagnosticConf[0]['stubs'][FileIntegrityStub::class]);
49+
$stub->setModule($module);
50+
$response = $stub->getHandler()->handle();
51+
52+
if (empty($response['created'])) {
53+
return true;
7954
}
55+
56+
$files = array_filter(
57+
$response['created'],
58+
function ($file) {
59+
return !preg_match('/^config_[a-z]+\.xml$/', $file) && $file !== 'config.xml';
60+
});
61+
8062
foreach ($files as $file) {
81-
$kit->unlink($baseDir . $file);
63+
try {
64+
unlink($baseDir . $file);
65+
} catch (Exception $e) {
66+
} catch (Throwable $e) {
67+
}
8268
}
8369

8470
return true;

vendor/.htaccess

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Apache 2.2
2+
<IfModule !mod_authz_core.c>
3+
Order deny,allow
4+
Deny from all
5+
</IfModule>
6+
7+
# Apache 2.4
8+
<IfModule mod_authz_core.c>
9+
Require all denied
10+
</IfModule>

views/templates/admin/_partials/statusBlock.tpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@
9797
</li>
9898
{/if}
9999
{/if}
100+
101+
{if isset($vars.numberRedundantFiles) && $vars.numberRedundantFiles}
102+
<li class="d-flex mb-1">
103+
{include
104+
file=$moduleFullDir|cat:"/views/templates/admin/_partials/icon-status.tpl"
105+
isSuccess=false
106+
}
107+
<div>{{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"'}]}</div>
108+
</li>
109+
{/if}
100110
</ul>
101111
</div>
102112

views/templates/admin/diagnostic/file_integrity.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@
8787
{/foreach}
8888
</div>
8989
{/if}
90+
91+
{if isset($isRedundantFileExist) && $isRedundantFileExist}
92+
<div class="d-flex justify-content-center m-3">
93+
<a href="{Context::getContext()->link->getAdminLink('AdminPaypalDiagnostic', true, [], ['remove_redundant_files' => 1])}" class="btn btn-primary">
94+
{l s='Remove redundant files' mod='paypal'}
95+
</a>
96+
</div>
97+
{/if}
9098
</div>
9199
</div>
92100
</div>

0 commit comments

Comments
 (0)