You are here

class FormassemblyCommands in FormAssembly 8

FormAssembly Drush commandfile.

@author Shawn P. Duncan <code@sd.shawnduncan.org>

Copyright 2019 by Shawn P. Duncan. This code is released under the GNU General Public License. Which means that it is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. http://www.gnu.org/licenses/gpl.html

Hierarchy

Expanded class hierarchy of FormassemblyCommands

1 string reference to 'FormassemblyCommands'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses FormassemblyCommands
formassembly.commands in ./drush.services.yml
\Drupal\formassembly\Commands\FormassemblyCommands

File

src/Commands/FormassemblyCommands.php, line 21

Namespace

Drupal\formassembly\Commands
View source
class FormassemblyCommands extends DrushCommands {

  /**
   * Injected Sync service.
   *
   * @var \Drupal\formassembly\FormAssemblyBatchProcessor
   */
  protected $batchProcessor;

  /**
   * Symfony progress bar component.
   *
   * @var \Symfony\Component\Console\Helper\ProgressBar
   */
  protected $progressBar;

  /**
   * FormassemblyCommands constructor.
   *
   * @param \Drupal\formassembly\FormAssemblyBatchProcessor $batchProcessor
   *   Our batch processing service.
   */
  public function __construct(FormAssemblyBatchProcessor $batchProcessor) {
    parent::__construct();
    $this->batchProcessor = $batchProcessor;
  }

  /**
   * 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
   */
  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;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormassemblyCommands::$batchProcessor protected property Injected Sync service.
FormassemblyCommands::$progressBar protected property Symfony progress bar component.
FormassemblyCommands::sync public function Synchronize the available forms with a Formassembly endpoint..
FormassemblyCommands::__construct public function FormassemblyCommands constructor.