Skip to content
Snippets Groups Projects
Commit a26cfda7 authored by baldwinlouie's avatar baldwinlouie
Browse files

git commit -m 'Issue #2982643: [Porting to D8] - Implement hook_cloud_config_delete()'

parent b4b9413a
No related branches found
No related tags found
No related merge requests found
......@@ -77,3 +77,19 @@ function cloud_server_template_theme_suggestions_cloud_server_template(array $va
$suggestions[] = 'cloud_server_template__' . $entity->id() . '__' . $sanitized_view_mode;
return $suggestions;
}
/**
* Implements hook_cloud_config_delete().
*/
function cloud_server_template_cloud_config_delete(\Drupal\cloud\Entity\CloudConfig $cloud_config) {
$ids = \Drupal::entityQuery('cloud_server_template')
->condition('cloud_context', $cloud_config->cloud_context())
->execute();
if (count($ids)) {
/* @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager */
$entity_manager = \Drupal::entityTypeManager();
$entities = $entity_manager->getStorage('cloud_server_template')->loadMultiple($ids);
$entity_manager->getStorage('cloud_server_template')->delete($entities);
}
}
\ No newline at end of file
......@@ -161,5 +161,14 @@ function aws_cloud_cron() {
// @todo: re-enabled instance bundling
}
}
/**
* Implements hook_cloud_config_delete().
*/
function aws_cloud_cloud_config_delete(\Drupal\cloud\Entity\CloudConfig $cloud_config) {
/* @var \Drupal\aws_cloud\Service\AwsEc2ServiceInterface $aws_ec2_service */
$aws_ec2_service = \Drupal::service('aws_cloud.ec2');
$aws_ec2_service->setCloudContext($cloud_config->cloud_context());
$aws_ec2_service->clearAllEntities();
}
......@@ -1094,6 +1094,21 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
return $zones;
}
/**
* {@inheritdoc}
*/
public function clearAllEntities() {
$timestamp = $this->getTimestamp();
$this->clearEntities('aws_cloud_instance', $timestamp);
$this->clearEntities('aws_cloud_security_group', $timestamp);
$this->clearEntities('aws_cloud_image', $timestamp);
$this->clearEntities('aws_cloud_network_interface', $timestamp);
$this->clearEntities('aws_cloud_elastic_ip', $timestamp);
$this->clearEntities('aws_cloud_key_pair', $timestamp);
$this->clearEntities('aws_cloud_volume', $timestamp);
$this->clearEntities('aws_cloud_snapshot', $timestamp);
}
/**
* Helper method to get the current timestamp
* @return int
......@@ -1134,6 +1149,7 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
private function clearEntities($entity_type, $timestamp) {
$entity_ids = $this->queryFactory->get($entity_type)
->condition('refreshed', $timestamp, '<')
->condition('cloud_context', $this->cloud_context)
->execute();
if (count($entity_ids)) {
$this->deleteEntities($entity_type, $entity_ids);
......
......@@ -395,4 +395,10 @@ interface AwsEc2ServiceInterface {
*/
public function getVpcs();
/**
* Method to clear all entities out of the system.
* @return mixed
*/
public function clearAllEntities();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment