SAAS-517: Create Provisioning controller with a terminate endpoint

This commit is contained in:
drigato 2014-12-11 13:35:34 -05:00
parent 008ffa025a
commit 891cfdb48e
5 changed files with 70 additions and 37 deletions

View file

@ -1,5 +1,7 @@
<?php
require_once 'ProxyStorageBackend.php';
use Aws\S3\S3Client;
class ProvisioningController extends Zend_Controller_Action
@ -19,44 +21,24 @@ class ProvisioningController extends Zend_Controller_Action
return;
}
//TODO - don't hardcode this here. maybe set it in $CC_CONFIG
$cloudFiles = array(
"amazon_S3" => array()
);
$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"]));
}
foreach ($CC_CONFIG["supportedStorageBackends"] as $storageBackend) {
$proxyStorageBackend = new ProxyStorageBackend($storageBackend);
$proxyStorageBackend->deleteObjects();
}
//check at to make sure cloud_file table is empty
if (CloudFileQuery::create()->count() > 0) {
$this->getResponse()
->setHttpResponseCode(400)
->appendBody("ERROR: Not all cloud files were deleted.");
return;
}
$this->getResponse()
->setHttpResponseCode(200)
->appendBody("OK");
}
private function verifyAPIKey()