CC-5888: Handle file deletion if the file is stored in the cloud

This commit is contained in:
drigato 2014-07-15 07:26:39 -04:00
parent 9d0f564190
commit 8e714bcb64
5 changed files with 25 additions and 14 deletions

View File

@ -80,9 +80,10 @@ class Application_Model_RabbitMq
} }
public static function SendMessageToAnalyzer($tmpFilePath, $importedStorageDirectory, $originalFilename, public static function SendMessageToAnalyzer($tmpFilePath, $importedStorageDirectory, $originalFilename,
$callbackUrl, $apiKey) $callbackUrl, $apiKey, $messageType)
{ {
$exchange = 'airtime-uploads'; $exchange = 'airtime-uploads';
$data['message_type'] = $messageType;
$data['tmp_file_path'] = $tmpFilePath; $data['tmp_file_path'] = $tmpFilePath;
$data['import_directory'] = $importedStorageDirectory; $data['import_directory'] = $importedStorageDirectory;
$data['original_filename'] = $originalFilename; $data['original_filename'] = $originalFilename;

View File

@ -384,28 +384,28 @@ SQL;
throw new FileNoPermissionException(); throw new FileNoPermissionException();
} }
$music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory()); $isInCloud = $this->isInCloud();
assert($music_dir);
$type = $music_dir->getType();
$filesize = $this->getFileSize();
if (file_exists($filepath) && $type == "stor") { if (file_exists($filepath) && !$isInCloud) {
try { try {
//Update the user's disk usage
Application_Model_Preference::updateDiskUsage(-1 * abs(filesize($filepath)));
unlink($filepath); unlink($filepath);
} catch (Exception $e) { } catch (Exception $e) {
Logging::error($e->getMessage()); Logging::error($e->getMessage());
return; 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()); Logging::info("User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$this->_file->getDbId());
// set hidden flag to true // set hidden flag to true
//$this->_file->setDbHidden(true); //$this->_file->setDbHidden(true);
$this->_file->setDbFileExists(false); //$this->_file->setDbFileExists(false);
$this->_file->save(); //$this->_file->save();
// need to explicitly update any playlist's and block's length // need to explicitly update any playlist's and block's length
// that contains the file getting deleted // that contains the file getting deleted
@ -423,6 +423,8 @@ SQL;
$bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME))); $bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME)));
$bl->save(); $bl->save();
} }
$this->_file->delete();
} }
/** /**

View File

@ -307,7 +307,6 @@ class Rest_MediaController extends Zend_Rest_Controller
if ($storedFile->existsOnDisk()) { if ($storedFile->existsOnDisk()) {
$storedFile->delete(); //TODO: This checks your session permissions... Make it work without a session? $storedFile->delete(); //TODO: This checks your session permissions... Make it work without a session?
} }
$file->delete();
$this->getResponse() $this->getResponse()
->setHttpResponseCode(204); ->setHttpResponseCode(204);
} else { } else {

View File

@ -41,3 +41,6 @@ class CloudStorageUploader:
metadata["s3_object_name"] = object_name metadata["s3_object_name"] = object_name
return metadata return metadata
def delete_obj(self, object_name):
pass

View File

@ -8,6 +8,7 @@ import logging
import multiprocessing import multiprocessing
from analyzer_pipeline import AnalyzerPipeline from analyzer_pipeline import AnalyzerPipeline
from status_reporter import StatusReporter from status_reporter import StatusReporter
from cloud_storage_uploader import CloudStorageUploader
EXCHANGE = "airtime-uploads" EXCHANGE = "airtime-uploads"
EXCHANGE_TYPE = "topic" EXCHANGE_TYPE = "topic"
@ -151,6 +152,7 @@ class MessageListener:
original_filename = "" original_filename = ""
callback_url = "" callback_url = ""
api_key = "" api_key = ""
message_type = ""
''' Spin up a worker process. We use the multiprocessing module and multiprocessing.Queue ''' 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 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"] original_filename = msg_dict["original_filename"]
callback_url = msg_dict["callback_url"] callback_url = msg_dict["callback_url"]
api_key = msg_dict["api_key"] 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) if event_type == "upload":
StatusReporter.report_success_to_callback_url(callback_url, api_key, audio_metadata) 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: except KeyError as e:
# A field in msg_dict that we needed was missing (eg. audio_file_path) # A field in msg_dict that we needed was missing (eg. audio_file_path)