You are here

public function FormassemblyCommands::sync in FormAssembly 8

Synchronize the available forms with a Formassembly endpoint..

@usage formassembly:sync This command runs a batch sync. It has no options.

@command formassembly:sync @aliases fas

File

src/Commands/FormassemblyCommands.php, line 57

Class

FormassemblyCommands
FormAssembly Drush commandfile.

Namespace

Drupal\formassembly\Commands

Code

public function sync() {
  $finished = FALSE;
  $batchConfig = [];
  try {
    $this->batchProcessor
      ->configureBatch($batchConfig);
    $this->progressBar = $this
      ->io()
      ->createProgressBar();
    while (!$finished) {
      $this->batchProcessor
        ->iterateBatch($batchConfig);
      $this->progressBar
        ->advance();
      $finished = $batchConfig['finished'] === 1;
    }
    $this->progressBar
      ->finish();
    $this
      ->io()
      ->newLine();
    $this
      ->io()
      ->text(dt('Processing data received from FormAssembly'));
    $this->batchProcessor
      ->batchPostProcess($batchConfig['sandbox']['sync_id']);
    $this
      ->logger()
      ->success(dt('Forms synchronized successfully'));
  } catch (\Exception $e) {
    $this->logger
      ->error(dt('Sync failed due to an Exception'));
    throw $e;
  }
}