You are here

public function FormAssemblyBatchProcessor::iterateBatch in FormAssembly 8

Processes one iteration of the batch process.

Parameters

array $batchConfig: An array with batch configuration options.

Throws

\Exception

File

src/FormAssemblyBatchProcessor.php, line 86

Class

FormAssemblyBatchProcessor
The "business logic" of the batch process for syncing with FormAssembly.

Namespace

Drupal\formassembly

Code

public function iterateBatch(array &$batchConfig) {

  // Batch has started processing.  Get the cache id back from context.
  $sync_id = $batchConfig['sandbox']['sync_id'];
  try {
    $batchConfig['message'] = t('Requesting page %page of forms.', [
      '%page' => $this->apiSync
        ->getPage(),
    ]);
    if ($this->apiSync
      ->getForms($sync_id)) {

      // Returns true when finished.
      $batchConfig['finished'] = 1;
      $batchConfig['results']['sync_id'] = $sync_id;
    }
    else {
      $batchConfig['finished'] = 0.66;
    }
  } catch (\Exception $caught) {
    \Drupal::logger('Formassembly')
      ->error('Form batch request failed. Error message: @message', [
      '@message' => $caught
        ->getMessage(),
    ]);
    throw $caught;
  }
}