Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #47377 removing redundant files #359

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions classes/Form/TechnicalChecklistForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
21 changes: 21 additions & 0 deletions controllers/admin/AdminPaypalDiagnostic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,4 +41,24 @@ public function initPageHeaderToolbar()
parent::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();

if (Tools::isSubmit('remove_redundant_files')) {
$kit = new ToolKit();
$baseDir = _PS_MODULE_DIR_ . 'paypal/';

foreach ($this->module->getRedundantFiles() as $file) {
$kit->unlink($baseDir . $file);
}
}
}
}
29 changes: 29 additions & 0 deletions paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) && $file !== 'config.xml';
});
}
}
2 changes: 1 addition & 1 deletion services/Kit.php → services/ToolKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use Exception;
use Throwable;

class Kit
class ToolKit
{
public function rrmdir($dir)
{
Expand Down
1 change: 1 addition & 0 deletions translations/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_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]';
kgleizes marked this conversation as resolved.
Show resolved Hide resolved
$_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';
Expand Down
68 changes: 27 additions & 41 deletions upgrade/Upgrade-6.4.3.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*
*/

use PaypalPPBTlib\Extensions\Diagnostic\Stubs\Concrete\FileIntegrityStub;

if (!defined('_PS_VERSION_')) {
exit;
}
Expand All @@ -34,51 +36,35 @@
*
* @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',
];
$baseDir = _PS_MODULE_DIR_ . 'paypal/';
$diagnosticConf = include _PS_MODULE_DIR_ . 'paypal/diagnostic.php';

if (empty($diagnosticConf[0]['stubs'][FileIntegrityStub::class])) {
return true;
}

foreach ($dirs as $dir) {
$kit->rrmdir($baseDir . $dir);
$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 ($files as $file) {
$kit->unlink($baseDir . $file);
try {
unlink($baseDir . $file);
} catch (Exception $e) {
} catch (Throwable $e) {
}
}

return true;
Expand Down
16 changes: 16 additions & 0 deletions vendor/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Apache 2.2
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
<Files ~ "(?i)^.*\.(jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico|webp|woff|woff2|ttf|eot|otf|css|js|map)$">
bogdan202 marked this conversation as resolved.
Show resolved Hide resolved
Allow from all
</Files>
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
<Files ~ "(?i)^.*\.(jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico|webp|woff|woff2|ttf|eot|otf|css|js|map)$">
Require all granted
</Files>
</IfModule>
10 changes: 10 additions & 0 deletions views/templates/admin/_partials/statusBlock.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
</li>
{/if}
{/if}

{if isset($vars.numberRedundantFiles) && $vars.numberRedundantFiles}
<li class="d-flex mb-1">
{include
file=$moduleFullDir|cat:"/views/templates/admin/_partials/icon-status.tpl"
isSuccess=false
}
<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>
</li>
{/if}
</ul>
</div>

Expand Down
8 changes: 8 additions & 0 deletions views/templates/admin/diagnostic/file_integrity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
{/foreach}
</div>
{/if}

{if isset($isRedundantFileExist) && $isRedundantFileExist}
<div class="d-flex justify-content-center m-3">
<a href="{Context::getContext()->link->getAdminLink('AdminPaypalDiagnostic', true, [], ['remove_redundant_files' => 1])}" class="btn btn-primary">
{l s='Remove redundant files' mod='paypal'}
</a>
</div>
{/if}
</div>
</div>
</div>
Expand Down
Loading