Development

/branches/1.2/lib/plugins/sfPropelPlugin/lib/debug/sfWebDebugPanelPropel.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfPropelPlugin/lib/debug/sfWebDebugPanelPropel.class.php

Revision 17296, 2.7 kB (checked in by fabien, 5 years ago)

[1.2, 1.3] fixed Propel query log doesn't work properly on queries with over 9 bindings (closes #5882)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfWebDebugPanelPropel adds a panel to the web debug toolbar with Propel information.
13  *
14  * @package    symfony
15  * @subpackage debug
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfWebDebugPanelPropel extends sfWebDebugPanel
20 {
21   /**
22    * Constructor.
23    *
24    * @param sfWebDebug $webDebug The web debut toolbar instance
25    */
26   public function __construct(sfWebDebug $webDebug)
27   {
28     parent::__construct($webDebug);
29
30     $this->webDebug->getEventDispatcher()->connect('debug.web.filter_logs', array($this, 'filterLogs'));
31   }
32
33   public function getTitle()
34   {
35     if ($sqlLogs = $this->getSqlLogs())
36     {
37       return '<img src="'.$this->webDebug->getOption('image_root_path').'/database.png" alt="SQL queries" /> '.count($sqlLogs);
38     }
39   }
40
41   public function getPanelTitle()
42   {
43     return 'SQL queries';
44   }
45
46   public function getPanelContent()
47   {
48     $logs = array();
49     foreach ($this->getSqlLogs() as $log)
50     {
51       $logs[] = htmlspecialchars($log, ENT_QUOTES, sfConfig::get('sf_charset'));
52     }
53
54     return '
55       <div id="sfWebDebugDatabaseLogs">
56       <ol><li>'.implode("</li>\n<li>", $logs).'</li></ol>
57       </div>
58     ';
59   }
60
61   public function filterLogs(sfEvent $event, $logs)
62   {
63     $newLogs = array();
64     foreach ($logs as $log)
65     {
66       if ('sfPropelLogger' != $log['type'])
67       {
68         $newLogs[] = $log;
69       }
70     }
71
72     return $newLogs;
73   }
74
75   static public function listenToAddPanelEvent(sfEvent $event)
76   {
77     $event->getSubject()->setPanel('db', new self($event->getSubject()));
78   }
79
80   protected function getSqlLogs()
81   {
82     $logs = array();
83     $bindings = array();
84     $i = 0;
85     foreach ($this->webDebug->getLogger()->getLogs() as $log)
86     {
87       if ('sfPropelLogger' != $log['type'])
88       {
89         continue;
90       }
91
92       if (preg_match('/^(?:prepare|exec|query): (.*)$/s', $log['message'], $match))
93       {
94         $logs[$i++] = $match[1];
95         $bindings[$i - 1] = array();
96       }
97       else if (preg_match('/Binding (.*) at position (.+?) w\//', $log['message'], $match))
98       {
99         $bindings[$i - 1][$match[2]] = $match[1];
100       }
101     }
102
103     foreach ($logs as $i => $log)
104     {
105       if (count($bindings[$i]))
106       {
107         $bindings[$i] = array_reverse($bindings[$i]);
108         foreach ($bindings[$i] as $search => $replace)
109         {
110           $logs[$i] = str_replace($search, $replace, $logs[$i]);
111         }
112       }
113     }
114
115     return $logs;
116   }
117 }
118
Note: See TracBrowser for help on using the browser.