Commit acf084b0 authored by Takumaru Sekine's avatar Takumaru Sekine Committed by Yas Naoi
Browse files

Issue #3271949 by sekinet, yas: Fix an issue to delete pod / deployment when...

Issue #3271949 by sekinet, yas: Fix an issue to delete pod / deployment when deleting K8s schedule entity
parent 8ed06a99
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -957,7 +957,7 @@ display:
          operator: '='
          value: cloud_orchestrator_scheduler
          group: 1
          exposed: true
          exposed: false
          expose:
            operator_id: schedule_type_op
            label: 'Schedule type'
@@ -2049,7 +2049,7 @@ display:
          operator: '='
          value: cloud_orchestrator_scheduler
          group: 1
          exposed: true
          exposed: false
          expose:
            operator_id: schedule_type_op
            label: 'Schedule type'
@@ -3240,7 +3240,7 @@ display:
          operator: '='
          value: cloud_orchestrator_scheduler
          group: 1
          exposed: true
          exposed: false
          expose:
            operator_id: schedule_type_op
            label: 'Schedule type'
+11 −0
Original line number Diff line number Diff line
@@ -3577,3 +3577,14 @@ function k8s_update_8344(): void {
  ];
  \Drupal::service('cloud')->updateYmlDefinitions($files, 'k8s');
}

/**
 * Update schedule_type of k8s_schedule.
 */
function k8s_update_8345(): void {
  // Update view k8s_schedule.
  $files = [
    'views.view.k8s_schedule.yml',
  ];
  \Drupal::service('cloud')->updateYmlDefinitions($files, 'k8s');
}
+2 −2
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ use Drupal\k8s\Form\K8sContentFormInterface;
 *     "access"       = "Drupal\k8s\Controller\K8sScheduleAccessControlHandler",
 *     "form" = {
 *       "edit"       = "Drupal\k8s\Form\K8sScheduleEditForm",
 *       "delete"     = "Drupal\k8s\Form\K8sDeleteForm",
 *       "delete-multiple-confirm" = "Drupal\k8s\Form\K8sDeleteMultipleForm",
 *       "delete"     = "Drupal\k8s\Form\K8sScheduleDeleteForm",
 *       "delete-multiple-confirm" = "Drupal\k8s\Form\K8sScheduleDeleteMultipleForm",
 *     },
 *     "route_provider" = {
 *       "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
+54 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\k8s\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Provides a form for deleting a Schedule entity.
 *
 * @ingroup k8s
 */
class K8sScheduleDeleteForm extends K8sDeleteForm {

  /**
   * {@inheritdoc}
   */
  public function getQuestion(): TranslatableMarkup {
    $entity = $this->entity;

    return $this->t('Are you sure you want to delete the "@name" schedule?<br>CAUTION: The @kind "@resource_name" is also going to be deleted.', [
      '@name' => $entity->getName(),
      '@kind' => $entity->getKind(),
      '@resource_name' => $entity->getResourceName(),
    ]);
  }

  /**
   * {@inheritdoc}
   *
   * @throws \Drupal\k8s\Service\K8sServiceException
   *    Thrown when unable to delete entity.
   */
  public function submitForm(array &$form, FormStateInterface $form_state): void {
    $entity = $this->entity;

    // Delete an entity for a resource scheduled in K8sSchedule.
    $scheduled_entity = !empty($entity->getCloudContext()) && !empty($entity->getResourceName()) && $entity->getNamespaceName()
      ? $this->k8sService->getEntity(
        'k8s_' . self::getSnakeCase($entity->getKind()),
        $entity->getCloudContext(),
        $entity->getResourceName(),
        $entity->getNamespaceName(),
      )
      : NULL;
    empty($scheduled_entity) ?: $this->k8sOperationsService->deleteK8sEntity($scheduled_entity);

    // Delete K8sSchedule entity.
    $this->k8sOperationsService->deleteK8sEntity($entity);

    $form_state->setRedirect('view.k8s_schedule.list', ['cloud_context' => $entity->getCloudContext()]);
  }

}
+49 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\k8s\Form;

use Drupal\cloud\Entity\CloudContentEntityBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Provides an entities deletion confirmation form.
 */
class K8sScheduleDeleteMultipleForm extends K8sDeleteMultipleForm {

  /**
   * {@inheritdoc}
   */
  protected function processCloudResource(CloudContentEntityBase $entity): bool {

    // Delete an entity for a resource scheduled in K8sSchedule.
    $scheduled_entity = !empty($entity->getCloudContext()) && !empty($entity->getResourceName()) && $entity->getNamespaceName()
      ? $this->k8sService->getEntity(
        'k8s_' . self::getSnakeCase($entity->getKind()),
        $entity->getCloudContext(),
        $entity->getResourceName(),
        $entity->getNamespaceName(),
      )
      : NULL;
    if (!empty($scheduled_entity)) {
      $name_camel = $this->getShortEntityTypeNameCamel($scheduled_entity);
      $this->deleteCloudResource($scheduled_entity, "delete{$name_camel}");
    }

    return $this->deleteCloudResource($entity, 'deleteSchedule');
  }

  /**
   * {@inheritdoc}
   */
  public function getQuestion(): TranslatableMarkup {

    return $this->formatPlural(count($this->selection),
      'Are you sure you want to delete this @item?<br>CAUTION: The scheduled resources is also going to be deleted.',
      'Are you sure you want to delete these @items?<br>CAUTION: The scheduled resources are also going to be deleted.', [
        '@item' => $this->entityType->getSingularLabel(),
        '@items' => $this->entityType->getPluralLabel(),
      ]
    );
  }

}
Loading