diff --git a/airtime_mvc/application/cloud_storage/Amazon_S3.php b/airtime_mvc/application/cloud_storage/Amazon_S3.php index f66dd7f65..9f0b7570f 100644 --- a/airtime_mvc/application/cloud_storage/Amazon_S3.php +++ b/airtime_mvc/application/cloud_storage/Amazon_S3.php @@ -59,46 +59,19 @@ class Amazon_S3 extends StorageBackend } } - public function deleteObjects() + public function deleteAllCloudFileObjects() { - $cloudFilePager = CloudFileQuery::create() - ->filterByStorageBackend("amazon_S3") - ->paginate($page=1, $maxPerPage=1000); - - if ($cloudFilePager->haveToPaginate()) { - $numPages = $cloudFilePager->getLastPage(); - $currentPage = 1; - while ($currentPage <= $numPages) { - $cloudFilePager = CloudFileQuery::create() - ->filterByStorageBackend("amazon_S3") - ->paginate($page = $currentPage, $maxPerPage = 1000); + $this->s3Client->deleteMatchingObjects( + $bucket = $this->getBucket(), + $prefix = Application_Model_Preference::GetStationName()); - $this->deleteObjectSet($cloudFilePager->getResults()); - - $currentPage += 1; - } - } else { - $this->deleteObjectSet($cloudFilePager->getResults()); - } - } - - /** - * Deletes objects from Amazon S3 1000 at a time. - * 1000 is the max number of objects that can be deleted using the aws sdk - * api, per request. - */ - private function deleteObjectSet($cloudFiles) - { - if (!$cloudFiles->isEmpty()) { - $cloudFilesToDelete = array(); - - foreach ($cloudFiles as $cloudFile) { - array_push($cloudFilesToDelete, array("Key" => $cloudFile->getResourceId())); - } - - $this->s3Client->deleteObjects(array( - "Bucket" => $this->getBucket(), - "Objects" => $cloudFilesToDelete)); + // delete record of the cloud files from the database + $criteria = new Criteria(); + $criteria->clearSelectColumns(); + $criteria->addSelectColumn(CloudFilePeer::CC_FILE_ID); + $results = CloudFilePeer::doSelectStmt($criteria)->fetchAll(); + foreach ($results as $key => $value) { + CcFilesQuery::create()->findPk($value["cc_file_id"])->delete(); } } } diff --git a/airtime_mvc/application/cloud_storage/ProxyStorageBackend.php b/airtime_mvc/application/cloud_storage/ProxyStorageBackend.php index 171bbe64c..6b7cadd13 100644 --- a/airtime_mvc/application/cloud_storage/ProxyStorageBackend.php +++ b/airtime_mvc/application/cloud_storage/ProxyStorageBackend.php @@ -43,9 +43,9 @@ class ProxyStorageBackend extends StorageBackend $this->storageBackend->deletePhysicalFile($resourceId); } - public function deleteObjects() + public function deleteAllCloudFileObjects() { - $this->storageBackend->deleteObjects(); + $this->storageBackend->deleteAllCloudFileObjects(); } } diff --git a/airtime_mvc/application/cloud_storage/StorageBackend.php b/airtime_mvc/application/cloud_storage/StorageBackend.php index e078e9abf..463d99071 100644 --- a/airtime_mvc/application/cloud_storage/StorageBackend.php +++ b/airtime_mvc/application/cloud_storage/StorageBackend.php @@ -23,8 +23,9 @@ abstract class StorageBackend /** Deletes the file from the storage backend. */ abstract public function deletePhysicalFile($resourceId); - /** Deletes multiple objects (files) stored on the cloud service. */ - abstract public function deleteObjects(); + /** Deletes all objects (files) stored on the cloud service. To be used + * for station termination */ + abstract public function deleteAllCloudFileObjects(); protected function getBucket() { diff --git a/airtime_mvc/application/controllers/ProvisioningController.php b/airtime_mvc/application/controllers/ProvisioningController.php index 313fae351..3039df7a4 100644 --- a/airtime_mvc/application/controllers/ProvisioningController.php +++ b/airtime_mvc/application/controllers/ProvisioningController.php @@ -25,7 +25,7 @@ class ProvisioningController extends Zend_Controller_Action foreach ($CC_CONFIG["supportedStorageBackends"] as $storageBackend) { $proxyStorageBackend = new ProxyStorageBackend($storageBackend); - $proxyStorageBackend->deleteObjects(); + $proxyStorageBackend->deleteAllCloudFileObjects(); } //check at to make sure cloud_file table is empty