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
mkdir($path);
}
$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(),
];
$summary = $this->collectSummary();
$dataFile = "$path/{$this->tag}.data";
$data = [];
foreach ($this->module->panels as $id => $panel) {
......@@ -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 0.
* @return integer
......@@ -149,9 +163,10 @@ class LogTarget extends Target
if (!isset($this->module->panels['db'])) {
return 0;
}
$profileLogs = $this->module->panels['db']->save();
$profileLogs = $this->module->panels['db']->getProfileLogs();
# / 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
*/
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
public $statusCode;
/**
*
* @var integer sql count attribute input search value
*/
public $sqlCount;
/**
* @var integer total mail count attribute input search value
*/
public $mailCount;
/**
* @var array critical codes, used to determine grid row options.
*/
public $criticalCodes = [400, 404, 500];
......@@ -66,7 +70,7 @@ class Debug extends Base
public function rules()
{
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
'ajax' => 'Ajax',
'url' => 'url',
'statusCode' => 'Status code',
'sqlCount' => 'Total queries',
'sqlCount' => 'Query Count',
'mailCount' => 'Mail Count',
];
}
......@@ -97,7 +102,7 @@ class Debug extends Base
$dataProvider = new ArrayDataProvider([
'allModels' => $models,
'sort' => [
'attributes' => ['method', 'ip', 'tag', 'time', 'statusCode', 'sqlCount'],
'attributes' => ['method', 'ip', 'tag', 'time', 'statusCode', 'sqlCount', 'mailCount'],
],
'pagination' => [
'pageSize' => 50,
......@@ -116,6 +121,7 @@ class Debug extends Base
$this->addCondition($filter, 'url', true);
$this->addCondition($filter, 'statusCode');
$this->addCondition($filter, 'sqlCount');
$this->addCondition($filter, 'mailCount');
$dataProvider->allModels = $filter->filter($models);
return $dataProvider;
......
......@@ -94,9 +94,18 @@ class DbPanel extends Panel
*/
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;
$messages = $target->filterMessages($target->messages, Logger::LEVEL_PROFILE, ['yii\db\Command::query', 'yii\db\Command::execute']);
return ['messages' => $messages];
return $target->filterMessages($target->messages, Logger::LEVEL_PROFILE, ['yii\db\Command::query', 'yii\db\Command::execute']);
}
/**
......@@ -164,4 +173,5 @@ class DbPanel extends Panel
{
return (($this->criticalQueryThreshold !== null) && ($count > $this->criticalQueryThreshold));
}
}
......@@ -77,6 +77,16 @@ class MailPanel extends Panel
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;
}
......
......@@ -68,7 +68,7 @@ if (isset($this->context->module->panels['db']) && isset($this->context->module-
'ip',
[
'attribute' => 'sqlCount',
'label' => 'Total queries',
'label' => 'Query Count',
'value' => function ($data) {
$dbPanel = $this->context->module->panels['db'];
......@@ -86,6 +86,10 @@ if (isset($this->context->module->panels['db']) && isset($this->context->module-
'format' => 'html',
],
[
'attribute' => 'mailCount',
'visible' => isset($this->context->module->panels['mail']),
],
[
'attribute' => 'method',
'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