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

SV-37 Added logging to front controllers #203

Merged
merged 43 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7678e2c
[SV-34] added Logger
MarijusCoding Oct 3, 2024
03bdc2b
[SV-34] added LoggerInterface
MarijusCoding Oct 3, 2024
f906c95
[SV-34] added LoggerInterface into BaseServiceProvider
MarijusCoding Oct 3, 2024
437b79a
[SV-34] added LOGGER
MarijusCoding Oct 3, 2024
53da130
revert cache
MarijusCoding Oct 3, 2024
83016ac
[SV-34] fix composer
MarijusCoding Oct 3, 2024
cfca8e1
[SV-34] REMOVED LOG
MarijusCoding Oct 3, 2024
ec5351e
[SV-34] fix
MarijusCoding Oct 3, 2024
a4cad9b
[SV-34] license
MarijusCoding Oct 3, 2024
1924110
[SV-34] license
MarijusCoding Oct 3, 2024
e4c9f69
[SV-37] added log to front controllers
MarijusCoding Oct 3, 2024
80155cd
fix
MarijusCoding Oct 3, 2024
5acb6eb
[SV-34] added logs
MarijusCoding Oct 3, 2024
565bb98
[SV-34] added more logs
MarijusCoding Oct 3, 2024
d09becb
[SV-34] more logs
MarijusCoding Oct 3, 2024
63a4d57
[SV-34] removed comments
MarijusCoding Oct 4, 2024
5ddd92c
Merge branch 'SV-34/logging-classes' of github.com:Invertus/saferpayo…
MarijusCoding Oct 4, 2024
66e5079
[SV-34] removed long-tail
MarijusCoding Oct 4, 2024
fa3df9e
[SV-34] typo
MarijusCoding Oct 4, 2024
1f0609a
[SV-34] typo
MarijusCoding Oct 4, 2024
b39824a
[SV-34] typo
MarijusCoding Oct 4, 2024
bb027a6
[SV-34] CS-FIXER
MarijusCoding Oct 4, 2024
2fb1293
[SV-34] typo
MarijusCoding Oct 4, 2024
43f81bf
Merge branch 'SV-34/logging-classes' of github.com:Invertus/saferpayo…
MarijusCoding Oct 4, 2024
06db095
[SV-37] more logs
MarijusCoding Oct 4, 2024
180b3f5
[SV-37] typos
MarijusCoding Oct 4, 2024
12d080b
added logs
MarijusCoding Oct 7, 2024
a6b656a
edited log
MarijusCoding Oct 7, 2024
26495f3
edit log
MarijusCoding Oct 7, 2024
176e6a6
[SV-37] added log
MarijusCoding Oct 7, 2024
34e06fd
added log
MarijusCoding Oct 7, 2024
417c4b3
fixed logs
MarijusCoding Oct 7, 2024
5461ee7
added logs
MarijusCoding Oct 7, 2024
aef6eac
fixed logs
MarijusCoding Oct 8, 2024
700fd9d
added exception messages
MarijusCoding Oct 8, 2024
2bd2046
fixed logs
MarijusCoding Oct 8, 2024
bb37f94
fix logs
MarijusCoding Oct 8, 2024
f1af893
fixes
MarijusCoding Oct 8, 2024
24ed687
fix
MarijusCoding Oct 8, 2024
f0951a8
fix
MarijusCoding Oct 8, 2024
fe4137c
removed status code
MarijusCoding Oct 8, 2024
f15c4fa
safe exception message from exception
MarijusCoding Oct 8, 2024
24aa0a1
Merge branch 'SV-27/logger-inferface' into SV-37/logging-controllers
MarijusCoding Oct 8, 2024
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
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
"phpunit/phpunit": "*",
"behat/behat": "*",
"symfony/translation": "*",
"prestashop/php-dev-tools": "^3.16",
"invertus/knapsack": "^10.0"
"prestashop/php-dev-tools": "^3.16"
},
"scripts": {
"test-integration": "./vendor/bin/phpunit --configuration ./tests/Integration/phpunit.xml",
Expand Down
57 changes: 32 additions & 25 deletions controllers/admin/AdminSaferPayOfficialLogsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@
*@license SIX Payment Services
*/

use Invertus\SaferPay\Adapter\LegacyContext;
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\Saferpay\Context\GlobalShopContext;
use Invertus\SaferPay\Controller\AbstractAdminSaferPayController;
use Invertus\SaferPay\Enum\PermissionType;
use Invertus\SaferPay\Logger\Formatter\LogFormatter;
use Invertus\SaferPay\Logger\LoggerInterface;
use Invertus\SaferPay\Repository\SaferPayLogRepository;
use Invertus\SaferPay\Utility\ExceptionUtility;
use Invertus\SaferPay\Utility\VersionUtility;
use Invertus\SaferPay\Logger\Logger;
use Invertus\SaferPay\Adapter\Tools;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -150,7 +156,8 @@ public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);

$context = $this->module->getService(\Invertus\SaferPay\Adapter\LegacyContext::class);
/** @var LegacyContext $context */
$context = $this->module->getService(LegacyContext::class);

