SyncCommand.php in FormAssembly 8
File
src/Command/SyncCommand.php
View source
<?php
namespace Drupal\formassembly\Command;
use Drupal\Console\Annotations\DrupalCommand;
use Drupal\formassembly\FormAssemblyBatchProcessor;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\ContainerAwareCommand;
class SyncCommand extends ContainerAwareCommand {
protected $batchProcessor;
protected $progressBar;
public function __construct(FormAssemblyBatchProcessor $batchProcessor) {
$this->batchProcessor = $batchProcessor;
parent::__construct();
}
protected function configure() {
$this
->setName('formassembly:sync')
->setDescription($this
->trans('commands.formassembly.sync.description'));
}
protected function execute(InputInterface $input, OutputInterface $output) {
$finished = FALSE;
$batchConfig = [];
$this->batchProcessor
->configureBatch($batchConfig);
$this->progressBar = $this
->getIo()
->createProgressBar();
while (!$finished) {
$this->batchProcessor
->iterateBatch($batchConfig);
$this->progressBar
->advance();
$finished = $batchConfig['finished'] === 1;
}
$this->progressBar
->finish();
$this
->getIo()
->text($this
->trans('commands.formassembly.sync.messages.processing'));
$this->batchProcessor
->batchPostProcess($batchConfig['sandbox']['sync_id']);
$this
->getIo()
->success($this
->trans('commands.formassembly.sync.messages.success'));
}
}