Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
M
migrate_devel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
migrate_devel
Commits
cbeff372
Commit
cbeff372
authored
Mar 01, 2017
by
Derimagia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert config on import
parent
4b36b845
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
README.md
README.md
+6
-0
migrate_devel.drush.inc
migrate_devel.drush.inc
+96
-0
No files found.
README.md
View file @
cbeff372
...
...
@@ -14,4 +14,10 @@ cli coloring and named variable debugging.
Options are:
*
`--migrate-debug`
- Prints out rows as they run.
Can be used in
`migrate-import`
or
`migrate-status`
and will revert
existing migrations to the default and clear the cache for them.
This requires
[
config_update
](
https://www.drupal.org/project/config_update
)
if you use
[
migrate_plus
](
https://www.drupal.org/project/migrate_plus
)
because migrations go into config.
*
`--migrate-debug-pre`
- Same as above before the process is run on the row.
Can be used in
`migrate-import`
.
migrate_devel.drush.inc
View file @
cbeff372
...
...
@@ -4,6 +4,12 @@
* @file
* File for Drush Integration.
*/
use
Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface
;
use
Drupal\config_update
\
ConfigListInterface
;
use
Drupal\config_update
\
ConfigRevertInterface
;
use
Drupal\Core\Config\StorageInterface
;
use
Drupal\migrate_plus
\
Plugin\Discovery\ConfigEntityDiscovery
;
use
Drush\Log\LogLevel
;
/**
* Implements hook_drush_help_alter().
...
...
@@ -13,4 +19,94 @@ function migrate_devel_drush_help_alter(&$command) {
$command
[
'options'
][
'migrate-debug'
]
=
'Enable Debug Mode'
;
$command
[
'options'
][
'migrate-debug-pre'
]
=
'Enable Debug Mode (Before Row Save)'
;
}
if
(
$command
[
'command'
]
==
'migrate-status'
)
{
$command
[
'options'
][
'migrate-debug'
]
=
'Enable Debug Mode'
;
}
}
/**
* Implements hook_drush_command_alter().
*/
function
migrate_devel_drush_command_alter
(
&
$command
)
{
$cmd
=
$command
[
'command'
];
if
(
$cmd
==
'migrate-import'
||
$cmd
==
'migrate-status'
)
{
// Reset all migrations
if
(
drush_get_option
(
'migrate-debug'
))
{
migrate_devel_rebuild_migrations
();
}
}
}
/**
* Clears cache for migrations and reverts config of migrations if needed.
*/
function
migrate_devel_rebuild_migrations
()
{
/* @var $discovery CachedDiscoveryInterface */
if
(
\
Drupal
::
moduleHandler
()
->
moduleExists
(
'migrate_plus'
))
{
$discovery
=
\
Drupal
::
service
(
'plugin.manager.config_entity_migration'
);
migrate_devel_revert_migrate_config
();
}
else
{
$discovery
=
\
Drupal
::
service
(
'plugin.manager.migration'
);
}
// Reset cached migrations
$discovery
->
clearCachedDefinitions
();
drush_log
(
dt
(
'Reset Cached Migrations'
),
LogLevel
::
DEBUG
);
}
/**
* Reverts migrate config for migrate_plus
*/
function
migrate_devel_revert_migrate_config
()
{
// If migrate_plus and config_update exists, revert the config.
if
(
\
Drupal
::
moduleHandler
()
->
moduleExists
(
'config_update'
))
{
/* @var $config_revert ConfigRevertInterface */
$config_revert
=
\
Drupal
::
service
(
'config_update.config_update'
);
$migration_discovery
=
new
ConfigEntityDiscovery
(
'migration'
);
foreach
(
$migration_discovery
->
getDefinitions
()
as
$definition
)
{
$config_revert
->
revert
(
'migration'
,
$definition
[
'id'
]);
}
drush_log
(
dt
(
'Reverted Existing Migration Configs'
));
// Revert missing config
migrate_devel_revert_missing_config
(
'migration'
);
}
else
{
drush_log
(
dt
(
'Missing config_update for revert.'
));
}
}
/**
* Reverts missing config for a specific config type.
*
* @param string $type
*/
function
migrate_devel_revert_missing_config
(
$type
)
{
/* @var ConfigRevertInterface $config_revert */
$config_revert
=
\
Drupal
::
service
(
'config_update.config_update'
);
// Now we need to add any new migrations.
/* @var ConfigListInterface $config_lister */
$config_lister
=
\
Drupal
::
service
(
'config_update.config_list'
);
// Add any new migrations we need to.
list
(
$active_list
,
$install_list
,
$optional_list
)
=
$config_lister
->
listConfig
(
'type'
,
$type
);
$missing
=
array_diff
(
$install_list
,
$active_list
);
/* @var StorageInterface $config_reader */
$config_reader
=
\
Drupal
::
service
(
'config_update.extension_storage'
);
foreach
(
$missing
as
$name
)
{
$config
=
$config_reader
->
read
(
$name
);
$config_type
=
$config_lister
->
getTypeNameByConfigName
(
$name
);
$definition
=
$config_lister
->
getType
(
$config_type
);
$id_key
=
$definition
->
getKey
(
'id'
);
if
(
$config_revert
->
import
(
$config_type
,
$config
[
$id_key
]))
{
drush_log
(
dt
(
'Imported @config'
,
[
'@config'
=>
$name
]),
LogLevel
::
ALERT
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment