diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index b4f6bffa6..a45e63e99 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -387,10 +387,8 @@ SQL; //try { //Delete the physical file from either the local stor directory //or from the cloud - $this->_file->deletePhysicalFile(); + $filesize = $this->_file->deletePhysicalFile(); - $filesize = $this->getFileSize(); - //Update the user's disk usage Application_Model_Preference::updateDiskUsage(-1 * $filesize); diff --git a/airtime_mvc/application/models/airtime/CcFiles.php b/airtime_mvc/application/models/airtime/CcFiles.php index 2790de707..e1d770bad 100644 --- a/airtime_mvc/application/models/airtime/CcFiles.php +++ b/airtime_mvc/application/models/airtime/CcFiles.php @@ -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 diff --git a/airtime_mvc/application/models/airtime/CloudFile.php b/airtime_mvc/application/models/airtime/CloudFile.php index eab64c1ce..d64d8f6e0 100644 --- a/airtime_mvc/application/models/airtime/CloudFile.php +++ b/airtime_mvc/application/models/airtime/CloudFile.php @@ -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") { - Logging::info($output); - throw new Exception("Could not delete file from cloud storage"); + 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(); } } diff --git a/python_apps/pypo/cloud_storage_deleter.py b/python_apps/pypo/cloud_storage_deleter.py index 6b6aef818..93bccd76f 100755 --- a/python_apps/pypo/cloud_storage_deleter.py +++ b/python_apps/pypo/cloud_storage_deleter.py @@ -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) + + data = simplejson.dumps({"filesize": filesize}) + print data 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))