New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[generate:plugin:migrate:dataparser] Add new command for generating data parser plugin for migration. Fix #3773 #3774
Merged
jmolivas
merged 7 commits into
hechoendrupal:master
from
joshirohit100:data_parser_plugin
Apr 22, 2018
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a3a798a
Adding command to generate data parser migrate plugin.
joshirohit100 fc750f9
Updating code styling in twig.
joshirohit100 50ee3e1
Updating code styling in twig.
joshirohit100 dc13fe4
Removing unwanted dependency from container.
joshirohit100 3a4eeed
Adding option for plugin title,
joshirohit100 6550fcd
Adding dependency of extension manager.
joshirohit100 b18260d
Changing the command name.
joshirohit100 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
src/Command/Generate/PluginMigrateDataParserCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Console\Command\Generate\PluginMigrateDataParserCommand. | ||
*/ | ||
|
||
namespace Drupal\Console\Command\Generate; | ||
|
||
use Drupal\Console\Utils\Validator; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Drupal\Console\Core\Command\ContainerAwareCommand; | ||
use Drupal\Console\Generator\PluginMigrateDataParserGenerator; | ||
use Drupal\Console\Command\Shared\ModuleTrait; | ||
use Drupal\Console\Extension\Manager; | ||
use Drupal\Console\Command\Shared\ConfirmationTrait; | ||
use Drupal\Console\Core\Utils\StringConverter; | ||
use Drupal\Console\Core\Utils\ChainQueue; | ||
|
||
class PluginMigrateDataParserCommand extends ContainerAwareCommand | ||
{ | ||
use ModuleTrait; | ||
use ConfirmationTrait; | ||
|
||
/** | ||
* @var PluginMigrateProcessGenerator | ||
*/ | ||
protected $generator; | ||
|
||
/** | ||
* @var ChainQueue | ||
*/ | ||
protected $chainQueue; | ||
|
||
/** | ||
* @var Manager | ||
*/ | ||
protected $extensionManager; | ||
|
||
/** | ||
* @var StringConverter | ||
*/ | ||
protected $stringConverter; | ||
|
||
/** | ||
* @var Validator | ||
*/ | ||
protected $validator; | ||
|
||
/** | ||
* PluginMigrateDataParserGenerator constructor. | ||
* | ||
* @param PluginMigrateDataParserGenerator $generator | ||
* @param ChainQueue $chainQueue | ||
* @param Manager $extensionManager | ||
* @param StringConverter $stringConverter | ||
* @param Validator $validator | ||
*/ | ||
public function __construct( | ||
PluginMigrateDataParserGenerator $generator, | ||
ChainQueue $chainQueue, | ||
Manager $extensionManager, | ||
StringConverter $stringConverter, | ||
Validator $validator | ||
) { | ||
$this->generator = $generator; | ||
$this->chainQueue = $chainQueue; | ||
$this->extensionManager = $extensionManager; | ||
$this->stringConverter = $stringConverter; | ||
$this->validator = $validator; | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setName('generate:plugin:migrate:data_parser') | ||
->setDescription($this->trans('commands.generate.plugin.migrate.data_parser.description')) | ||
->setHelp($this->trans('commands.generate.plugin.migrate.data_parser.help')) | ||
->addOption( | ||
'module', | ||
null, | ||
InputOption::VALUE_REQUIRED, | ||
$this->trans('commands.common.options.module') | ||
) | ||
->addOption( | ||
'class', | ||
null, | ||
InputOption::VALUE_OPTIONAL, | ||
$this->trans('commands.generate.plugin.migrate.data_parser.options.class') | ||
) | ||
->addOption( | ||
'plugin-id', | ||
null, | ||
InputOption::VALUE_OPTIONAL, | ||
$this->trans('commands.generate.plugin.migrate.data_parser.options.plugin-id') | ||
) | ||
->addOption( | ||
'plugin-title', | ||
null, | ||
InputOption::VALUE_OPTIONAL, | ||
$this->trans('commands.generate.plugin.migrate.data_parser.options.plugin-title') | ||
)->setAliases(['gpmdp']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
// @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation | ||
if (!$this->confirmOperation()) { | ||
return 1; | ||
} | ||
|
||
$module = $input->getOption('module'); | ||
$class_name = $this->validator->validateClassName($input->getOption('class')); | ||
$plugin_id = $input->getOption('plugin-id'); | ||
$plugin_title = $input->getOption('plugin-title'); | ||
|
||
$this->generator->generate([ | ||
'module' => $module, | ||
'class_name' => $class_name, | ||
'plugin_id' => $plugin_id, | ||
'plugin_title' => $plugin_title, | ||
]); | ||
|
||
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
// 'module-name' option. | ||
$module = $this->getModuleOption(); | ||
|
||
// 'class-name' option | ||
$class = $input->getOption('class'); | ||
if (!$class) { | ||
$class = $this->getIo()->ask( | ||
$this->trans('commands.generate.plugin.migrate.data_parser.questions.class'), | ||
ucfirst($this->stringConverter->underscoreToCamelCase($module)), | ||
function ($class) { | ||
return $this->validator->validateClassName($class); | ||
} | ||
); | ||
$input->setOption('class', $class); | ||
} | ||
|
||
// 'plugin-id' option. | ||
$pluginId = $input->getOption('plugin-id'); | ||
if (!$pluginId) { | ||
$pluginId = $this->getIo()->ask( | ||
$this->trans('commands.generate.plugin.migrate.data_parser.questions.plugin-id'), | ||
$this->stringConverter->camelCaseToUnderscore($class) | ||
); | ||
$input->setOption('plugin-id', $pluginId); | ||
} | ||
|
||
// 'plugin-title' option. | ||
$pluginTitle = $input->getOption('plugin-title'); | ||
if (!$pluginTitle) { | ||
$pluginTitle = $this->getIo()->ask( | ||
$this->trans('commands.generate.plugin.migrate.data_parser.questions.plugin-title'), | ||
$this->stringConverter->camelCaseToUnderscore($class) | ||
); | ||
$input->setOption('plugin-title', $pluginTitle); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Console\Generator\PluginMigrateDataParserGenerator. | ||
*/ | ||
|
||
namespace Drupal\Console\Generator; | ||
|
||
use Drupal\Console\Core\Generator\Generator; | ||
use Drupal\Console\Extension\Manager; | ||
|
||
class PluginMigrateDataParserGenerator extends Generator | ||
{ | ||
/** | ||
* @var Manager | ||
*/ | ||
protected $extensionManager; | ||
|
||
/** | ||
* PluginMigrateDataParserGenerator constructor. | ||
* | ||
* @param Manager $extensionManager | ||
*/ | ||
public function __construct( | ||
Manager $extensionManager | ||
) { | ||
$this->extensionManager = $extensionManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function generate(array $parameters) | ||
{ | ||
$module = $parameters['module']; | ||
$class_name = $parameters['class_name']; | ||
|
||
$this->renderFile( | ||
'module/src/Plugin/migrate_plus/data_parser/data_parser.php.twig', | ||
$this->extensionManager->getPluginPath($module, 'migrate_plus') . '/data_parser/' . $class_name . '.php', | ||
$parameters | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
templates/module/src/Plugin/migrate_plus/data_parser/data_parser.php.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{% extends "base/class.php.twig" %} | ||
|
||
{% block file_path %} | ||
\Drupal\{{module}}\Plugin\migrate_plus\data_parser\{{class_name}}. | ||
{% endblock %} | ||
|
||
{% block namespace_class %} | ||
namespace Drupal\{{module}}\Plugin\migrate_plus\data_parser; | ||
{% endblock %} | ||
|
||
{% block use_class %} | ||
use Drupal\migrate_plus\DataParserPluginBase; | ||
{% endblock %} | ||
|
||
{% block class_declaration %} | ||
/** | ||
* Provides a '{{class_name}}' data parser plugin. | ||
* | ||
* @DataParser( | ||
* id = "{{plugin_id}}" | ||
* title = @Translation("{{plugin_title}}") | ||
* ) | ||
*/ | ||
class {{class_name}} extends DataParserPluginBase {% endblock %} | ||
{% block class_methods %} | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function openSourceUrl($url) { | ||
// Plugin logic goes here. | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function fetchNextRow() { | ||
// Plugin logic goes here. | ||
} | ||
{% endblock %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshirohit100 Normally, underscore is not used in command name.
some examples generate:plugin:rulesaction, generate:plugin:rulesaction and etc.
Maybe it would be better to use something like this generate:plugin:migrate:data:parse. So, if we add also data fetcher we will have generate:plugin:migrate:data:fetcher. What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with both generate:plugin:migrate:dataparser or generate:plugin:migrate:data:parse
Lets see what other say
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like
generate:plugin:migrate:dataparser
betterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I have updated the PR