class MigrationDrushCommandProgress in Migrate Tools 8.5
Same name and namespace in other branches
- 8.4 src/EventSubscriber/MigrationDrushCommandProgress.php \Drupal\migrate_tools\EventSubscriber\MigrationDrushCommandProgress
Import and rollback progress bar.
Hierarchy
- class \Drupal\migrate_tools\EventSubscriber\MigrationDrushCommandProgress implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of MigrationDrushCommandProgress
1 string reference to 'MigrationDrushCommandProgress'
1 service uses MigrationDrushCommandProgress
File
- src/
EventSubscriber/ MigrationDrushCommandProgress.php, line 15
Namespace
Drupal\migrate_tools\EventSubscriberView source
class MigrationDrushCommandProgress implements EventSubscriberInterface {
/**
* The logger service.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* MigrationDrushCommandProgress constructor.
*
* @param \Psr\Log\LoggerInterface $logger
* The logger service.
*/
public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
}
/**
* The progress bar.
*
* @var \Symfony\Component\Console\Helper\ProgressBar
*/
protected $symfonyProgressBar;
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [];
$events[MigrateEvents::POST_ROW_SAVE][] = [
'updateProgressBar',
-10,
];
$events[MigrateEvents::MAP_DELETE][] = [
'updateProgressBar',
-10,
];
$events[MigrateEvents::POST_IMPORT][] = [
'clearProgress',
10,
];
$events[MigrateEvents::POST_ROLLBACK][] = [
'clearProgress',
10,
];
return $events;
}
/**
* Initializes the progress bar.
*
* This must be called before the progress bar can be used.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* The output.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration.
*/
public function initializeProgress(OutputInterface $output, MigrationInterface $migration) {
// Don't display progress bar if explicitly disabled.
if (!empty($migration->skipProgressBar)) {
return;
}
// If the source is configured to skip counts, a progress bar is not
// possible.
if (!empty($migration
->getSourceConfiguration()['skip_count'])) {
return;
}
try {
// Clone so that any generators aren't initialized prematurely.
$source = clone $migration
->getSourcePlugin();
$this->symfonyProgressBar = new ProgressBar($output, $source
->count());
} catch (\Exception $exception) {
if (!empty($migration->continueOnFailure)) {
$this->logger
->error($exception
->getMessage());
}
else {
throw $exception;
}
}
}
/**
* Event callback for advancing the progress bar.
*/
public function updateProgressBar() {
if ($this
->isProgressBar()) {
$this->symfonyProgressBar
->advance();
}
}
/**
* Event callback for removing the progress bar after operation is finished.
*/
public function clearProgress() {
if ($this
->isProgressBar()) {
$this->symfonyProgressBar
->clear();
}
}
/**
* Determine if a progress bar should be displayed.
*
* @return bool
* TRUE if a progress bar should be displayed, FALSE otherwise.
*/
protected function isProgressBar() {
// Can't do anything if the progress bar is not initialised; this probably
// means we're not running as a Drush command and so we should do nothing.
if (!$this->symfonyProgressBar) {
return FALSE;
}
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrationDrushCommandProgress:: |
protected | property | The logger service. | |
MigrationDrushCommandProgress:: |
protected | property | The progress bar. | |
MigrationDrushCommandProgress:: |
public | function | Event callback for removing the progress bar after operation is finished. | |
MigrationDrushCommandProgress:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
MigrationDrushCommandProgress:: |
public | function | Initializes the progress bar. | |
MigrationDrushCommandProgress:: |
protected | function | Determine if a progress bar should be displayed. | |
MigrationDrushCommandProgress:: |
public | function | Event callback for advancing the progress bar. | |
MigrationDrushCommandProgress:: |
public | function | MigrationDrushCommandProgress constructor. |