show reason for mime type detection failure in setup check
[phorkie.git] / src / phorkie / Repository / Post.php
index e2e4e9197fd8c4c3b6b8bc95d49b5df3523a0854..09cb977e2ac4eed1e7bd6894c5fd44e0bace25dc 100644 (file)
@@ -116,6 +116,10 @@ class Repository_Post
                     && $file->getContent() != $arFile['content']
                 )
             ) {
+                $dir = dirname($file->getFullPath());
+                if (!is_dir($dir)) {
+                    mkdir($dir, 0777, true);
+                }
                 file_put_contents($file->getFullPath(), $arFile['content']);
                 $command = $vc->getCommand('add')
                     ->addArgument($file->getFilename())
@@ -147,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;
         }
 
@@ -154,8 +162,10 @@ class Repository_Post
             //FIXME: index changed files only
             //also handle file deletions
             $db = new Database();
+            $not = new Notificator();
             if ($bNew) {
                 $db->getIndexer()->addRepo($this->repo);
+                $not->create($this->repo);
             } else {
                 $commits = $this->repo->getHistory();
                 $db->getIndexer()->updateRepo(
@@ -163,6 +173,7 @@ class Repository_Post
                     $commits[count($commits)-1]->committerTime,
                     $commits[0]->committerTime
                 );
+                $not->edit($this->repo);
             }
         }
 
@@ -175,7 +186,15 @@ class Repository_Post
             if ($_FILES['files']['error'][$num]['upload'] == 0) {
                 return true;
             }
-            if ($arFile['content'] != '') {
+            if (isset($arFile['content']) && $arFile['content'] != '') {
+                return true;
+            }
+            if (isset($arFile['name']) && $arFile['name'] != '') {
+                //binary files do not have content
+                return true;
+            }
+            if (isset($arFile['delete']) && $arFile['delete'] != '') {
+                //binary files do not have content
                 return true;
             }
         }
@@ -213,13 +232,17 @@ class Repository_Post
         return $prefix . $num;
     }
 
-    protected function getType($content)
+    public function getType($content, $returnError = false)
     {
         $tmp = tempnam(sys_get_temp_dir(), 'phorkie-autodetect-');
         file_put_contents($tmp, $content);
-        $type = \MIME_Type_PlainDetect::autoDetect($tmp);
+        $type = Tool_MIME_Type_PlainDetect::autoDetect($tmp);
         unlink($tmp);
 
+        if ($returnError && $type instanceof \PEAR_Error) {
+            return $type;
+        }
+
         return $this->findExtForType($type);
     }