Media::addJsDef([
'saferpayofficial' => [
Expand Down Expand Up @@ -239,19 +246,19 @@ public function displayAjaxGetLog()
return;
}

/** @var \Invertus\SaferPay\Adapter\Tools $tools */
$tools = $this->module->getService(\Invertus\SaferPay\Adapter\Tools::class);
/** @var Tools $tools */
$tools = $this->module->getService(Tools::class);

/** @var \Invertus\SaferPay\Repository\SaferPayLogRepository $logRepository */
$logRepository = $this->module->getService(\Invertus\SaferPay\Repository\SaferPayLogRepository::class);
/** @var SaferPayLogRepository $logRepository */
$logRepository = $this->module->getService(SaferPayLogRepository::class);

/** @var \Invertus\SaferPay\Context\GlobalShopContext $shopContext */
$globalShopContext = $this->module->getService(\Invertus\SaferPay\Context\GlobalShopContext::class);
/** @var GlobalShopContext $shopContext */
$globalShopContext = $this->module->getService(GlobalShopContext::class);

$logId = $tools->getValueAsInt('log_id');

// /** @var LoggerInterface $logger */
// $logger = $this->module->getService(LoggerInterface::class);
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

try {
/** @var \SaferPayLog|null $log */
Expand All @@ -260,13 +267,13 @@ public function displayAjaxGetLog()
'id_shop' => $globalShopContext->getShopId(),
]);
} catch (Exception $exception) {
// $logger->error('Failed to find log', [
// 'context' => [
// 'id_log' => $logId,
// 'id_shop' => $globalShopContext->getShopId(),
// ],
// 'exceptions' => ExceptionUtility::getExceptions($exception),
// ]);
$logger->error('Failed to find log', [
'context' => [
'id_log' => $logId,
'id_shop' => $globalShopContext->getShopId(),
],
'exceptions' => ExceptionUtility::getExceptions($exception),
]);

$this->ajaxResponse(json_encode([
'error' => true,
Expand All @@ -275,13 +282,13 @@ public function displayAjaxGetLog()
}

if (!isset($log)) {
// $logger->error('No log information found.', [
// 'context' => [
// 'id_log' => $logId,
// 'id_shop' => $globalShopContext->getShopId(),
// ],
// 'exceptions' => [],
// ]);
$logger->error('No log information found.', [
'context' => [
'id_log' => $logId,
'id_shop' => $globalShopContext->getShopId(),
],
'exceptions' => [],
]);

$this->ajaxRender(json_encode([
'error' => true,
Expand Down Expand Up @@ -316,8 +323,8 @@ public function processExport($textDelimiter = '"')
/** @var Configuration $configuration */
$configuration = $this->module->getService(Configuration::class);

/** @var \Invertus\SaferPay\Adapter\LegacyContext $context */
$context = $this->module->getService(\Invertus\SaferPay\Adapter\LegacyContext::class);
/** @var LegacyContext $context */
$context = $this->module->getService(LegacyContext::class);

$storeInfo = [
'PrestaShop Version' => _PS_VERSION_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function __construct()
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);

$this->addCSS("{$this->module->getPathUri()}views/css/admin/payment_method.css");
$this->addJS("{$this->module->getPathUri()}views/js/admin/chosen_countries.js");
$this->addJS("{$this->module->getPathUri()}views/js/admin/payment_method_all.js");
Expand Down
22 changes: 22 additions & 0 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Invertus\SaferPay\Controller\Front\CheckoutController;
use Invertus\SaferPay\Core\Payment\DTO\CheckoutData;
use Invertus\SaferPay\Enum\ControllerName;
use Invertus\SaferPay\Logger\LoggerInterface;
use Invertus\SaferPay\Repository\SaferPayOrderRepository;

if (!defined('_PS_VERSION_')) {
Expand All @@ -40,6 +41,11 @@ class SaferPayOfficialAjaxModuleFrontController extends ModuleFrontController

public function postProcess()
{
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->debug(sprintf('%s - Controller called', self::FILE_NAME));

switch (Tools::getValue('action')) {
case 'submitHostedFields':
$this->submitHostedFields();
Expand Down Expand Up @@ -90,6 +96,10 @@ protected function processGetStatus()
]
),
]));
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);
MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved

$logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME));
}

private function getFailControllerLink($cartId, $secureKey, $moduleId)
Expand Down Expand Up @@ -156,12 +166,24 @@ private function submitHostedFields()
'url' => $redirectUrl,
]));
} catch (Exception $e) {
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->error(sprintf('%s - Exception occurred', self::FILE_NAME), [
MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved
'message' => $e->getMessage(),
]);

$this->ajaxDie(json_encode([
'error' => true,
'message' => $e->getMessage(),
'url' => $this->getRedirectionToControllerUrl('fail'),
]));
}

/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME));
}

