01f26048be466ce5b00f1274f0a8f31f490759b0
[yaffs-website] / vendor / drupal / console / src / Command / Debug / MigrateCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Debug\MigrateCommand.
6  */
7
8 namespace Drupal\Console\Command\Debug;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Command\Shared\MigrationTrait;
14 use Drupal\Console\Annotations\DrupalCommand;
15 use Drupal\Console\Core\Command\Command;
16 use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
17
18 /**
19  * @DrupalCommand(
20  *     extension = "migrate",
21  *     extensionType = "module"
22  * )
23  */
24 class MigrateCommand extends Command
25 {
26     use MigrationTrait;
27
28     /**
29      * @var MigrationPluginManagerInterface $pluginManagerMigration
30      */
31     protected $pluginManagerMigration;
32
33     /**
34      * MigrateCommand constructor.
35      *
36      * @param MigrationPluginManagerInterface $pluginManagerMigration
37      */
38     public function __construct(
39         MigrationPluginManagerInterface $pluginManagerMigration
40     ) {
41         $this->pluginManagerMigration = $pluginManagerMigration;
42         parent::__construct();
43     }
44
45     protected function configure()
46     {
47         $this
48             ->setName('debug:migrate')
49             ->setDescription($this->trans('commands.debug.migrate.description'))
50             ->addArgument(
51                 'tag',
52                 InputArgument::OPTIONAL,
53                 $this->trans('commands.debug.migrate.arguments.tag')
54             )
55             ->setAliases(['mid']);
56     }
57
58     protected function execute(InputInterface $input, OutputInterface $output)
59     {
60         $drupal_version = 'Drupal ' . $input->getArgument('tag');
61
62         $migrations = $this->getMigrations($drupal_version);
63
64
65         $tableHeader = [
66           $this->trans('commands.debug.migrate.messages.id'),
67           $this->trans('commands.debug.migrate.messages.description'),
68           $this->trans('commands.debug.migrate.messages.tags'),
69         ];
70
71         $tableRows = [];
72         if (empty($migrations)) {
73             $this->getIo()->error(
74                 sprintf(
75                     $this->trans('commands.debug.migrate.messages.no-migrations'),
76                     count($migrations)
77                 )
78             );
79         }
80         foreach ($migrations as $migration_id => $migration) {
81             $tableRows[] = [$migration_id, $migration['description'], $migration['tags']];
82         }
83         $this->getIo()->table($tableHeader, $tableRows, 'compact');
84     }
85 }