You are here

public function WebformScheduledEmailManager::reschedule in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_scheduled_email/src/WebformScheduledEmailManager.php \Drupal\webform_scheduled_email\WebformScheduledEmailManager::reschedule()

REscheduled an email that is waiting to sent.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A webform, webform submission, or source entity.

string|null $handler_id: The webform handler ID.

Overrides WebformScheduledEmailManagerInterface::reschedule

File

modules/webform_scheduled_email/src/WebformScheduledEmailManager.php, line 393

Class

WebformScheduledEmailManager
Defines the webform scheduled email manager.

Namespace

Drupal\webform_scheduled_email

Code

public function reschedule(EntityInterface $entity, $handler_id = NULL) {
  if ($entity instanceof WebformSubmissionInterface) {
    $webform_submission = $entity;
    $query = $this->database
      ->update('webform_scheduled_email')
      ->fields([
      'state' => WebformScheduledEmailManagerInterface::SUBMISSION_RESCHEDULE,
    ])
      ->condition('sid', $webform_submission
      ->id());
    if ($handler_id) {
      $query
        ->condition('handler_id', $handler_id);
    }
    $query
      ->execute();
  }
  elseif ($entity instanceof WebformInterface) {
    $webform = $entity;
    $query = $this->database
      ->update('webform_scheduled_email')
      ->fields([
      'state' => WebformScheduledEmailManagerInterface::SUBMISSION_RESCHEDULE,
    ])
      ->condition('webform_id', $webform
      ->id());
    if ($handler_id) {
      $query
        ->condition('handler_id', $handler_id);
    }
    $query
      ->execute();
  }

  // Since webform and submissions can also be used as a source entity,
  // include them in rescheduling.
  $query = $this->database
    ->update('webform_scheduled_email')
    ->fields([
    'state' => WebformScheduledEmailManagerInterface::SUBMISSION_RESCHEDULE,
  ])
    ->condition('entity_type', $entity
    ->getEntityTypeId())
    ->condition('entity_id', $entity
    ->id());
  if ($handler_id) {
    $query
      ->condition('handler_id', $handler_id);
  }
  $query
    ->execute();
}