CC-5888: Handle file deletion if the file is stored in the cloud
This commit is contained in:
parent
9d0f564190
commit
8e714bcb64
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -41,3 +41,6 @@ class CloudStorageUploader:
|
|||
|
||||
metadata["s3_object_name"] = object_name
|
||||
return metadata
|
||||
|
||||
def delete_obj(self, object_name):
|
||||
pass
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue