You are here

function webform_scheduled_email_cron_process in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_scheduled_email/drush/webform_scheduled_email.drush.inc \webform_scheduled_email_cron_process()

Implements drush_hook_COMMAND().

NOTE: Unable to use drush_hook_COMMAND_validate because we are using a custom callback to prevent conflicts with webform_scheduled_email_cron().

See also

webform_scheduled_email_cron()

\Drupal\webform_scheduled_email\Commands\WebformScheduledEmailCommands::drush_webform_scheduled_email_cron_validate()

\Drupal\webform_scheduled_email\Commands\WebformScheduledEmailCommands::drush_webform_scheduled_email_cron()

1 string reference to 'webform_scheduled_email_cron_process'
webform_scheduled_email_drush_command in modules/webform_scheduled_email/drush/webform_scheduled_email.drush.inc
Implements hook_drush_command().

File

modules/webform_scheduled_email/drush/webform_scheduled_email.drush.inc, line 70
Webform scheduled email module drush commands.

Code

function webform_scheduled_email_cron_process($webform_id = NULL, $handler_id = NULL) {
  $schedule_limit = drush_get_option('schedule_limit') ?: 1000;
  $send_limit = drush_get_option('send_limit') ?: 500;

  // Get and validate optional $webform_id parameter.
  $webform = NULL;
  if ($webform_id) {
    $webform = Webform::load($webform_id);
    if (!$webform) {
      return drush_set_error(dt('Webform @id not recognized.', [
        '@id' => $webform_id,
      ]));
    }
  }

  // Get and validate optional $handler_id parameter.
  if ($handler_id) {
    try {
      $handler = $webform
        ->getHandler($handler_id);
    } catch (\Exception $exception) {
      return drush_set_error(dt('Handler @id not recognized.', [
        '@id' => $handler_id,
      ]));
    }
    if (!$handler instanceof ScheduleEmailWebformHandler) {
      return drush_set_error(dt('Handler @id is not a scheduled email handler.', [
        '@id' => $handler_id,
      ]));
    }
  }
  $webform = $webform_id ? Webform::load($webform_id) : NULL;

  /** @var \Drupal\webform_scheduled_email\WebformScheduledEmailManagerInterface $webform_scheduled_email_manager */
  $webform_scheduled_email_manager = \Drupal::service('webform_scheduled_email.manager');
  $stats = $webform_scheduled_email_manager
    ->cron($webform, $handler_id, $schedule_limit, $send_limit);
  Drush::output()
    ->writeln(dt($stats['_message'], $stats['_context']));
}