| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class sfWebDebugPanelPropel extends sfWebDebugPanel |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
* Get the title/icon for the panel |
|---|
| 25 |
* |
|---|
| 26 |
* @return string $html |
|---|
| 27 |
*/ |
|---|
| 28 |
public function getTitle() |
|---|
| 29 |
{ |
|---|
| 30 |
if ($sqlLogs = $this->getSqlLogs()) |
|---|
| 31 |
{ |
|---|
| 32 |
return '<img src="'.$this->webDebug->getOption('image_root_path').'/database.png" alt="SQL queries" /> '.count($sqlLogs); |
|---|
| 33 |
} |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
* Get the verbal title of the panel |
|---|
| 38 |
* |
|---|
| 39 |
* @return string $title |
|---|
| 40 |
*/ |
|---|
| 41 |
public function getPanelTitle() |
|---|
| 42 |
{ |
|---|
| 43 |
return 'SQL queries'; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
* Get the html content of the panel |
|---|
| 48 |
* |
|---|
| 49 |
* @return string $html |
|---|
| 50 |
*/ |
|---|
| 51 |
public function getPanelContent() |
|---|
| 52 |
{ |
|---|
| 53 |
return ' |
|---|
| 54 |
<div id="sfWebDebugDatabaseLogs"> |
|---|
| 55 |
<h3>Propel Version: '.Propel::VERSION.'</h3> |
|---|
| 56 |
<ol>'.implode("\n", $this->getSqlLogs()).'</ol> |
|---|
| 57 |
</div> |
|---|
| 58 |
'; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
* Listens to debug.web.load_panels and adds this panel. |
|---|
| 63 |
*/ |
|---|
| 64 |
static public function listenToAddPanelEvent(sfEvent $event) |
|---|
| 65 |
{ |
|---|
| 66 |
$event->getSubject()->setPanel('db', new self($event->getSubject())); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
* Builds the sql logs and returns them as an array. |
|---|
| 71 |
* |
|---|
| 72 |
* @return array |
|---|
| 73 |
*/ |
|---|
| 74 |
protected function getSqlLogs() |
|---|
| 75 |
{ |
|---|
| 76 |
$config = $this->getPropelConfiguration(); |
|---|
| 77 |
$outerGlue = $config->getParameter('debugpdo.logging.outerglue', ' | '); |
|---|
| 78 |
$innerGlue = $config->getParameter('debugpdo.logging.innerglue', ': '); |
|---|
| 79 |
$flagSlow = $config->getParameter('debugpdo.logging.details.slow.enabled', false); |
|---|
| 80 |
$threshold = $config->getParameter('debugpdo.logging.details.slow.threshold', DebugPDO::DEFAULT_SLOW_THRESHOLD); |
|---|
| 81 |
|
|---|
| 82 |
$html = array(); |
|---|
| 83 |
foreach ($this->webDebug->getLogger()->getLogs() as $log) |
|---|
| 84 |
{ |
|---|
| 85 |
if ('sfPropelLogger' != $log['type']) |
|---|
| 86 |
{ |
|---|
| 87 |
continue; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
$details = array(); |
|---|
| 91 |
$slowQuery = false; |
|---|
| 92 |
|
|---|
| 93 |
$parts = explode($outerGlue, $log['message']); |
|---|
| 94 |
foreach ($parts as $i => $part) |
|---|
| 95 |
{ |
|---|
| 96 |
|
|---|
| 97 |
if (preg_match('/^(\w+)'.preg_quote($innerGlue, '/').'(.*)/', $part, $match)) |
|---|
| 98 |
{ |
|---|
| 99 |
$details[] = $part; |
|---|
| 100 |
unset($parts[$i]); |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
if ('time' == $match[1]) |
|---|
| 104 |
{ |
|---|
| 105 |
if ($flagSlow && (float) $match[2] > $threshold) |
|---|
| 106 |
{ |
|---|
| 107 |
$slowQuery = true; |
|---|
| 108 |
if ($this->getStatus() > sfLogger::NOTICE) |
|---|
| 109 |
{ |
|---|
| 110 |
$this->setStatus(sfLogger::NOTICE); |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
$query = join($outerGlue, $parts); |
|---|
| 118 |
|
|---|
| 119 |
$query = $this->formatSql(htmlspecialchars($query, ENT_QUOTES, sfConfig::get('sf_charset'))); |
|---|
| 120 |
$backtrace = isset($log['debug_backtrace']) && count($log['debug_backtrace']) ? ' '.$this->getToggleableDebugStack($log['debug_backtrace']) : ''; |
|---|
| 121 |
|
|---|
| 122 |
$html[] = sprintf(' |
|---|
| 123 |
<li%s> |
|---|
| 124 |
<p class="sfWebDebugDatabaseQuery">%s</p> |
|---|
| 125 |
<div class="sfWebDebugDatabaseLogInfo">%s%s</div> |
|---|
| 126 |
</li>', |
|---|
| 127 |
$slowQuery ? ' class="sfWebDebugWarning"' : '', |
|---|
| 128 |
$query, |
|---|
| 129 |
implode(', ', $details), |
|---|
| 130 |
$backtrace |
|---|
| 131 |
); |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
return $html; |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
* Returns the current PropelConfiguration. |
|---|
| 139 |
* |
|---|
| 140 |
* @return PropelConfiguration |
|---|
| 141 |
*/ |
|---|
| 142 |
protected function getPropelConfiguration() |
|---|
| 143 |
{ |
|---|
| 144 |
return Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); |
|---|
| 145 |
} |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|