Improvements based on import test.
[rock.divinelegy.git] / Controllers / SimfileController.php
index 06fe869..b9ca15e 100644 (file)
@@ -2,12 +2,14 @@
 \r
 namespace Controllers;\r
 \r
+use Exception;\r
 use Controllers\IDivineController;\r
 use Services\Http\IHttpResponse;\r
 use Services\Uploads\IUploadManager;\r
 use Services\IUserSession;\r
 use Services\IZipParser;\r
 use Services\ISMOMatcher;\r
+use Services\IStatusReporter;\r
 use DataAccess\StepMania\ISimfileRepository;\r
 use DataAccess\StepMania\IPackRepository;\r
 use DataAccess\IFileRepository;\r
@@ -27,6 +29,8 @@ class SimfileController implements IDivineController
     private $_zipParser;\r
     private $_smoMatcher;\r
     private $_downloadRepository;\r
+    private $_statusReporter;\r
+    private $_userSession;\r
     \r
     public function __construct(\r
         IHttpResponse $response,\r
@@ -37,7 +41,8 @@ class SimfileController implements IDivineController
         IUserSession $userSession,\r
         IZipParser $zipParser,\r
         ISMOMatcher $smoMatcher,\r
-        IDownloadRepository $downloadRepository\r
+        IDownloadRepository $downloadRepository,\r
+        IStatusReporter $statusReporter\r
     ) {\r
         $this->_response = $response;\r
         $this->_uploadManager = $uploadManager;\r
@@ -47,6 +52,8 @@ class SimfileController implements IDivineController
         $this->_zipParser = $zipParser;\r
         $this->_smoMatcher = $smoMatcher;\r
         $this->_downloadRepository = $downloadRepository;\r
+        $this->_statusReporter = $statusReporter;\r
+        $this->_userSession = $userSession;\r
     }\r
     \r
     public function indexAction() {\r
@@ -147,7 +154,9 @@ class SimfileController implements IDivineController
     }\r
     \r
     public function uploadAction()\r
-    {                       \r
+    {\r
+        if(!$this->_userSession->getCurrentUser()) $this->_statusReporter->error('You must be authenticated to upload files');\r
+        \r
         //TODO: Put directory in config ?\r
         $files = $this->_uploadManager->setFilesDirectory('../files')\r
                                       ->setDestination('StepMania/')\r
@@ -157,7 +166,9 @@ class SimfileController implements IDivineController
         {\r
             $zipParser = $this->_zipParser;\r
             $zipParser->parse($file);\r
-                        \r
+                   \r
+            if(!$zipParser->simfiles()) $this->_statusReporter->error('That zip doesn\'t seem to have any simfiles in it.');\r
+            \r
             //save the actual zip in the db\r
             $this->findAndAddSmoMirror($file);\r
             $this->_fileRepository->save($file);  \r
@@ -181,6 +192,8 @@ class SimfileController implements IDivineController
                 $this->_simfileRepository->save($simfile);\r
             }\r
         }\r
+        \r
+        $this->_statusReporter->success('Uploaded succesfully');\r
     }\r
     \r
     private function getPackMirrorsArray(IPack $pack)\r