MigrationCommands.php in Lightning Workflow 8.2
File
modules/lightning_scheduler/src/Commands/MigrationCommands.php
View source
<?php
namespace Drupal\lightning_scheduler\Commands;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\lightning_scheduler\Migrator;
use Drush\Commands\DrushCommands;
final class MigrationCommands extends DrushCommands {
protected $migrator;
public function __construct(Migrator $migrator, TranslationInterface $translation = NULL) {
$this->migrator = $migrator;
}
public function migrate($entity_type_id = NULL) {
$out = $this
->output();
$entity_types = $this->migrator
->getEntityTypesToMigrate((array) $entity_type_id);
if (empty($entity_types)) {
if ($entity_type_id) {
$out
->writeln("The {$entity_type_id} entity type does not need to be migrated.");
}
else {
$out
->writeln('All migrations are complete.');
}
return;
}
$message = $this->migrator
->generatePreMigrationMessage($entity_types, FALSE);
$out
->writeln((string) $message);
$continue = $this
->confirm('Continue?');
if (empty($continue)) {
return;
}
foreach ($entity_types as $entity_type_id => $entity_type) {
$callback = function ($entity_type_id, $count) use ($entity_type, $out) {
if ($count % 10 === 0) {
$variables = [
'@singular' => $entity_type
->getSingularLabel(),
'@plural' => $entity_type
->getPluralLabel(),
];
$message = new PluralTranslatableMarkup($count, '1 @singular migrated.', '@count @plural migrated.', $variables);
$out
->writeln((string) $message);
}
};
$this->migrator
->migrateAll($entity_type_id, $callback);
}
}
public function purge($entity_type_id) {
$out = $this
->output();
$entity_types = $this->migrator
->getEntityTypesToMigrate((array) $entity_type_id);
if (empty($entity_types)) {
$out
->writeln('The given entity type either does not need to be migrated, or it has already been migrated or purged.');
return;
}
$message = "You are about to purge existing scheduled transitions for the given entity type. This will permanently delete scheduled transitions and cannot be undone.";
$out
->writeln($message);
$continue = $this
->confirm('Continue?');
if (empty($continue)) {
return;
}
$this->migrator
->purge($entity_type_id, 'scheduled_publication');
$this->migrator
->purge($entity_type_id, 'scheduled_moderation_state');
$this->migrator
->completeMigration($entity_type_id);
}
}
Classes
Name |
Description |
MigrationCommands |
Provides Drush commands for migrating scheduler data to the new base fields. |