|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Contains AdminController. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Drupal\mongodb_watchdog\Controller; |
|
9
|
|
|
|
|
10
|
|
|
use Drupal\Component\Utility\Unicode; |
|
11
|
|
|
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; |
|
12
|
|
|
use Drupal\Core\Url; |
|
13
|
|
|
use Drupal\mongodb_watchdog\Logger; |
|
14
|
|
|
use MongoDB\Database; |
|
15
|
|
|
use Psr\Log\LogLevel; |
|
16
|
|
|
use Psr\Log\LoggerInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class AdminController. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Drupal\mongodb_watchdog |
|
23
|
|
|
*/ |
|
24
|
|
|
class AdminController implements ContainerInjectionInterface { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The MongoDB database for the logger alias. |
|
28
|
|
|
* |
|
29
|
|
|
* @var \MongoDB |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $database; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The core logger channel, to log intervening events. |
|
35
|
|
|
* |
|
36
|
|
|
* @var \Psr\Log\LoggerInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $logger; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The MongoDB logger, to load events. |
|
42
|
|
|
* |
|
43
|
|
|
* @var \Drupal\mongodb_watchdog\Logger |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $watchdog; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Constructor. |
|
49
|
|
|
* |
|
50
|
|
|
* @param \MongoDB\Database $database |
|
51
|
|
|
* The watchdog database. |
|
52
|
|
|
* @param \Psr\Log\LoggerInterface $logger |
|
53
|
|
|
* The logger service, to log intervening events. |
|
54
|
|
|
* @param \Drupal\mongodb_watchdog\Logger $watchdog |
|
55
|
|
|
* The MongoDB logger, to load stored events. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct(Database $database, LoggerInterface $logger, Logger $watchdog) { |
|
58
|
|
|
$this->database = $database; |
|
|
|
|
|
|
59
|
|
|
$this->logger = $logger; |
|
60
|
|
|
$this->watchdog = $watchdog; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Controller for mongodb_watchdog.overview. |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
|
|
|
|
|
67
|
|
|
* A render array. |
|
68
|
|
|
*/ |
|
69
|
|
|
public function overview() { |
|
70
|
|
|
$icons = array( |
|
|
|
|
|
|
71
|
|
|
LogLevel::DEBUG => '', |
|
72
|
|
|
LogLevel::INFO => '', |
|
73
|
|
|
LogLevel::NOTICE => '', |
|
74
|
|
|
LogLevel::WARNING => ['#theme' => 'image', 'path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')], |
|
75
|
|
|
LogLevel::ERROR => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('error'), 'title' => t('error')], |
|
76
|
|
|
LogLevel::CRITICAL => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('critical'), 'title' => t('critical')], |
|
77
|
|
|
LogLevel::ALERT => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('alert'), 'title' => t('alert')], |
|
78
|
|
|
LogLevel::EMERGENCY => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('emergency'), 'title' => t('emergency')], |
|
79
|
|
|
); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
$collection = $this->database->selectCollection(Logger::TEMPLATE_COLLECTION); |
|
82
|
|
|
$cursor = $collection->find(); |
|
83
|
|
|
|
|
84
|
|
|
$header = array( |
|
85
|
|
|
// Icon column. |
|
86
|
|
|
'', |
|
87
|
|
|
t('#'), |
|
88
|
|
|
array('data' => t('Type')), |
|
89
|
|
|
array('data' => t('Date')), |
|
90
|
|
|
t('Source'), |
|
91
|
|
|
t('Message'), |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
$rows = array(); |
|
95
|
|
|
foreach ($cursor as $id => $value) { |
|
96
|
|
|
// dsm($value, $id); |
|
|
|
|
|
|
97
|
|
|
/* |
|
|
|
|
|
|
98
|
|
|
if ($value['type'] == 'php' && $value['message'] == '%type: %message in %function (line %line of %file).') { |
|
|
|
|
|
|
99
|
|
|
$collection = $this->logger->eventCollection($value['_id']); |
|
|
|
|
|
|
100
|
|
|
$result = $collection->find() |
|
|
|
|
|
|
101
|
|
|
->sort(array('$natural' => -1)) |
|
|
|
|
|
|
102
|
|
|
->limit(1) |
|
|
|
|
|
|
103
|
|
|
->getNext(); |
|
|
|
|
|
|
104
|
|
|
if ($value) { |
|
|
|
|
|
|
105
|
|
|
$value['file'] = basename($result['variables']['%file']); |
|
|
|
|
|
|
106
|
|
|
$value['line'] = $result['variables']['%line']; |
|
|
|
|
|
|
107
|
|
|
$value['message'] = '%type in %function'; |
|
|
|
|
|
|
108
|
|
|
$value['variables'] = $result['variables']; |
|
|
|
|
|
|
109
|
|
|
} |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
*/ |
|
|
|
|
|
|
112
|
|
|
$message = ''; //Unicode::truncate(strip_tags(SafeMarkup::format($value)), 56, TRUE, TRUE); |
|
|
|
|
|
|
113
|
|
|
//$value['count'] = $this->logger->eventCollection($value['_id'])->count(); |
|
|
|
|
|
|
114
|
|
|
$rows[$id] = array( |
|
115
|
|
|
//$icons[$value['severity']], |
|
|
|
|
|
|
116
|
|
|
isset($value['count']) && $value['count'] > 1 ? intval($value['count']) : 0, |
|
117
|
|
|
t($value['type']), |
|
|
|
|
|
|
118
|
|
|
empty($value['timestamp']) ? '' : format_date($value['timestamp'], 'short'), |
|
119
|
|
|
empty($value['file']) ? '' : Unicode::truncate(basename($value['file']), 30) . (empty($value['line']) ? '' : ('+' . $value['line'])), |
|
120
|
|
|
\Drupal::l($message, Url::fromRoute('mongodb_watchdog.reports.detail', ['event_template' => $id])), |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$build['mongodb_watchdog_table'] = array( |
|
|
|
|
|
|
125
|
|
|
'#theme' => 'table', |
|
126
|
|
|
'#header' => $header, |
|
127
|
|
|
'#rows' => $rows, |
|
128
|
|
|
'#attributes' => ['id' => 'admin-mongodb_watchdog'], |
|
129
|
|
|
); |
|
130
|
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
return $build; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* The controller factory. |
|
137
|
|
|
* |
|
138
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container |
|
139
|
|
|
* The DIC. |
|
140
|
|
|
* |
|
141
|
|
|
* @return static |
|
142
|
|
|
* The database instance. |
|
143
|
|
|
*/ |
|
144
|
|
View Code Duplication |
public static function create(ContainerInterface $container) { |
|
|
|
|
|
|
145
|
|
|
/** @var \MongoDB $database */ |
|
146
|
|
|
$database = $container->get('mongodb.watchdog_storage'); |
|
147
|
|
|
|
|
148
|
|
|
/** @var \Psr\Log\LoggerInterface $logger */ |
|
149
|
|
|
$logger = $container->get('logger.channel.mongodb_watchdog'); |
|
150
|
|
|
|
|
151
|
|
|
/** @var \Drupal\mongodb_watchdog\Logger $logger */ |
|
152
|
|
|
$watchdog = $container->get('mongodb.logger'); |
|
153
|
|
|
|
|
154
|
|
|
return new static($database, $logger, $watchdog); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
|
|
|
|
|
157
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..