X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FMigrate%2FRollBackCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FMigrate%2FRollBackCommand.php;h=1d0b3a6d90466626b5f5246e024b8828edc8302c;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Migrate/RollBackCommand.php b/vendor/drupal/console/src/Command/Migrate/RollBackCommand.php new file mode 100644 index 000000000..1d0b3a6d9 --- /dev/null +++ b/vendor/drupal/console/src/Command/Migrate/RollBackCommand.php @@ -0,0 +1,181 @@ +pluginManagerMigration = $pluginManagerMigration; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('migrate:rollback') + ->setDescription($this->trans('commands.migrate.rollback.description')) + ->addArgument('migration-ids', InputArgument::IS_ARRAY, $this->trans('commands.migrate.rollback.arguments.id')) + ->addOption( + 'source-base_path', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.migrate.setup.options.source-base_path') + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $sourceBasepath = $input->getOption('source-base_path'); + $configuration['source']['constants']['source_base_path'] = rtrim($sourceBasepath, '/') . '/'; + // --migration-id prefix + $migration_id = $input->getArgument('migration-ids'); + $migrations_list = array_keys($this->getMigrations($version_tag)); + // If migrations weren't provided finish execution + if (empty($migration_id)) { + return; + } + + + if (!in_array('all', $migration_id)) { + $migration_ids = $migration_id; + } else { + $migration_ids = $migrations_list; + } + + foreach ($migration_ids as $migration) { + if (!in_array($migration, $migrations_list)) { + $io->warning( + sprintf( + $this->trans('commands.migrate.rollback.messages.not-available'), + $migration + ) + ); + continue; + } + $migration_service = $this->pluginManagerMigration->createInstance($migration, $configuration); + if ($migration_service) { + $messages = new MigrateExecuteMessageCapture(); + $executable = new MigrateExecutable($migration_service, $messages); + + $migration_status = $executable->rollback(); + switch ($migration_status) { + case MigrationInterface::RESULT_COMPLETED: + $io->info( + sprintf( + $this->trans('commands.migrate.rollback.messages.processing'), + $migration + ) + ); + break; + case MigrationInterface::RESULT_INCOMPLETE: + $io->info( + sprintf( + $this->trans('commands.migrate.execute.messages.importing-incomplete'), + $migration + ) + ); + break; + case MigrationInterface::RESULT_STOPPED: + $io->error( + sprintf( + $this->trans('commands.migrate.execute.messages.import-stopped'), + $migration + ) + ); + break; + } + } + } + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + // Get migrations + $migrations_list = $this->getMigrations($version_tag); + + // --migration-id prefix + $migration_id = $input->getArgument('migration-ids'); + + + if (!$migration_id) { + $migrations_ids = []; + + while (true) { + $migration_id = $io->choiceNoList( + $this->trans('commands.migrate.execute.questions.id'), + array_keys($migrations_list), + 'all' + ); + + if (empty($migration_id) || $migration_id == 'all') { + // Only add all if it's the first option + if (empty($migrations_ids) && $migration_id == 'all') { + $migrations_ids[] = $migration_id; + } + break; + } else { + $migrations_ids[] = $migration_id; + } + } + + $input->setArgument('migration-ids', $migrations_ids); + } + + // --source-base_path + $sourceBasepath = $input->getOption('source-base_path'); + if (!$sourceBasepath) { + $sourceBasepath = $io->ask( + $this->trans('commands.migrate.setup.questions.source-base_path'), + '' + ); + $input->setOption('source-base_path', $sourceBasepath); + } + } +}