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

Execute a python script that deletes a file from the cloud
This commit is contained in:
drigato 2014-07-31 23:11:49 -04:00
parent 8c2754972e
commit dd37ffbdd7
7 changed files with 81 additions and 44 deletions

View file

@ -384,27 +384,26 @@ SQL;
$file_id = $this->_file->getDbId();
Logging::info("User ".$user->getLogin()." is deleting file: ".$this->_file->getDbTrackTitle()." - file id: ".$file_id);
$music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
if (!is_null($music_dir) && $music_dir->getType() == "stor" && file_exists($filepath)) {
try {
$filesize = $this->getFileSize();
//Update the user's disk usage
Application_Model_Preference::updateDiskUsage(-1 * $filesize);
//Explicitly update any playlist's and block's length that contain
//the file getting deleted
self::updateBlockAndPlaylistLength($this->_file->getDbId());
$this->_file->deletePhysicalFile();
//delete the file record from cc_files (and cloud_file, if applicable)
$this->_file->delete();
} catch (Exception $e) {
Logging::error($e->getMessage());
return;
}
}
//try {
//Delete the physical file from either the local stor directory
//or from the cloud
$this->_file->deletePhysicalFile();
$filesize = $this->getFileSize();
//Update the user's disk usage
Application_Model_Preference::updateDiskUsage(-1 * $filesize);
//Explicitly update any playlist's and block's length that contain
//the file getting deleted
self::updateBlockAndPlaylistLength($this->_file->getDbId());
//delete the file record from cc_files (and cloud_file, if applicable)
$this->_file->delete();
//} catch (Exception $e) {
//Logging::error($e->getMessage());
//return;
//}
}
/*
@ -611,7 +610,8 @@ SQL;
//Attempt to get the cloud file object and return it. If no cloud
//file object is found then we are dealing with a regular stored
//object so return that
$cloudFile = $storedFile->getCloudFiles()->getFirst();
$cloudFile = CloudFileQuery::create()->findOneByCcFileId($p_id);
if (is_null($cloudFile)) {
return self::createWithFile($storedFile, $con);
} else {

View file

@ -101,7 +101,12 @@ class CcFiles extends BaseCcFiles {
public function deletePhysicalFile()
{
unlink($this->getAbsoluteFilePath());
$filepath = $this->getAbsoluteFilePath();
if (file_exists($filepath)) {
unlink($filepath);
} else {
throw new Exception("Could not locate file ".$filepath);
}
}
} // CcFiles

View file

@ -53,18 +53,27 @@ class CloudFile extends BaseCloudFile
public function deletePhysicalFile()
{
//TODO: execute a python script that deletes the file from the cloud
$CC_CONFIG = Config::getConfig();
//$pathToScript = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."cloud_storage_deleter.py" : "/home/denise/airtime/cloud_storage_deleter.py";
//Dispatch a message to airtime_analyzer through RabbitMQ,
//notifying it that we need to delete a file from the cloud
/*$CC_CONFIG = Config::getConfig();
$apiKey = $CC_CONFIG["apiKey"][0];
//If the file was successfully deleted from the cloud the analyzer
//will make a request to the Media API to do the deletion cleanup.
$callbackUrl = 'http://'.$_SERVER['HTTP_HOST'].'/rest/media/'.$file_id.'/delete-success';
Application_Model_RabbitMq::SendDeleteMessageToAnalyzer(
$callbackUrl, $this->_file->getDbResourceId(), $apiKey, 'delete');*/
$provider = escapeshellarg($CC_CONFIG["cloud_storage"]["provider"]);
$bucket = escapeshellarg($CC_CONFIG["cloud_storage"]["bucket"]);
$apiKey = escapeshellarg($CC_CONFIG["cloud_storage"]["api_key"]);
$apiSecret = escapeshellarg($CC_CONFIG["cloud_storage"]["api_key_secret"]);
$objName = $this->getResourceId();
//we will pass the cloud storage bucket and api key info to the script
//instead of the script reading from a config file beacuse on saas we
//might store this info in the apache vhost
$command = '/usr/lib/airtime/pypo/bin/cloud_storage_deleter.py "'
.$provider.'" "'
.$bucket.'" "'
.$apiKey.'" "'
.$apiSecret.'" "'
.$this->getResourceId().'" 2>&1; echo $?';
$output = shell_exec($command);
if ($output != "0") {
Logging::info($output);
throw new Exception("Could not delete file from cloud storage");
}
}
}