1
|
|
|
<?php |
2
|
|
|
namespace DigitalOrigin\Pmt\Controller\Payment; |
3
|
|
|
|
4
|
|
|
use Magento\Framework\App\Action\Action; |
5
|
|
|
use Magento\Framework\App\ResourceConnection; |
6
|
|
|
use Magento\Framework\DB\Ddl\Table; |
7
|
|
|
|
8
|
|
|
class Log extends Action |
9
|
|
|
{ |
10
|
|
|
/** Concurrency tablename */ |
11
|
|
|
const LOGS_TABLE = 'pmt_logs'; |
12
|
|
|
|
13
|
|
|
/** @var mixed $config */ |
14
|
|
|
protected $config; |
15
|
|
|
|
16
|
|
|
/** @var ResourceConnection $dbObject */ |
17
|
|
|
protected $dbObject; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Log constructor. |
21
|
|
|
* |
22
|
|
|
* @param \Magento\Framework\App\Action\Context $context |
23
|
|
|
* @param \DigitalOrigin\Pmt\Helper\Config $pmtConfig |
24
|
|
|
* @param ResourceConnection $dbObject |
25
|
|
|
*/ |
26
|
|
|
public function __construct( |
27
|
|
|
\Magento\Framework\App\Action\Context $context, |
28
|
|
|
\DigitalOrigin\Pmt\Helper\Config $pmtConfig, |
29
|
|
|
ResourceConnection $dbObject |
30
|
|
|
) { |
31
|
|
|
$this->config = $pmtConfig->getConfig(); |
32
|
|
|
$this->dbObject = $dbObject; |
33
|
|
|
return parent::__construct($context); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Main function |
38
|
|
|
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void |
39
|
|
|
*/ |
40
|
|
|
public function execute() |
41
|
|
|
{ |
42
|
|
|
try { |
43
|
|
|
$response = array(); |
44
|
|
|
$secretKey = $this->getRequest()->getParam('secret'); |
45
|
|
|
$privateKey = isset($this->config['secret_key']) ? $this->config['secret_key'] : null; |
46
|
|
|
|
47
|
|
|
if ($secretKey!='' && $privateKey!='') { |
48
|
|
|
$this->checkDbLogTable(); |
49
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
50
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
51
|
|
|
$tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
52
|
|
|
$sql = $dbConnection |
53
|
|
|
->select() |
54
|
|
|
->from($tableName, array('log', 'createdAt')); |
|
|
|
|
55
|
|
|
|
56
|
|
|
if ($dateFrom = $this->getRequest()->getParam('from')) { |
57
|
|
|
$sql->where('createdAt > ?', $dateFrom); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($dateTo = $this->getRequest()->getParam('to')) { |
61
|
|
|
$sql->where('createdAt < ?', $dateTo); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$limit = ($this->getRequest()->getParam('limit')) ? $this->getRequest()->getParam('limit') : 50; |
65
|
|
|
$sql->limit($limit); |
66
|
|
|
$sql->order('createdAt', 'desc'); |
|
|
|
|
67
|
|
|
|
68
|
|
|
$results = $dbConnection->fetchAll($sql); |
69
|
|
|
if (isset($results) && $privateKey == $secretKey) { |
70
|
|
|
foreach ($results as $key => $result) { |
71
|
|
|
$response[$key]['timestamp'] = $result['createdAt']; |
72
|
|
|
$response[$key]['log'] = json_decode($result['log']); |
73
|
|
|
} |
74
|
|
|
} else { |
75
|
|
|
$response['result'] = 'Error'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$response = json_encode($response); |
79
|
|
|
header("HTTP/1.1 200", true, 200); |
80
|
|
|
header('Content-Type: application/json', true); |
81
|
|
|
header('Content-Length: '.strlen($response)); |
82
|
|
|
echo($response); |
83
|
|
|
exit(); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
} catch (\Exception $e) { |
86
|
|
|
die($e->getMessage()); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return void|\Zend_Db_Statement_Interface |
92
|
|
|
* @throws \Zend_Db_Exception |
93
|
|
|
*/ |
94
|
|
|
private function checkDbLogTable() |
95
|
|
|
{ |
96
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
97
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
98
|
|
|
$tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
99
|
|
|
if (!$dbConnection->isTableExists($tableName)) { |
100
|
|
|
$table = $dbConnection |
101
|
|
|
->newTable($tableName) |
102
|
|
|
->addColumn('id', Table::TYPE_SMALLINT, null, array('nullable'=>false, 'auto_increment'=>true, 'primary'=>true)) |
103
|
|
|
->addColumn('log', Table::TYPE_TEXT, null, array('nullable'=>false)) |
104
|
|
|
->addColumn('createdAt', Table::TYPE_TIMESTAMP, null, array('nullable'=>false, 'default'=>Table::TIMESTAMP_INIT)); |
105
|
|
|
return $dbConnection->createTable($table); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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.