You are here

public static function MaestroEngine::deleteProcess in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 src/Engine/MaestroEngine.php \Drupal\maestro\Engine\MaestroEngine::deleteProcess()

Removes all data elements associated with a process. This includes queue, assignment, status, entity identifiers and variables.

Parameters

int $processID: The Maestro Process ID.

2 calls to MaestroEngine::deleteProcess()
MaestroTemplateDeleteForm::submitForm in src/Form/MaestroTemplateDeleteForm.php
The submit handler for the confirm form.
MaestroTraceDeleteProcess::submitForm in src/Form/MaestroTraceDeleteProcess.php
Form submission handler.

File

src/Engine/MaestroEngine.php, line 1145

Class

MaestroEngine
Class MaestroEngine.

Namespace

Drupal\maestro\Engine

Code

public static function deleteProcess($processID) {

  // Delete queue items.
  $query = \Drupal::entityQuery('maestro_queue')
    ->condition('process_id', $processID)
    ->accessCheck(FALSE);
  $ids = $query
    ->execute();
  foreach ($ids as $queueID) {

    // Delete the assignments.
    $query = \Drupal::entityQuery('maestro_production_assignments')
      ->condition('queue_id', $queueID)
      ->accessCheck(FALSE);
    $entityIDs = $query
      ->execute();
    foreach ($entityIDs as $entityID) {
      $record = \Drupal::entityTypeManager()
        ->getStorage('maestro_production_assignments')
        ->load($entityID);
      if ($record) {
        $record
          ->delete();
      }
    }
    $queueRecord = MaestroEngine::getQueueEntryById($queueID);
    $queueRecord
      ->delete();
  }

  // Delete entity identifiers.
  $query = \Drupal::entityQuery('maestro_entity_identifiers')
    ->condition('process_id', $processID)
    ->accessCheck(FALSE);
  $entityIDs = $query
    ->execute();
  foreach ($entityIDs as $entityID) {
    $record = \Drupal::entityTypeManager()
      ->getStorage('maestro_entity_identifiers')
      ->load($entityID);
    if ($record) {
      $record
        ->delete();
    }
  }

  // Delete process variables.
  $query = \Drupal::entityQuery('maestro_process_variables')
    ->condition('process_id', $processID)
    ->accessCheck(FALSE);
  $entityIDs = $query
    ->execute();
  foreach ($entityIDs as $entityID) {
    $record = \Drupal::entityTypeManager()
      ->getStorage('maestro_process_variables')
      ->load($entityID);
    if ($record) {
      $record
        ->delete();
    }
  }

  // Delete the status.
  $query = \Drupal::entityQuery('maestro_process_status')
    ->condition('process_id', $processID)
    ->accessCheck(FALSE);
  $entityIDs = $query
    ->execute();
  foreach ($entityIDs as $entityID) {
    $record = \Drupal::entityTypeManager()
      ->getStorage('maestro_process_status')
      ->load($entityID);
    if ($record) {
      $record
        ->delete();
    }
  }

  // finally, delete the process.
  $processRecord = MaestroEngine::getProcessEntryById($processID);
  $processRecord
    ->delete();
}