/**
Expand Down
10 changes: 10 additions & 0 deletions controllers/front/creditCards.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Logger\LoggerInterface;
use Invertus\SaferPay\Repository\SaferPayCardAliasRepository;

if (!defined('_PS_VERSION_')) {
Expand Down Expand Up @@ -54,6 +55,7 @@ public function display()
private function initCardList()
{
$customerId = $this->context->customer->id;

/** @var SaferPayCardAliasRepository $cardAliasRep */
$cardAliasRep = $this->module->getService(SaferPayCardAliasRepository::class);
$savedCustomerCards = $cardAliasRep->getSavedCardsByCustomerId($customerId);
Expand Down Expand Up @@ -83,6 +85,11 @@ private function initCardList()

public function postProcess()
{
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->debug(sprintf('%s - Controller called', self::FILE_NAME));

$selectedCard = Tools::getValue('saved_card_id');
if ($selectedCard) {
$cardAlias = new SaferPayCardAlias($selectedCard);
Expand All @@ -92,6 +99,9 @@ public function postProcess()
}
$this->errors[] = $this->module->l('Failed to removed credit card', self::FILENAME);
}

$logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME));

parent::postProcess();
}

Expand Down
9 changes: 9 additions & 0 deletions controllers/front/creditCards16.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Logger\LoggerInterface;
use Invertus\SaferPay\Repository\SaferPayCardAliasRepository;

if (!defined('_PS_VERSION_')) {
Expand Down Expand Up @@ -91,6 +92,11 @@ private function initCardList()

public function postProcess()
{
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->debug(sprintf('%s - Controller called', self::FILE_NAME));

$selectedCard = Tools::getValue('saved_card_id');
if ($selectedCard) {
$cardAlias = new SaferPayCardAlias($selectedCard);
Expand All @@ -100,6 +106,9 @@ public function postProcess()
}
$this->errors[] = $this->module->l('Failed to removed credit card', self::FILENAME);
}

$logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME));

parent::postProcess();
}

Expand Down
8 changes: 8 additions & 0 deletions controllers/front/fail.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Service\CartDuplicationService;
use Invertus\SaferPay\Logger\LoggerInterface;
use PrestaShop\PrestaShop\Adapter\Order\OrderPresenter;

if (!defined('_PS_VERSION_')) {
Expand Down Expand Up @@ -93,6 +94,11 @@ public function initContent()
{
parent::initContent();

/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->debug(sprintf('%s - Controller called', self::FILE_NAME));

$orderLink = $this->context->link->getPageLink(
'order',
true,
Expand All @@ -117,5 +123,7 @@ public function initContent()
false
)
);

MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved
$logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME));
}
}
8 changes: 8 additions & 0 deletions controllers/front/failIFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Enum\ControllerName;
use Invertus\SaferPay\Logger\LoggerInterface;

if (!defined('_PS_VERSION_')) {
exit;
Expand All @@ -48,6 +49,11 @@ public function initContent()
{
parent::initContent();

/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->debug(sprintf('%s - Controller called', self::FILE_NAME));

$orderLink = $this->context->link->getPageLink(
'order',
true,
Expand All @@ -64,6 +70,8 @@ public function initContent()
'redirectUrl' => $orderLink,
]);
$this->setTemplate('loading_16.tpl');
MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved

$logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME));
}

public function setMedia()
Expand Down
8 changes: 8 additions & 0 deletions controllers/front/failValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

use Invertus\SaferPay\Controller\AbstractSaferPayController;
use Invertus\SaferPay\Logger\LoggerInterface;
use Invertus\SaferPay\Repository\SaferPayOrderRepository;
use Invertus\SaferPay\Service\CartDuplicationService;

Expand All @@ -35,6 +36,11 @@ class SaferPayOfficialFailValidationModuleFrontController extends AbstractSaferP

public function postProcess()
{
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->debug(sprintf('%s - Controller called', self::FILE_NAME));

$cartId = Tools::getValue('cartId');
$orderId = Tools::getValue('orderId');
$secureKey = Tools::getValue('secureKey');
Expand Down Expand Up @@ -87,5 +93,7 @@ public function postProcess()
);

Tools::redirect($failUrl);

$logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME));
MarijusCoding marked this conversation as resolved.
Show resolved Hide resolved
}
}
8 changes: 8 additions & 0 deletions controllers/front/hostedIframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

use Invertus\SaferPay\Config\SaferPayConfig;
use Invertus\SaferPay\Logger\LoggerInterface;
use PrestaShop\PrestaShop\Core\Checkout\TermsAndConditions;

if (!defined('_PS_VERSION_')) {
Expand All @@ -34,6 +35,11 @@ class SaferPayOfficialHostedIframeModuleFrontController extends ModuleFrontContr

public function initContent()
{
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);

$logger->debug(sprintf('%s - Controller called', self::FILENAME));

parent::initContent();

$paymentMethod = Tools::getValue('saved_card_method');
Expand Down Expand Up @@ -63,6 +69,8 @@ public function initContent()
'_16.tpl'
);
}

$logger->debug(sprintf('%s - Controller action ended', self::FILENAME));
}

public function setMedia()
Expand Down
Loading