|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package CLI |
|
5
|
|
|
* @author Iurii Makukh <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2018, Iurii Makukh <[email protected]> |
|
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace gplcart\modules\cli\controllers; |
|
11
|
|
|
|
|
12
|
|
|
use gplcart\core\models\Report as ReportModel; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Handles commands related to system events (logs) |
|
16
|
|
|
*/ |
|
17
|
|
|
class Event extends Base |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Report model class instance |
|
22
|
|
|
* @var \gplcart\core\models\Report $report |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $report; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param ReportModel $report |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(ReportModel $report) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
|
|
33
|
|
|
$this->report = $report; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Callback for "event-get" command |
|
38
|
|
|
*/ |
|
39
|
|
|
public function cmdGetEvent() |
|
40
|
|
|
{ |
|
41
|
|
|
$result = $this->getListEvent(); |
|
42
|
|
|
$this->outputFormat($result); |
|
43
|
|
|
$this->outputFormatTableEvent($result); |
|
44
|
|
|
$this->output(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Callback for "event-delete" command |
|
49
|
|
|
*/ |
|
50
|
|
|
public function cmdDeleteEvent() |
|
51
|
|
|
{ |
|
52
|
|
|
if ($this->getParam('expired')) { |
|
53
|
|
|
$this->report->deleteExpired(); |
|
54
|
|
|
} else { |
|
55
|
|
|
$this->report->delete(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$this->output(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Returns an array of events |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function getListEvent() |
|
66
|
|
|
{ |
|
67
|
|
|
$options = array( |
|
68
|
|
|
'order' => 'desc', |
|
69
|
|
|
'sort' => 'created', |
|
70
|
|
|
'limit' => $this->getLimit(), |
|
71
|
|
|
'severity' => $this->getParam('severity') |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
return (array) $this->report->getList($options); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Output events in a table |
|
79
|
|
|
* @param array $events |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function outputFormatTableEvent(array $events) |
|
82
|
|
|
{ |
|
83
|
|
|
$header = array( |
|
84
|
|
|
$this->text('Text'), |
|
85
|
|
|
$this->text('Type'), |
|
86
|
|
|
$this->text('Severity'), |
|
87
|
|
|
$this->text('Created') |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$rows = array(); |
|
91
|
|
|
|
|
92
|
|
|
foreach ($events as $item) { |
|
93
|
|
|
$text = empty($item['translatable']) ? $item['text'] : $this->text($item['text']); |
|
94
|
|
|
$rows[] = array( |
|
95
|
|
|
$this->truncate($text, 50), |
|
96
|
|
|
$this->text($item['type']), |
|
97
|
|
|
$this->text($item['severity']), |
|
98
|
|
|
$this->date($item['created']), |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$this->outputFormatTable($rows, $header); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|