diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index 7af846127..bbabb6440 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -80,9 +80,10 @@ class Application_Model_RabbitMq } public static function SendMessageToAnalyzer($tmpFilePath, $importedStorageDirectory, $originalFilename, - $callbackUrl, $apiKey) + $callbackUrl, $apiKey, $messageType) { $exchange = 'airtime-uploads'; + $data['message_type'] = $messageType; $data['tmp_file_path'] = $tmpFilePath; $data['import_directory'] = $importedStorageDirectory; $data['original_filename'] = $originalFilename; diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index bb2d040a3..76415e1da 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -384,28 +384,28 @@ SQL; throw new FileNoPermissionException(); } - $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory()); - assert($music_dir); - $type = $music_dir->getType(); + $isInCloud = $this->isInCloud(); - - if (file_exists($filepath) && $type == "stor") { + $filesize = $this->getFileSize(); + if (file_exists($filepath) && !$isInCloud) { try { - //Update the user's disk usage - Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($filepath))); - unlink($filepath); } catch (Exception $e) { Logging::error($e->getMessage()); return; } + } elseif ($isInCloud) { + //delete file from cloud } + //Update the user's disk usage + Application_Model_Preference::updateDiskUsage(-1 * $filesize); + Logging::info("User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$this->_file->getDbId()); // set hidden flag to true //$this->_file->setDbHidden(true); - $this->_file->setDbFileExists(false); - $this->_file->save(); + //$this->_file->setDbFileExists(false); + //$this->_file->save(); // need to explicitly update any playlist's and block's length // that contains the file getting deleted @@ -423,6 +423,8 @@ SQL; $bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME))); $bl->save(); } + + $this->_file->delete(); } /** diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index fb77c91c7..16e084e80 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -307,7 +307,6 @@ class Rest_MediaController extends Zend_Rest_Controller if ($storedFile->existsOnDisk()) { $storedFile->delete(); //TODO: This checks your session permissions... Make it work without a session? } - $file->delete(); $this->getResponse() ->setHttpResponseCode(204); } else { diff --git a/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py b/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py index 4fa2da0b7..3cd7793df 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/cloud_storage_uploader.py @@ -41,3 +41,6 @@ class CloudStorageUploader: metadata["s3_object_name"] = object_name return metadata + + def delete_obj(self, object_name): + pass \ No newline at end of file diff --git a/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py b/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py index e723542d7..45db99150 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/message_listener.py @@ -8,6 +8,7 @@ import logging import multiprocessing from analyzer_pipeline import AnalyzerPipeline from status_reporter import StatusReporter +from cloud_storage_uploader import CloudStorageUploader EXCHANGE = "airtime-uploads" EXCHANGE_TYPE = "topic" @@ -151,6 +152,7 @@ class MessageListener: original_filename = "" callback_url = "" api_key = "" + message_type = "" ''' Spin up a worker process. We use the multiprocessing module and multiprocessing.Queue to pass objects between the processes so that if the analyzer process crashes, it does not @@ -166,9 +168,13 @@ class MessageListener: original_filename = msg_dict["original_filename"] callback_url = msg_dict["callback_url"] api_key = msg_dict["api_key"] + message_type = msg_dict["message_type"] - audio_metadata = self.spawn_analyzer_process(audio_file_path, import_directory, original_filename) - StatusReporter.report_success_to_callback_url(callback_url, api_key, audio_metadata) + if event_type == "upload": + audio_metadata = self.spawn_analyzer_process(audio_file_path, import_directory, original_filename) + StatusReporter.report_success_to_callback_url(callback_url, api_key, audio_metadata) + elif event_type == "delete": + pass except KeyError as e: # A field in msg_dict that we needed was missing (eg. audio_file_path)