Commit 2060ed40 authored by baldwinlouie's avatar baldwinlouie Committed by Yas Naoi
Browse files

Issue #3273629 by baldwinlouie, yas: Remove revisions from Drupal\cloud\Entity\CloudStore

parent f271c7e0
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -1171,3 +1171,60 @@ function cloud_update_8155(): void {
  $config->set('cloud_custom_d3_horizon_chart_js_url', 'https://unpkg.com/@docomoinnovations/horizon-chart@1.1.0/dist/d3-horizon-chart.js');
  $config->save();
}

/**
 * Update cloud_store entity type.
 *
 * This update deletes all cloud_store data and updates the
 * cloud_store entity structure.  Backup your data before
 * performing this update.
 */
function cloud_update_8156(): void {
  // Truncate the cloud_store tables since the new code will conflict with
  // existing entities.
  $tables = [
    'cloud_store',
    'cloud_store__field_cloud_context',
    'cloud_store__field_costs',
    'cloud_store__field_resources',
    'cloud_store_field_data',
    'cloud_store_field_revision',
    'cloud_store_revision',
    'cloud_store_revision__field_cloud_context',
    'cloud_store_revision__field_costs',
    'cloud_store_revision__field_resources',
  ];
  $db = \Drupal::database();
  foreach ($tables ?: [] as $table) {
    $db->truncate($table)->execute();
  }

  // Delete and re-add cloud_store.
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = \Drupal::entityTypeManager()->getDefinition('cloud_store');
  if (!empty($entity_type)) {
    $definition_update_manager->uninstallEntityType($entity_type);
    // Finally re-add the entity type.
    $definition_update_manager->installEntityType($entity_type);
  }

  // After uninstalling entity type, delete the revision related tables.
  $delete_tables = [
    'cloud_store_field_data',
    'cloud_store_field_revision',
    'cloud_store_revision',
    'cloud_store_revision__field_cloud_context',
    'cloud_store_revision__field_costs',
    'cloud_store_revision__field_resources',
  ];
  foreach ($delete_tables ?: [] as $table) {
    $db->schema()->dropTable($table);
  }

  // Update cloud_store view.
  $files = [
    'views.view.cloud_store.yml',
  ];
  \Drupal::service('cloud')->updateYmlDefinitions($files, 'cloud');

}
+0 −4
Original line number Diff line number Diff line
@@ -110,10 +110,6 @@ entity.cloud_store.delete_form:
  class: '\Drupal\cloud\Plugin\Derivative\CloudStoreTab'
  title: 'Delete'

entity.cloud_store.version_history:
  route_name: entity.cloud_store.version_history
  base_route: entity.cloud_store.canonical
  title: 'Revisions'

# Structure | Cloud service providers | List.
# The cloud service provider (CloudConfig) menu items definition.
+3 −3
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ label: 'Cloud store'
module: views
description: 'Listing page showing all cloud store type.'
tag: ''
base_table: cloud_store_field_data
base_table: cloud_store
base_field: id
display:
  default:
@@ -127,7 +127,7 @@ display:
      fields:
        type:
          id: type
          table: cloud_store_field_data
          table: cloud_store
          field: type
          relationship: none
          group_type: group
@@ -194,7 +194,7 @@ display:
      sorts:
        type:
          id: type
          table: cloud_store_field_data
          table: cloud_store
          field: type
          relationship: none
          group_type: group
+21 −21
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ label: 'K8s cloud store'
module: views
description: 'Listing page showing all cloud store.'
tag: ''
base_table: cloud_store_field_data
base_table: cloud_store
base_field: id
display:
  default:
@@ -30,7 +30,7 @@ display:
      fields:
        name:
          id: name
          table: cloud_store_field_data
          table: cloud_store
          field: name
          relationship: none
          group_type: group
@@ -95,7 +95,7 @@ display:
          field_api_classes: false
        created:
          id: created
          table: cloud_store_field_data
          table: cloud_store
          field: created
          relationship: none
          group_type: group
@@ -378,7 +378,7 @@ display:
      sorts:
        created:
          id: created
          table: cloud_store_field_data
          table: cloud_store
          field: created
          relationship: none
          group_type: group
@@ -396,7 +396,7 @@ display:
      filters:
        type:
          id: type
          table: cloud_store_field_data
          table: cloud_store
          field: type
          relationship: none
          group_type: group
@@ -573,7 +573,7 @@ display:
          selected_actions: {  }
        name:
          id: name
          table: cloud_store_field_data
          table: cloud_store
          field: name
          relationship: none
          group_type: group
@@ -638,7 +638,7 @@ display:
          field_api_classes: false
        created:
          id: created
          table: cloud_store_field_data
          table: cloud_store
          field: created
          relationship: none
          group_type: group
@@ -705,7 +705,7 @@ display:
          field_api_classes: false
        cloud_context:
          id: cloud_context
          table: cloud_store_field_data
          table: cloud_store
          field: cloud_context
          relationship: none
          group_type: group
@@ -884,7 +884,7 @@ display:
      filters:
        type:
          id: type
          table: cloud_store_field_data
          table: cloud_store
          field: type
          relationship: none
          group_type: group
