1
|
|
|
<?php |
2
|
|
|
namespace Pagantis\Pagantis\Controller\Payment; |
3
|
|
|
|
4
|
|
|
use Magento\Framework\App\Action\Action; |
5
|
|
|
use Magento\Framework\App\ResourceConnection; |
6
|
|
|
use Magento\Framework\DB\Ddl\Table; |
7
|
|
|
use Magento\Framework\App\CsrfAwareActionInterface; |
8
|
|
|
use Magento\Framework\App\RequestInterface; |
9
|
|
|
use Magento\Framework\App\Request\InvalidRequestException; |
10
|
|
|
|
11
|
|
|
class LogV2 extends Action implements CsrfAwareActionInterface |
12
|
|
|
{ |
13
|
|
|
/** Concurrency tablename */ |
14
|
|
|
const LOGS_TABLE = 'Pagantis_logs'; |
15
|
|
|
|
16
|
|
|
/** @var mixed $config */ |
17
|
|
|
protected $config; |
18
|
|
|
|
19
|
|
|
/** @var ResourceConnection $dbObject */ |
20
|
|
|
protected $dbObject; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Log constructor. |
24
|
|
|
* |
25
|
|
|
* @param \Magento\Framework\App\Action\Context $context |
26
|
|
|
* @param \Pagantis\Pagantis\Helper\Config $pagantisConfig |
27
|
|
|
* @param ResourceConnection $dbObject |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
\Magento\Framework\App\Action\Context $context, |
31
|
|
|
\Pagantis\Pagantis\Helper\Config $pagantisConfig, |
32
|
|
|
ResourceConnection $dbObject |
33
|
|
|
) { |
34
|
|
|
$this->config = $pagantisConfig->getConfig(); |
35
|
|
|
$this->dbObject = $dbObject; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
return parent::__construct($context); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Main function |
43
|
|
|
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void |
44
|
|
|
*/ |
45
|
|
|
public function execute() |
46
|
|
|
{ |
47
|
|
|
try { |
48
|
|
|
$response = array(); |
49
|
|
|
$secretKey = $this->getRequest()->getParam('secret'); |
50
|
|
|
$privateKey = isset($this->config['pagantis_private_key']) ? $this->config['pagantis_private_key'] : null; |
51
|
|
|
|
52
|
|
|
if ($secretKey!='' && $privateKey!='') { |
53
|
|
|
$this->checkDbLogTable(); |
54
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
55
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
56
|
|
|
$tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
57
|
|
|
$sql = $dbConnection |
58
|
|
|
->select() |
59
|
|
|
->from($tableName, array('log', 'createdAt')); |
|
|
|
|
60
|
|
|
|
61
|
|
|
if ($dateFrom = $this->getRequest()->getParam('from')) { |
62
|
|
|
$sql->where('createdAt > ?', $dateFrom); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ($dateTo = $this->getRequest()->getParam('to')) { |
66
|
|
|
$sql->where('createdAt < ?', $dateTo); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$limit = ($this->getRequest()->getParam('limit')) ? $this->getRequest()->getParam('limit') : 50; |
70
|
|
|
$sql->limit($limit); |
71
|
|
|
$sql->order('createdAt', 'desc'); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$results = $dbConnection->fetchAll($sql); |
74
|
|
|
if (isset($results) && $privateKey == $secretKey) { |
75
|
|
|
foreach ($results as $key => $result) { |
76
|
|
|
$response[$key]['timestamp'] = $result['createdAt']; |
77
|
|
|
$response[$key]['log'] = json_decode($result['log']); |
78
|
|
|
} |
79
|
|
|
} else { |
80
|
|
|
$response['result'] = 'Error'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$response = json_encode($response); |
84
|
|
|
header("HTTP/1.1 200", true, 200); |
85
|
|
|
header('Content-Type: application/json', true); |
86
|
|
|
header('Content-Length: '.strlen($response)); |
87
|
|
|
echo($response); |
88
|
|
|
exit(); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
} catch (\Exception $e) { |
91
|
|
|
die($e->getMessage()); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return void|\Zend_Db_Statement_Interface |
97
|
|
|
* @throws \Zend_Db_Exception |
98
|
|
|
*/ |
99
|
|
|
private function checkDbLogTable() |
100
|
|
|
{ |
101
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
102
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
103
|
|
|
$tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
104
|
|
|
if (!$dbConnection->isTableExists($tableName)) { |
105
|
|
|
$table = $dbConnection |
106
|
|
|
->newTable($tableName) |
107
|
|
|
->addColumn( |
108
|
|
|
'id', |
109
|
|
|
Table::TYPE_SMALLINT, |
110
|
|
|
null, |
111
|
|
|
array('nullable'=>false, 'auto_increment'=>true, 'primary'=>true) |
112
|
|
|
) |
113
|
|
|
->addColumn('log', Table::TYPE_TEXT, null, array('nullable'=>false)) |
114
|
|
|
->addColumn( |
115
|
|
|
'createdAt', |
116
|
|
|
Table::TYPE_TIMESTAMP, |
117
|
|
|
null, |
118
|
|
|
array('nullable'=>false, |
119
|
|
|
'default'=>Table::TIMESTAMP_INIT) |
120
|
|
|
); |
121
|
|
|
return $dbConnection->createTable($table); |
122
|
|
|
} |
123
|
|
|
return; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param RequestInterface $request |
128
|
|
|
* |
129
|
|
|
* @return InvalidRequestException|null |
130
|
|
|
*/ |
131
|
|
|
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException |
132
|
|
|
{ |
133
|
|
|
return null; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param RequestInterface $request |
138
|
|
|
* |
139
|
|
|
* @return bool|null |
140
|
|
|
*/ |
141
|
|
|
public function validateForCsrf(RequestInterface $request): ?bool |
142
|
|
|
{ |
143
|
|
|
return true; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.