make mime type detection work on php-fpm which has no PATH env variable
[phorkie.git] / src / phorkie / Repository / Post.php
index fbfea4bcb74c3bbf081f16b5e054abcafa9455fd..a61f2a257e6f78709e49489bce9a1f4dfa063ba5 100644 (file)
@@ -151,6 +151,10 @@ class Repository_Post
                 ->setOption('force')
                 ->setOption('message', "$notes")
                 ->execute();
+            //update info for dumb git HTTP transport
+            //the post-update hook should do that IMO, but does not somehow
+            $vc->getCommand('update-server-info')->execute();
+
             $bChanged = true;
         }
 
@@ -228,13 +232,23 @@ class Repository_Post
         return $prefix . $num;
     }
 
-    public function getType($content)
+    public function getType($content, $returnError = false)
     {
+        if (getenv('PATH') == '') {
+            //php-fpm does not fill $PATH by default
+            // we have to work around that since System::which() uses it
+            putenv('PATH=/usr/local/bin:/usr/bin:/bin');
+        }
+
         $tmp = tempnam(sys_get_temp_dir(), 'phorkie-autodetect-');
         file_put_contents($tmp, $content);
         $type = Tool_MIME_Type_PlainDetect::autoDetect($tmp);
         unlink($tmp);
 
+        if ($returnError && $type instanceof \PEAR_Error) {
+            return $type;
+        }
+
         return $this->findExtForType($type);
     }