SAAS-525: Station Termination -> Delete cloud_file table records
Deleted cloud_file records. Renamed the function that does this.
This commit is contained in:
parent
09c30bde1b
commit
ab4ebb2969
|
@ -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);
|
||||
$this->s3Client->deleteMatchingObjects(
|
||||
$bucket = $this->getBucket(),
|
||||
$prefix = Application_Model_Preference::GetStationName());
|
||||
|
||||
if ($cloudFilePager->haveToPaginate()) {
|
||||
$numPages = $cloudFilePager->getLastPage();
|
||||
$currentPage = 1;
|
||||
while ($currentPage <= $numPages) {
|
||||
$cloudFilePager = CloudFileQuery::create()
|
||||
->filterByStorageBackend("amazon_S3")
|
||||
->paginate($page = $currentPage, $maxPerPage = 1000);
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,9 +43,9 @@ class ProxyStorageBackend extends StorageBackend
|
|||
$this->storageBackend->deletePhysicalFile($resourceId);
|
||||
}
|
||||
|
||||
public function deleteObjects()
|
||||
public function deleteAllCloudFileObjects()
|
||||
{
|
||||
$this->storageBackend->deleteObjects();
|
||||
$this->storageBackend->deleteAllCloudFileObjects();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue