From cdabbc6648c505fa649bc6b88e2ec63176196790 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 17 Dec 2014 13:11:11 -0500 Subject: [PATCH] SAAS-527: Allow files to be uploaded to either the cloud or on local file storage Done. --- .../rest/controllers/MediaController.php | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index f19700ff1..492d7140a 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -215,6 +215,42 @@ class Rest_MediaController extends Zend_Rest_Controller $file->setDbMtime($now); $file->save(); + $this->getResponse() + ->setHttpResponseCode(200) + ->appendBody(json_encode(CcFiles::sanitizeResponse($file))); + } else if ($file) { + //local file storage + $file->setDbDirectory(self::MUSIC_DIRS_STOR_PK); + $file->fromArray($whiteList, BasePeer::TYPE_FIELDNAME); + //Our RESTful API takes "full_path" as a field, which we then split and translate to match + //our internal schema. Internally, file path is stored relative to a directory, with the directory + //as a foreign key to cc_music_dirs. + if (isset($requestData["full_path"])) { + $fileSizeBytes = filesize($requestData["full_path"]); + if (!isset($fileSizeBytes) || $fileSizeBytes === false) + { + $file->setDbImportStatus(self::IMPORT_STATUS_FAILED)->save(); + $this->fileNotFoundResponse(); + return; + } + Application_Model_Preference::updateDiskUsage($fileSizeBytes); + $fullPath = $requestData["full_path"]; + $storDir = Application_Model_MusicDir::getStorDir()->getDirectory(); + $pos = strpos($fullPath, $storDir); + + if ($pos !== FALSE) + { + assert($pos == 0); //Path must start with the stor directory path + + $filePathRelativeToStor = substr($fullPath, strlen($storDir)); + $file->setDbFilepath($filePathRelativeToStor); + } + } + + $now = new DateTime("now", new DateTimeZone("UTC")); + $file->setDbMtime($now); + $file->save(); + $this->getResponse() ->setHttpResponseCode(200) ->appendBody(json_encode(CcFiles::sanitizeResponse($file))); @@ -430,8 +466,6 @@ class Rest_MediaController extends Zend_Rest_Controller return; } - - Logging::info($importedStorageDirectory); //Dispatch a message to airtime_analyzer through RabbitMQ, //notifying it that there's a new upload to process! Application_Model_RabbitMq::SendMessageToAnalyzer($newTempFilePath,