automatically add file extension to new files when it has no extension
[phorkie.git] / src / phorkie / Repository / Post.php
index 828dbadb16e897c8c36833b4d9a82cd968cc7778..b9d9be5aa626e6af73ca4556e2debc6481f66196 100644 (file)
@@ -44,13 +44,20 @@ class Repository_Post
             }
 
             $bNew = false;
             }
 
             $bNew = false;
+            $bDelete = false;
             if (!isset($orignalName) || $orignalName == '') {
                 //new file
                 $bNew = true;
             if (!isset($orignalName) || $orignalName == '') {
                 //new file
                 $bNew = true;
+                if (strpos($name, '.') === false) {
+                    //automatically append file extension if none is there
+                    $name .= '.' . $arFile['type'];
+                }
             } else if (!$this->repo->hasFile($orignalName)) {
                 //unknown file
                 //FIXME: Show error message
                 continue;
             } else if (!$this->repo->hasFile($orignalName)) {
                 //unknown file
                 //FIXME: Show error message
                 continue;
+            } else if (isset($arFile['delete']) && $arFile['delete'] == 1) {
+                $bDelete = true;
             } else if ($orignalName != $name) {
                 //FIXME: what to do with overwrites?
                 $vc->getCommand('mv')
             } else if ($orignalName != $name) {
                 //FIXME: what to do with overwrites?
                 $vc->getCommand('mv')
@@ -61,7 +68,12 @@ class Repository_Post
             }
 
             $file = $this->repo->getFileByName($name, false);
             }
 
             $file = $this->repo->getFileByName($name, false);
-            if ($bNew || $file->getContent() != $arFile['content']) {
+            if ($bDelete) {
+                $command = $vc->getCommand('rm')
+                    ->addArgument($file->getFilename())
+                    ->execute();
+                $bChanged = true;
+            } else if ($bNew || $file->getContent() != $arFile['content']) {
                 file_put_contents($file->getPath(), $arFile['content']);
                 $command = $vc->getCommand('add')
                     ->addArgument($file->getFilename())
                 file_put_contents($file->getPath(), $arFile['content']);
                 $command = $vc->getCommand('add')
                     ->addArgument($file->getFilename())