merged branch jfsimon/issue-7012 (PR #7297)
This PR was squashed before being merged into the 2.1 branch (closes #7297).
Commits
-------
ef53456
[DoctrineBridge] Avoids blob values to be logged by doctrine
Discussion
----------
[DoctrineBridge] Avoids blob values to be logged by doctrine
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #7012
---------------------------------------------------------------------------
by pborreli at 2013-03-07T17:07:23Z
what about clob ?
---------------------------------------------------------------------------
by jfsimon at 2013-03-07T17:10:45Z
@pborreli do you think clob values shouldn't be logged?
---------------------------------------------------------------------------
by pborreli at 2013-03-07T17:26:27Z
well they can have same size than blob
---------------------------------------------------------------------------
by beberlei at 2013-03-07T18:07:15Z
I agree, skipping clobs as well would be WIN :-)
---------------------------------------------------------------------------
by francisbesset at 2013-03-08T08:44:08Z
Where are the tests?
---------------------------------------------------------------------------
by beberlei at 2013-03-08T09:25:20Z
Ah yes, the DbalLogger has a testsuite, can you extend it to show this behavior works?
---------------------------------------------------------------------------
by jfsimon at 2013-03-08T10:28:53Z
@francisbesset @beberlei tests written.
---------------------------------------------------------------------------
by staabm at 2013-03-10T16:00:55Z
May I also ask for text/char fields with a certain amount of chars?
This commit is contained in:
commit
18cd187ae9
@ -22,6 +22,9 @@ use Doctrine\DBAL\Logging\SQLLogger;
|
||||
*/
|
||||
class DbalLogger implements SQLLogger
|
||||
{
|
||||
const MAX_STRING_LENGTH = 32;
|
||||
const BINARY_DATA_VALUE = '(binary value)';
|
||||
|
||||
protected $logger;
|
||||
protected $stopwatch;
|
||||
|
||||
@ -46,6 +49,26 @@ class DbalLogger implements SQLLogger
|
||||
$this->stopwatch->start('doctrine', 'doctrine');
|
||||
}
|
||||
|
||||
if (is_array($params)) {
|
||||
foreach ($params as $index => $param) {
|
||||
if (!is_string($params[$index])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// non utf-8 strings break json encoding
|
||||
if (null === preg_match('#[^\p{L}\p{N} ]#u', $params[$index])) {
|
||||
$params[$index] = self::BINARY_DATA_VALUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
// too long string must be shorten
|
||||
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
|
||||
$params[$index] = substr($params[$index], self::MAX_STRING_LENGTH - 6).' [...]';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->logger) {
|
||||
$this->log($sql, null === $params ? array() : $params);
|
||||
}
|
||||
|
@ -33,10 +33,15 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
|
||||
protected function getExtensions()
|
||||
{
|
||||
$manager = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
|
||||
|
||||
$manager->expects($this->any())
|
||||
->method('getManager')
|
||||
->will($this->returnValue($this->em));
|
||||
|
||||
$manager->expects($this->any())
|
||||
->method('getManagerForClass')
|
||||
->will($this->returnValue($this->em));
|
||||
|
||||
return array(
|
||||
new CoreExtension(),
|
||||
new DoctrineOrmExtension($manager)
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Bridge\Doctrine\Tests\Logger;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Logger\DbalLogger;
|
||||
|
||||
class DbalLoggerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
@ -59,12 +61,38 @@ class DbalLoggerTest extends \PHPUnit_Framework_TestCase
|
||||
$dbalLogger
|
||||
->expects($this->once())
|
||||
->method('log')
|
||||
->with('SQL', array('utf8' => 'foo', 'nonutf8' => "\x7F\xFF"))
|
||||
->with('SQL', array('utf8' => 'foo', 'nonutf8' => DbalLogger::BINARY_DATA_VALUE))
|
||||
;
|
||||
|
||||
$dbalLogger->startQuery('SQL', array(
|
||||
'utf8' => 'foo',
|
||||
'nonutf8' => "\x7F\xFF"
|
||||
'nonutf8' => "\x7F\xFF",
|
||||
));
|
||||
}
|
||||
|
||||
public function testLogLongString()
|
||||
{
|
||||
$logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
|
||||
|
||||
$dbalLogger = $this
|
||||
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
|
||||
->setConstructorArgs(array($logger, null))
|
||||
->setMethods(array('log'))
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$shortString = str_repeat('a', DbalLogger::MAX_STRING_LENGTH);
|
||||
$longString = str_repeat('a', DbalLogger::MAX_STRING_LENGTH + 1);
|
||||
|
||||
$dbalLogger
|
||||
->expects($this->once())
|
||||
->method('log')
|
||||
->with('SQL', array('short' => $shortString, 'long' => substr($longString, DbalLogger::MAX_STRING_LENGTH - 6).' [...]'))
|
||||
;
|
||||
|
||||
$dbalLogger->startQuery('SQL', array(
|
||||
'short' => $shortString,
|
||||
'long' => $longString,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user