diff --git a/airtime_mvc/application/controllers/ProvisioningController.php b/airtime_mvc/application/controllers/ProvisioningController.php index 2323b151f..7ce8a4428 100644 --- a/airtime_mvc/application/controllers/ProvisioningController.php +++ b/airtime_mvc/application/controllers/ProvisioningController.php @@ -1,6 +1,6 @@ getZendServiceAmazonS3(); - $bucket = $amazon_s3->getBucket(); + //TODO - don't hardcode this here. maybe set it in $CC_CONFIG + $cloudFiles = array( + "amazon_S3" => array() + ); - // Get all files stored on Amazon S3 - $cloudFiles = CloudFilesQuery::create()->find(); - foreach ($cloudFiles as $cloudFile) { - $resource_id = $this->getResourceId(); - $amz_resource = utf8_encode("$bucket/$resource_id"); - $zend_s3->removeObject($amz_resource); + $CC_CONFIG = Config::getConfig(); + + //TODO - dynamically select the storage backend credentials here + $s3Client = S3Client::factory(array( + 'key' => $CC_CONFIG["amazon_S3"]['api_key'], + 'secret' => $CC_CONFIG["amazon_S3"]['api_key_secret'], + )); + + $cloudFilePager = CloudFileQuery::create() + ->paginate($page=1, $maxPerPage=1000); + + if ($cloudFilePager->haveToPaginate()) { + $numPages = $cloudFilePager->getLastPage(); + $currentPage = 1; + while ($currentPage <= $numPages) { + $cloudFilePager = CloudFileQuery::create() + ->paginate($page = $currentPage, $maxPerPage = 1000); + + //TODO - delete objects here + + $currentPage += 1; + } + } else { + //TODO - move this into function so it can be reused above + foreach ($cloudFilePager->getResults() as $cloudFile) { + array_push($cloudFiles[$cloudFile->getStorageBackend()], + array("Key" => $cloudFile->getResourceId())); + + $result = $s3Client->deleteObjects(array( + "Bucket" => $CC_CONFIG["amazon_S3"]["bucket"], + "Objects" => $cloudFiles["amazon_S3"])); + } } }