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
- class \Drupal\formassembly\Commands\FormassemblyCommands extends \Drush\Commands\DrushCommands
Expanded class hierarchy of FormassemblyCommands
1 string reference to 'FormassemblyCommands'
1 service uses FormassemblyCommands
File
- src/
Commands/ FormassemblyCommands.php, line 21
Namespace
Drupal\formassembly\CommandsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormassemblyCommands:: |
protected | property | Injected Sync service. | |
FormassemblyCommands:: |
protected | property | Symfony progress bar component. | |
FormassemblyCommands:: |
public | function | Synchronize the available forms with a Formassembly endpoint.. | |
FormassemblyCommands:: |
public | function | FormassemblyCommands constructor. |