@@ -1081,7 +1081,7 @@ display:
          selected_actions: {  }
        name:
          id: name
          table: cloud_store_field_data
          table: cloud_store
          field: name
          relationship: none
          group_type: group
@@ -1146,7 +1146,7 @@ display:
          field_api_classes: false
        created:
          id: created
          table: cloud_store_field_data
          table: cloud_store
          field: created
          relationship: none
          group_type: group
@@ -1213,7 +1213,7 @@ display:
          field_api_classes: false
        cloud_context:
          id: cloud_context
          table: cloud_store_field_data
          table: cloud_store
          field: cloud_context
          relationship: none
          group_type: group
@@ -1455,7 +1455,7 @@ display:
      filters:
        type:
          id: type
          table: cloud_store_field_data
          table: cloud_store
          field: type
          relationship: none
          group_type: group
@@ -1652,7 +1652,7 @@ display:
          selected_actions: {  }
        name:
          id: name
          table: cloud_store_field_data
          table: cloud_store
          field: name
          relationship: none
          group_type: group
@@ -1717,7 +1717,7 @@ display:
          field_api_classes: false
        created:
          id: created
          table: cloud_store_field_data
          table: cloud_store
          field: created
          relationship: none
          group_type: group
@@ -1784,7 +1784,7 @@ display:
          field_api_classes: false
        cloud_context:
          id: cloud_context
          table: cloud_store_field_data
          table: cloud_store
          field: cloud_context
          relationship: none
          group_type: group
@@ -1963,7 +1963,7 @@ display:
      filters:
        type:
          id: type
          table: cloud_store_field_data
          table: cloud_store
          field: type
          relationship: none
          group_type: group
@@ -2151,7 +2151,7 @@ display:
          selected_actions: {  }
        name:
          id: name
          table: cloud_store_field_data
          table: cloud_store
          field: name
          relationship: none
          group_type: group
@@ -2216,7 +2216,7 @@ display:
          field_api_classes: false
        created:
          id: created
          table: cloud_store_field_data
          table: cloud_store
          field: created
          relationship: none
          group_type: group
@@ -2283,7 +2283,7 @@ display:
          field_api_classes: false
        cloud_context:
          id: cloud_context
          table: cloud_store_field_data
          table: cloud_store
          field: cloud_context
          relationship: none
          group_type: group
@@ -2462,7 +2462,7 @@ display:
      filters:
        type:
          id: type
          table: cloud_store_field_data
          table: cloud_store
          field: type
          relationship: none
          group_type: group
+34 −1
Original line number Diff line number Diff line
@@ -6,9 +6,9 @@
 */

use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Config\FileStorage;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\k8s\Entity\K8sEntityInterface;
@@ -86,6 +86,7 @@ function k8s_update_dependencies(): array {
      8306 => ['cloud' => 8147],
      8307 => ['cloud' => 8148],
      8332 => ['cloud' => 8153],
      8348 => ['cloud' => 8156],
    ],
    'cloud' => [
      8150 => ['k8s' => 8312],
@@ -3615,3 +3616,35 @@ function k8s_update_8347(): void {
    $field
  );
}

/**
 * Re-add K8s cloud_store bundle after the entity update.
 */
function k8s_update_8348() {
  // Add new fields and field_store for cloud_store.k8s.
  $files = [
    'field.storage.cloud_store.field_cloud_context.yml',
    'field.storage.cloud_store.field_costs.yml',
    'field.storage.cloud_store.field_resources.yml',
    'cloud.cloud_store_type.k8s_cost_store.yml',
    'cloud.cloud_store_type.k8s_namespace_resource_store.yml',
    'cloud.cloud_store_type.k8s_node_resource_store.yml',
    'cloud.cloud_store_type.k8s_pod_resource_store.yml',
    'core.entity_view_display.cloud_store.k8s_cost_store.default.yml',
    'core.entity_view_display.cloud_store.k8s_namespace_resource_store.default.yml',
    'core.entity_view_display.cloud_store.k8s_node_resource_store.default.yml',
    'core.entity_view_display.cloud_store.k8s_pod_resource_store.default.yml',
    'field.field.cloud_store.k8s_cost_store.field_costs.yml',
    'field.field.cloud_store.k8s_cost_store.field_resources.yml',
    'field.field.cloud_store.k8s_namespace_resource_store.field_cloud_context.yml',
    'field.field.cloud_store.k8s_namespace_resource_store.field_costs.yml',
    'field.field.cloud_store.k8s_namespace_resource_store.field_resources.yml',
    'field.field.cloud_store.k8s_node_resource_store.field_cloud_context.yml',
    'field.field.cloud_store.k8s_node_resource_store.field_resources.yml',
    'field.field.cloud_store.k8s_pod_resource_store.field_cloud_context.yml',
    'field.field.cloud_store.k8s_pod_resource_store.field_resources.yml',
    'views.view.k8s_cloud_store.yml',
  ];
  \Drupal::service('cloud')->updateYmlDefinitions($files, 'k8s');
  drupal_flush_all_caches();
}
Loading