From 00ac4f7648184ff3c28751905ed4737d91e9926e Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Fri, 13 Jun 2014 15:57:28 +0300 Subject: [PATCH 1/4] Added a debug toolbar panel for MongoDB --- extensions/mongodb/CHANGELOG.md | 1 + extensions/mongodb/README.md | 28 ++++++++++++++- extensions/mongodb/debug/MongoDbPanel.php | 43 +++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 extensions/mongodb/debug/MongoDbPanel.php diff --git a/extensions/mongodb/CHANGELOG.md b/extensions/mongodb/CHANGELOG.md index 05558632f2..978f591af0 100644 --- a/extensions/mongodb/CHANGELOG.md +++ b/extensions/mongodb/CHANGELOG.md @@ -7,6 +7,7 @@ Yii Framework 2 mongodb extension Change Log - Bug #3385: Fixed "The 'connected' property is deprecated" (samdark) - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh: Gii generator for Active Record model added (klimov-paul) +- Enh: Added a debug toolbar panel for MongoDB (klimov-paul) 2.0.0-beta April 13, 2014 diff --git a/extensions/mongodb/README.md b/extensions/mongodb/README.md index 28f456ed3a..49250c10b4 100644 --- a/extensions/mongodb/README.md +++ b/extensions/mongodb/README.md @@ -285,4 +285,30 @@ return [ ``` > Note: since MongoDB is schemaless, there is not much information, which generated code may base on. So generated code - is very basic and definitely requires adjustments. \ No newline at end of file + is very basic and definitely requires adjustments. + + +Using the MongoDB DebugPanel +---------------------------- + +The yii2 MongoDB extensions provides a debug panel that can be integrated with the yii debug module +and shows the executed MongoDB queries. + +Add the following to you application config to enable it (if you already have the debug module +enabled, it is sufficient to just add the panels configuration): + +```php + // ... + 'bootstrap' => ['debug'], + 'modules' => [ + 'debug' => [ + 'class' => 'yii\\debug\\Module', + 'panels' => [ + 'mongodb' => [ + 'class' => 'yii\\mongodb\\debug\\MongoDbPanel', + ], + ], + ], + ], + // ... +``` diff --git a/extensions/mongodb/debug/MongoDbPanel.php b/extensions/mongodb/debug/MongoDbPanel.php new file mode 100644 index 0000000000..a8e86f7663 --- /dev/null +++ b/extensions/mongodb/debug/MongoDbPanel.php @@ -0,0 +1,43 @@ + + * @since 2.0 + */ +class MongoDbPanel extends DbPanel +{ + /** + * @inheritdoc + */ + public function getName() + { + return 'MongoDB'; + } + + /** + * Returns all profile logs of the current request for this panel. + * @return array + */ + public function getProfileLogs() + { + $target = $this->module->logTarget; + + return $target->filterMessages($target->messages, Logger::LEVEL_PROFILE, [ + 'yii\mongodb\Collection::*', + 'yii\mongodb\Query::*', + 'yii\mongodb\Database::*', + ]); + } +} \ No newline at end of file From 950577d52b6a50c28e5d52e3aef33af20a2bf85f Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Thu, 11 Sep 2014 11:51:19 +0300 Subject: [PATCH 2/4] Dynamic naming added to `DbPanel` --- extensions/debug/panels/DbPanel.php | 8 ++++++++ extensions/debug/views/default/panels/db/detail.php | 2 +- extensions/debug/views/default/panels/db/summary.php | 2 +- extensions/mongodb/debug/MongoDbPanel.php | 8 ++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/extensions/debug/panels/DbPanel.php b/extensions/debug/panels/DbPanel.php index 37bde4ebbb..a654463680 100644 --- a/extensions/debug/panels/DbPanel.php +++ b/extensions/debug/panels/DbPanel.php @@ -47,6 +47,14 @@ class DbPanel extends Panel return 'Database'; } + /** + * @return string short name of the panel, which will be use in summary. + */ + public function getSummaryName() + { + return 'DB'; + } + /** * @inheritdoc */ diff --git a/extensions/debug/views/default/panels/db/detail.php b/extensions/debug/views/default/panels/db/detail.php index 4bd839f538..709291ec15 100644 --- a/extensions/debug/views/default/panels/db/detail.php +++ b/extensions/debug/views/default/panels/db/detail.php @@ -7,7 +7,7 @@ use yii\helpers\Html; use yii\grid\GridView; ?> -

Database Queries

+

getName(); ?> Queries

diff --git a/extensions/mongodb/debug/MongoDbPanel.php b/extensions/mongodb/debug/MongoDbPanel.php index a8e86f7663..35b5fd93ed 100644 --- a/extensions/mongodb/debug/MongoDbPanel.php +++ b/extensions/mongodb/debug/MongoDbPanel.php @@ -26,6 +26,14 @@ class MongoDbPanel extends DbPanel return 'MongoDB'; } + /** + * @inheritdoc + */ + public function getSummaryName() + { + return 'MongoDB'; + } + /** * Returns all profile logs of the current request for this panel. * @return array From 891cd78173841a46b426f82e4e1d917404da24b3 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Thu, 11 Sep 2014 11:53:54 +0300 Subject: [PATCH 3/4] `MongoDbPanel` addition mentioned at CHANGELOG.md and README.md --- extensions/mongodb/CHANGELOG.md | 1 + extensions/mongodb/README.md | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/extensions/mongodb/CHANGELOG.md b/extensions/mongodb/CHANGELOG.md index ee2ebe99c0..d85eeb5a94 100644 --- a/extensions/mongodb/CHANGELOG.md +++ b/extensions/mongodb/CHANGELOG.md @@ -9,6 +9,7 @@ Yii Framework 2 mongodb extension Change Log - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh #3778: Gii generator for Active Record model added (klimov-paul) - Enh #3947: Migration support added (klimov-paul) +- Enh #3855: Enh: Added a debug toolbar panel for MongoDB (klimov-paul) - Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue) - Enh #4086: changedAttributes of afterSave Event now contain old values (dizews) - Enh #4335: `yii\mongodb\log\MongoDbTarget` log target added (klimov-paul) diff --git a/extensions/mongodb/README.md b/extensions/mongodb/README.md index 4ee7a70510..19171b5fc5 100644 --- a/extensions/mongodb/README.md +++ b/extensions/mongodb/README.md @@ -288,6 +288,32 @@ return [ is very basic and definitely requires adjustments. +Using the MongoDB DebugPanel +---------------------------- + +The yii2 MongoDB extensions provides a debug panel that can be integrated with the yii debug module +and shows the executed MongoDB queries. + +Add the following to you application config to enable it (if you already have the debug module +enabled, it is sufficient to just add the panels configuration): + +```php + // ... + 'bootstrap' => ['debug'], + 'modules' => [ + 'debug' => [ + 'class' => 'yii\\debug\\Module', + 'panels' => [ + 'mongodb' => [ + 'class' => 'yii\\mongodb\\debug\\MongoDbPanel', + ], + ], + ], + ], + // ... +``` + + Using Migrations ---------------- From 4ce785ef76848ce0587765237e4f74ba72ebba7e Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Fri, 12 Sep 2014 10:40:32 +0300 Subject: [PATCH 4/4] `DbPanel` summary view fixed --- extensions/debug/views/default/panels/db/summary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/debug/views/default/panels/db/summary.php b/extensions/debug/views/default/panels/db/summary.php index f15ab94044..91b5ec71ec 100644 --- a/extensions/debug/views/default/panels/db/summary.php +++ b/extensions/debug/views/default/panels/db/summary.php @@ -6,7 +6,7 @@