show reason for mime type detection failure in setup check
authorChristian Weiske <cweiske@cweiske.de>
Wed, 9 Jul 2014 16:21:08 +0000 (18:21 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 9 Jul 2014 16:21:08 +0000 (18:21 +0200)
src/phorkie/Repository/Post.php
src/phorkie/SetupCheck.php

index 5a450b1aa0b446f63c82de95ae568fd09864583d..09cb977e2ac4eed1e7bd6894c5fd44e0bace25dc 100644 (file)
@@ -232,13 +232,17 @@ class Repository_Post
         return $prefix . $num;
     }
 
-    public function getType($content)
+    public function getType($content, $returnError = false)
     {
         $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);
     }
 
index c4d365c7a79552166aea7e88413f44ef0087f821..e06f28cc62342bbdce019bb5e47c784c622a9f48 100644 (file)
@@ -133,8 +133,13 @@ class SetupCheck
     public function checkMimeTypeDetection()
     {
         $rp = new Repository_Post();
-        if ($rp->getType('<?php echo "foo"; ?>') != 'php') {
-            $this->fail('MIME type detection fails');
+        $type = $rp->getType('<?php echo "foo"; ?>', true);
+        if ($type != 'php') {
+            $msg = 'MIME type detection fails';
+            if ($type instanceof \PEAR_Error) {
+                $msg .= '. Error: ' . $type->getMessage();
+            }
+            $this->fail($msg);
         }
     }