Author: rande
Date: 2010-05-04 01:01:16 +0200 (Tue, 04 May 2010)
New Revision: 29340

Modified:
   
plugins/sfSolrPlugin/branches/sf1.2/lib/task/sfLuceneUpdateModelSystemTask.class.php
Log:
[sfSolrPlugin] fix memory exception analysing with sf1.3 and later

Modified: 
plugins/sfSolrPlugin/branches/sf1.2/lib/task/sfLuceneUpdateModelSystemTask.class.php
===================================================================
--- 
plugins/sfSolrPlugin/branches/sf1.2/lib/task/sfLuceneUpdateModelSystemTask.class.php
        2010-05-03 20:00:08 UTC (rev 29339)
+++ 
plugins/sfSolrPlugin/branches/sf1.2/lib/task/sfLuceneUpdateModelSystemTask.class.php
        2010-05-03 23:01:16 UTC (rev 29340)
@@ -20,6 +20,9 @@
 
 class sfLuceneUpdateModelSystemTask extends sfLuceneBaseTask
 {
+  protected 
+    $memory_error = false;
+  
   protected function configure()
   {
     $this->addArguments(array(
@@ -140,7 +143,7 @@
       {
         if(method_exists($this->getFilesystem(), 'execute')) // sf1.3 or 
greater
         {
-          $this->getFilesystem()->execute($command);
+          $this->getFilesystem()->execute($command, array($this, 
'analyseLine'));
         }
         else
         {
@@ -151,20 +154,45 @@
 
         return 0;
       } 
-      catch(sfException $e)
+      catch(Exception $e)
       {
-        if(preg_match("/Allowed memory size of ([0-9]*) bytes/", 
$e->getMessage()))
+        // sfException raise with sf1.2
+        if($e instanceof sfException && 
$this->isMemoryException($e->getMessage()))
         {
+          $this->memory_error = true;
+        }
+        
+        // this value can be set by the analyseLine method
+        if($this->memory_error)
+        {
           $this->logSection('lucene', '  memory limit reach, starting new 
subprocess');
-
+          
+          $this->memory_error = false;
+          
           continue;
         }
-        else
-        {
-          throw $e;
-        }
+        
+        throw $e;
       }
 
     } while(1);
   }
+  
+  public function isMemoryException($line)
+  {
+    if(preg_match("/Allowed memory size of ([0-9]*) bytes/", $line))
+    {
+      $this->logSection('lucene', '  memory limit reach, starting new 
subprocess');
+
+      return true;
+    }
+
+    return false;
+  }
+  
+  public function analyseLine($line)
+  {
+    // the fatal error momory exception is always the last line ...
+    $this->memory_error = $this->isMemoryException($line);
+  }
 }
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to