Commit f198f655 by Qiang Xue

Merge pull request #2438 from Ragazzo/debug_module_mail_improvements

Debug module mail improvements
parents edb6bca1 5534b513
...@@ -47,19 +47,7 @@ class LogTarget extends Target ...@@ -47,19 +47,7 @@ class LogTarget extends Target
mkdir($path); mkdir($path);
} }
$request = Yii::$app->getRequest(); $summary = $this->collectSummary();
$response = Yii::$app->getResponse();
$summary = [
'tag' => $this->tag,
'url' => $request->getAbsoluteUrl(),
'ajax' => $request->getIsAjax(),
'method' => $request->getMethod(),
'ip' => $request->getUserIP(),
'time' => time(),
'statusCode' => $response->statusCode,
'sqlCount' => $this->getSqlTotalCount(),
];
$dataFile = "$path/{$this->tag}.data"; $dataFile = "$path/{$this->tag}.data";
$data = []; $data = [];
foreach ($this->module->panels as $id => $panel) { foreach ($this->module->panels as $id => $panel) {
...@@ -140,6 +128,32 @@ class LogTarget extends Target ...@@ -140,6 +128,32 @@ class LogTarget extends Target
} }
/** /**
* Collects summary data of current request.
* @return array
*/
protected function collectSummary()
{
$request = Yii::$app->getRequest();
$response = Yii::$app->getResponse();
$summary = [
'tag' => $this->tag,
'url' => $request->getAbsoluteUrl(),
'ajax' => $request->getIsAjax(),
'method' => $request->getMethod(),
'ip' => $request->getUserIP(),
'time' => time(),
'statusCode' => $response->statusCode,
'sqlCount' => $this->getSqlTotalCount(),
];
if (isset($this->module->panels['mail'])) {
$summary['mailCount'] = count($this->module->panels['mail']->getMessages());
}
return $summary;
}
/**
* Returns total sql count executed in current request. If database panel is not configured * Returns total sql count executed in current request. If database panel is not configured
* returns 0. * returns 0.
* @return integer * @return integer
...@@ -149,9 +163,10 @@ class LogTarget extends Target ...@@ -149,9 +163,10 @@ class LogTarget extends Target
if (!isset($this->module->panels['db'])) { if (!isset($this->module->panels['db'])) {
return 0; return 0;
} }
$profileLogs = $this->module->panels['db']->save(); $profileLogs = $this->module->panels['db']->getProfileLogs();
# / 2 because messages are in couple (begin/end) # / 2 because messages are in couple (begin/end)
return count($profileLogs['messages']) / 2; return count($profileLogs) / 2;
} }
} }
...@@ -35,6 +35,7 @@ abstract class Base extends Component implements MatcherInterface ...@@ -35,6 +35,7 @@ abstract class Base extends Component implements MatcherInterface
*/ */
public function hasValue() public function hasValue()
{ {
return !empty($this->baseValue) || $this->baseValue === 0; return !empty($this->baseValue) || ($this->baseValue === '0');
} }
} }
...@@ -50,12 +50,16 @@ class Debug extends Base ...@@ -50,12 +50,16 @@ class Debug extends Base
public $statusCode; public $statusCode;
/** /**
*
* @var integer sql count attribute input search value * @var integer sql count attribute input search value
*/ */
public $sqlCount; public $sqlCount;
/** /**
* @var integer total mail count attribute input search value
*/
public $mailCount;
/**
* @var array critical codes, used to determine grid row options. * @var array critical codes, used to determine grid row options.
*/ */
public $criticalCodes = [400, 404, 500]; public $criticalCodes = [400, 404, 500];
...@@ -66,7 +70,7 @@ class Debug extends Base ...@@ -66,7 +70,7 @@ class Debug extends Base
public function rules() public function rules()
{ {
return [ return [
[['tag', 'ip', 'method', 'ajax', 'url', 'statusCode', 'sqlCount'], 'safe'], [['tag', 'ip', 'method', 'ajax', 'url', 'statusCode', 'sqlCount', 'mailCount'], 'safe'],
]; ];
} }
...@@ -82,7 +86,8 @@ class Debug extends Base ...@@ -82,7 +86,8 @@ class Debug extends Base
'ajax' => 'Ajax', 'ajax' => 'Ajax',
'url' => 'url', 'url' => 'url',
'statusCode' => 'Status code', 'statusCode' => 'Status code',
'sqlCount' => 'Total queries', 'sqlCount' => 'Query Count',
'mailCount' => 'Mail Count',
]; ];
} }
...@@ -97,7 +102,7 @@ class Debug extends Base ...@@ -97,7 +102,7 @@ class Debug extends Base
$dataProvider = new ArrayDataProvider([ $dataProvider = new ArrayDataProvider([
'allModels' => $models, 'allModels' => $models,
'sort' => [ 'sort' => [
'attributes' => ['method', 'ip', 'tag', 'time', 'statusCode', 'sqlCount'], 'attributes' => ['method', 'ip', 'tag', 'time', 'statusCode', 'sqlCount', 'mailCount'],
], ],
'pagination' => [ 'pagination' => [
'pageSize' => 50, 'pageSize' => 50,
...@@ -116,6 +121,7 @@ class Debug extends Base ...@@ -116,6 +121,7 @@ class Debug extends Base
$this->addCondition($filter, 'url', true); $this->addCondition($filter, 'url', true);
$this->addCondition($filter, 'statusCode'); $this->addCondition($filter, 'statusCode');
$this->addCondition($filter, 'sqlCount'); $this->addCondition($filter, 'sqlCount');
$this->addCondition($filter, 'mailCount');
$dataProvider->allModels = $filter->filter($models); $dataProvider->allModels = $filter->filter($models);
return $dataProvider; return $dataProvider;
......
...@@ -94,9 +94,18 @@ class DbPanel extends Panel ...@@ -94,9 +94,18 @@ class DbPanel extends Panel
*/ */
public function save() public function save()
{ {
return ['messages' => $this->getProfileLogs()];
}
/**
* Returns all profile logs of the current request for this panel. It includes categories such as:
* 'yii\db\Command::query', 'yii\db\Command::execute'.
* @return array
*/
public function getProfileLogs()
{
$target = $this->module->logTarget; $target = $this->module->logTarget;
$messages = $target->filterMessages($target->messages, Logger::LEVEL_PROFILE, ['yii\db\Command::query', 'yii\db\Command::execute']); return $target->filterMessages($target->messages, Logger::LEVEL_PROFILE, ['yii\db\Command::query', 'yii\db\Command::execute']);
return ['messages' => $messages];
} }
/** /**
...@@ -164,4 +173,5 @@ class DbPanel extends Panel ...@@ -164,4 +173,5 @@ class DbPanel extends Panel
{ {
return (($this->criticalQueryThreshold !== null) && ($count > $this->criticalQueryThreshold)); return (($this->criticalQueryThreshold !== null) && ($count > $this->criticalQueryThreshold));
} }
} }
...@@ -77,6 +77,16 @@ class MailPanel extends Panel ...@@ -77,6 +77,16 @@ class MailPanel extends Panel
public function save() public function save()
{ {
return $this->getMessages();
}
/**
* Returns info about messages of current request. Each element is array holding
* message info, such as: time, reply, bc, cc, from, to and other.
* @return array messages
*/
public function getMessages()
{
return $this->_messages; return $this->_messages;
} }
......
...@@ -68,7 +68,7 @@ if (isset($this->context->module->panels['db']) && isset($this->context->module- ...@@ -68,7 +68,7 @@ if (isset($this->context->module->panels['db']) && isset($this->context->module-
'ip', 'ip',
[ [
'attribute' => 'sqlCount', 'attribute' => 'sqlCount',
'label' => 'Total queries', 'label' => 'Query Count',
'value' => function ($data) { 'value' => function ($data) {
$dbPanel = $this->context->module->panels['db']; $dbPanel = $this->context->module->panels['db'];
...@@ -86,6 +86,10 @@ if (isset($this->context->module->panels['db']) && isset($this->context->module- ...@@ -86,6 +86,10 @@ if (isset($this->context->module->panels['db']) && isset($this->context->module-
'format' => 'html', 'format' => 'html',
], ],
[ [
'attribute' => 'mailCount',
'visible' => isset($this->context->module->panels['mail']),
],
[
'attribute' => 'method', 'attribute' => 'method',
'filter' => ['get' => 'GET', 'post' => 'POST', 'delete' => 'DELETE', 'put' => 'PUT', 'head' => 'HEAD'] 'filter' => ['get' => 'GET', 'post' => 'POST', 'delete' => 'DELETE', 'put' => 'PUT', 'head' => 'HEAD']
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment