[HttpKernel] Fix #4719. Added condition which verify existence of profiler dump file. If file does not exists script inserts record to csv file.
This commit is contained in:
parent
b8f99ee19e
commit
74aa5021df
@ -129,11 +129,14 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
{
|
||||
$file = $this->getFilename($profile->getToken());
|
||||
|
||||
$profileIndexed = is_file($file);
|
||||
if (!$profileIndexed) {
|
||||
// Create directory
|
||||
$dir = dirname($file);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Store profile
|
||||
$data = array(
|
||||
@ -151,6 +154,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$profileIndexed) {
|
||||
// Add to index
|
||||
if (false === $file = fopen($this->getIndexFilename(), 'a')) {
|
||||
return false;
|
||||
@ -165,6 +169,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
$profile->getParentToken(),
|
||||
));
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\HttpKernel\Tests\Profiler;
|
||||
|
||||
use Symfony\Component\HttpKernel\Profiler\FileProfilerStorage;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profile;
|
||||
|
||||
class FileProfilerStorageTest extends AbstractProfilerStorageTest
|
||||
{
|
||||
@ -57,4 +58,28 @@ class FileProfilerStorageTest extends AbstractProfilerStorageTest
|
||||
{
|
||||
return self::$storage;
|
||||
}
|
||||
|
||||
public function testMultiRowIndexFile()
|
||||
{
|
||||
$iteration = 3;
|
||||
for($i = 0; $i < $iteration; $i++) {
|
||||
$profile = new Profile('token' . $i);
|
||||
$profile->setIp('127.0.0.' . $i);
|
||||
$profile->setUrl('http://foo.bar/' . $i);
|
||||
$storage = $this->getStorage();
|
||||
|
||||
$storage->write($profile);
|
||||
$storage->write($profile);
|
||||
$storage->write($profile);
|
||||
}
|
||||
|
||||
$handle = fopen(self::$tmpDir . '/index.csv', 'r');
|
||||
for($i = 0; $i < $iteration; $i++) {
|
||||
$row = fgetcsv($handle);
|
||||
$this->assertEquals('token' . $i, $row[0]);
|
||||
$this->assertEquals('127.0.0.' . $i, $row[1]);
|
||||
$this->assertEquals('http://foo.bar/' . $i, $row[3]);
|
||||
}
|
||||
$this->assertFalse(fgetcsv($handle));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user