diff --git a/Controller/PanelController.php b/Controller/PanelController.php
index cd04c47..4a84943 100644
--- a/Controller/PanelController.php
+++ b/Controller/PanelController.php
@@ -12,6 +12,7 @@ namespace Propel\PropelBundle\Controller;
use Symfony\Bridge\Propel1\DataCollector\PropelDataCollector;
use Symfony\Component\DependencyInjection\ContainerAware;
+use Symfony\Component\HttpFoundation\Response;
/**
* PanelController is designed to display information in the Propel Panel.
@@ -39,4 +40,44 @@ class PanelController extends ContainerAware
);
}
+ /**
+ * Renders the profiler panel for the given token.
+ *
+ * @param string $token The profiler token
+ * @param string $connection The connection name
+ * @param integer $query
+ *
+ * @return Symfony\Component\HttpFoundation\Response A Response instance
+ */
+ public function explainAction($token, $connection, $query)
+ {
+ $profiler = $this->container->get('profiler');
+ $profiler->disable();
+
+ $profile = $profiler->loadProfile($token);
+ $queries = $profile->getCollector('propel')->getQueries();
+
+ if (!isset($queries[$query])) {
+ return new Response('This query does not exist.');
+ }
+
+ // Open the connection
+ $con = \Propel::getConnection($connection);
+
+ // Get the adapter
+ $db = \Propel::getDB($connection);
+
+ try {
+ $stmt = $db->doExplainPlan($con, $queries[$query]['sql']);
+ $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
+ } catch (\Exception $e) {
+ return new Response('
This query cannot be explained.
');
+ }
+
+ return $this->container->get('templating')->renderResponse('PropelBundle:Panel:explain.html.twig', array(
+ 'data' => $results,
+ 'query' => $query,
+ ));
+
+ }
}
diff --git a/PropelBundle.php b/PropelBundle.php
index ae8e18f..ece6e7a 100644
--- a/PropelBundle.php
+++ b/PropelBundle.php
@@ -51,6 +51,7 @@ class PropelBundle extends Bundle
$config->setParameter('debugpdo.logging.details', array(
'time' => array('enabled' => true),
'mem' => array('enabled' => true),
+ 'connection' => array('enabled' => true),
));
\Propel::setLogger($this->container->get('propel.logger'));
diff --git a/Resources/views/Collector/propel.html.twig b/Resources/views/Collector/propel.html.twig
index 0189d76..c22091c 100644
--- a/Resources/views/Collector/propel.html.twig
+++ b/Resources/views/Collector/propel.html.twig
@@ -42,6 +42,23 @@
font-size: 0.9em;
margin: 3px 0;
}
+
+ .SQLExplain {
+ margin: 5px;
+ }
+
+ .SQLExplain .error {
+ background-color: #F2DEDE;
+ border-color: #EED3D7;
+ color: #B94A48;
+ padding: 8px 35px 8px 14px;
+ font-weight: bold;
+ }
+
+ #content .SQLExplain h2 {
+ font-size: 17px;
+ margin-bottom: 0;
+ }
Queries
@@ -55,11 +72,28 @@
{% if not collector.querycount %}
No queries. |
{% else %}
- {% for query in collector.queries %}
+ {% for i, query in collector.queries %}
+
{{ query.sql|format_sql }}
- Time: {{ query.time }} - Memory: {{ query.memory }}
+ {% if app.request.query.has('query') and app.request.query.get('query') == i %}
+
+ {% render 'PropelBundle:Panel:explain' with {
+ 'token': token,
+ 'panel': 'propel',
+ 'query': app.request.query.get('query'),
+ 'connection': app.request.query.get('connection')
+ } %}
+
+ {% endif %}
+
+ Time: {{ query.time }} - Memory: {{ query.memory }} - Connection: {{ query.connection }}
+
+ {% if app.request.query.get('query', -1) != i %}
+ - Explain the query
+ {% endif %}
+
|
{% endfor %}
diff --git a/Resources/views/Panel/explain.html.twig b/Resources/views/Panel/explain.html.twig
new file mode 100644
index 0000000..0c132d7
--- /dev/null
+++ b/Resources/views/Panel/explain.html.twig
@@ -0,0 +1,16 @@
+Explanation
+
+
+
+ {% for label in data[0]|keys %}
+ {{ label }} |
+ {% endfor %}
+
+ {% for row in data %}
+
+ {% for item in row %}
+ {{ item }} |
+ {% endfor %}
+
+ {% endfor %}
+
\ No newline at end of file