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