You are here

protected function WebformSubmissionDevelGenerateTrait::generateSubmissions in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateTrait.php \Drupal\webform\Plugin\DevelGenerate\WebformSubmissionDevelGenerateTrait::generateSubmissions()

Generates submissions for a list of given webforms.

Parameters

array $values: The element values from the settings webform.

1 call to WebformSubmissionDevelGenerateTrait::generateSubmissions()
WebformSubmissionDevelGenerateTrait::generateElements in src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateTrait.php

File

src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateTrait.php, line 229

Class

WebformSubmissionDevelGenerateTrait
Provides a WebformSubmissionDevelGenerate plugin.

Namespace

Drupal\webform\Plugin\DevelGenerate

Code

protected function generateSubmissions(array $values) {
  static::$generatingSubmissions = TRUE;
  if (!empty($values['kill'])) {
    $this
      ->deleteWebformSubmissions($values['webform_ids'], $values['entity-type'], $values['entity-id']);
    $this
      ->setMessage($this
      ->t('Deleted existing submissions.'));
  }
  if (!empty($values['webform_ids'])) {
    $this
      ->initializeGenerate($values);
    $start = $this->time
      ->getRequestTime();
    for ($i = 1; $i <= $values['num']; $i++) {
      $this
        ->generateSubmission($values);
      $feedback = isset($values['feedback']) && is_int($values['feedback']) ? $values['feedback'] : 1000;
      if ($i % $feedback === 0) {
        $now = $this->time
          ->getRequestTime();
        $dt_args = [
          '@feedback' => $feedback,
          '@rate' => $feedback * 60 / ($now - $start),
        ];
        \Drupal::logger('webform')
          ->notice($this
          ->t('Completed @feedback submissions (@rate submissions/min)', $dt_args));
        $start = $now;
      }
    }
  }
  $this
    ->setMessage($this
    ->formatPlural($values['num'], '1 submissions created.', 'Finished creating @count submissions'));
  static::$generatingSubmissions = FALSE;
}