Browse Source

[ProfilerBundle] fixed page display when the profiler DB is not writable

Fabien Potencier 15 years ago
parent
commit
9ebfdf24a5

+ 12 - 3
src/Symfony/Framework/ProfilerBundle/DataCollector/DataCollectorManager.php

@@ -6,6 +6,7 @@ use Symfony\Components\DependencyInjection\ContainerInterface;
 use Symfony\Components\EventDispatcher\Event;
 use Symfony\Components\RequestHandler\Response;
 use Symfony\Framework\ProfilerBundle\ProfilerStorage;
+use Symfony\Foundation\LoggerInterface;
 
 /*
  * This file is part of the Symfony framework.
@@ -31,7 +32,7 @@ class DataCollectorManager
   protected $response;
   protected $lifetime;
 
-  public function __construct(ContainerInterface $container, ProfilerStorage $profilerStorage, $lifetime = 86400)
+  public function __construct(ContainerInterface $container, LoggerInterface $logger, ProfilerStorage $profilerStorage, $lifetime = 86400)
   {
     $this->container = $container;
     $this->lifetime = $lifetime;
@@ -58,8 +59,16 @@ class DataCollectorManager
     {
       $data[$name] = $collector->getData();
     }
-    $this->profilerStorage->write($data);
-    $this->profilerStorage->purge($this->lifetime);
+
+    try
+    {
+      $this->profilerStorage->write($data);
+      $this->profilerStorage->purge($this->lifetime);
+    }
+    catch (\Exception $e)
+    {
+      $this->logger->err('Unable to store the profiler information.');
+    }
 
     return $response;
   }

+ 1 - 0
src/Symfony/Framework/ProfilerBundle/Resources/config/collectors.xml

@@ -19,6 +19,7 @@
     <service id="data_collector_manager" class="%data_collector_manager.class%">
       <annotation name="kernel.listener" event="core.response" method="handle" />
       <argument type="service" id="service_container" />
+      <argument type="service" id="logger" />
       <argument type="service" id="data_collector_manager.storage" />
       <argument>%data_collector_manager.lifetime%</argument>
     </service>