CC-5888: Handle file deletion if the file is stored in the cloud
This commit is contained in:
parent
46228341b2
commit
879e776c8d
|
@ -387,9 +387,7 @@ SQL;
|
|||
//try {
|
||||
//Delete the physical file from either the local stor directory
|
||||
//or from the cloud
|
||||
$this->_file->deletePhysicalFile();
|
||||
|
||||
$filesize = $this->getFileSize();
|
||||
$filesize = $this->_file->deletePhysicalFile();
|
||||
|
||||
//Update the user's disk usage
|
||||
Application_Model_Preference::updateDiskUsage(-1 * $filesize);
|
||||
|
|
|
@ -99,6 +99,12 @@ class CcFiles extends BaseCcFiles {
|
|||
return is_file($this->getAbsoluteFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Deletes the file from the stor directory
|
||||
*
|
||||
* Returns the filesize of the deleted file
|
||||
*/
|
||||
public function deletePhysicalFile()
|
||||
{
|
||||
$filepath = $this->getAbsoluteFilePath();
|
||||
|
@ -107,6 +113,8 @@ class CcFiles extends BaseCcFiles {
|
|||
} else {
|
||||
throw new Exception("Could not locate file ".$filepath);
|
||||
}
|
||||
|
||||
return $this->getFileSize();
|
||||
}
|
||||
|
||||
} // CcFiles
|
||||
|
|
|
@ -51,6 +51,13 @@ class CloudFile extends BaseCloudFile
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Deletes the file from cloud storage by executing a python script
|
||||
* that uses Apache Libcloud to connect with the cloud storage service
|
||||
*
|
||||
* If the file was successfully deleted the filesize of that file is returned
|
||||
*/
|
||||
public function deletePhysicalFile()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
@ -60,20 +67,29 @@ class CloudFile extends BaseCloudFile
|
|||
$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 $?';
|
||||
$objName = escapeshellarg($this->getResourceId());
|
||||
|
||||
$command = "/usr/lib/airtime/pypo/bin/cloud_storage_deleter.py $provider $bucket $apiKey $apiSecret $objName 2>&1 echo $?";
|
||||
|
||||
$output = shell_exec($command);
|
||||
if ($output != "0") {
|
||||
if ($output != "") {
|
||||
if (stripos($output, 'filesize') === false) {
|
||||
Logging::info($output);
|
||||
throw new Exception("Could not delete file from cloud storage");
|
||||
}
|
||||
}
|
||||
|
||||
$outputArr = json_decode($output, true);
|
||||
return $outputArr["filesize"];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Deletes the cloud_file's 'parent' object before itself
|
||||
*/
|
||||
public function delete(PropelPDO $con = NULL)
|
||||
{
|
||||
CcFilesQuery::create()->findPk($this->getCcFileId())->delete();
|
||||
parent::delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import simplejson
|
||||
|
||||
from libcloud.storage.providers import get_driver
|
||||
from libcloud.storage.types import Provider, ContainerDoesNotExistError, ObjectDoesNotExistError
|
||||
from libcloud.storage.types import Provider, ObjectDoesNotExistError
|
||||
|
||||
provider = str(sys.argv[0])
|
||||
bucket = str(sys.argv[1])
|
||||
api_key = str(sys.argv[2])
|
||||
api_key_secret = str(sys.argv[3])
|
||||
obj_name = str(sys.argv[4])
|
||||
provider = str(sys.argv[1])
|
||||
bucket = str(sys.argv[2])
|
||||
api_key = str(sys.argv[3])
|
||||
api_key_secret = str(sys.argv[4])
|
||||
obj_name = str(sys.argv[5])
|
||||
|
||||
cls = get_driver(getattr(Provider, provider))
|
||||
driver = cls(api_key, api_key_secret)
|
||||
|
@ -19,6 +20,9 @@ try:
|
|||
object_name=obj_name)
|
||||
filesize = getattr(cloud_obj, 'size')
|
||||
driver.delete_object(obj=cloud_obj)
|
||||
except ObjectDoesNotExistError:
|
||||
raise Exception("Could not find object on %s" % provider)
|
||||
|
||||
data = simplejson.dumps({"filesize": filesize})
|
||||
print data
|
||||
except ObjectDoesNotExistError:
|
||||
raise Exception("Could not find object on %s in bucket: %s and object: %s" % (provider, bucket, obj_name))
|
||||
|
||||
|
|
Loading…
Reference in New Issue