Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
M
migrate_upgrade
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Drupal.org issue queue
Drupal.org issue queue
Security & Compliance
Security & Compliance
Dependency List
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
project
migrate_upgrade
Commits
f001e563
Commit
f001e563
authored
Jan 07, 2019
by
heddn
Committed by
heddn
Jan 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3023504
by heddn: Add test coverage for drush config export
parent
c92c89e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
212 additions
and
10 deletions
+212
-10
src/MigrateUpgradeDrushRunner.php
src/MigrateUpgradeDrushRunner.php
+24
-10
tests/src/Kernel/DrushTest.php
tests/src/Kernel/DrushTest.php
+188
-0
No files found.
src/MigrateUpgradeDrushRunner.php
View file @
f001e563
...
...
@@ -113,6 +113,14 @@ class MigrateUpgradeDrushRunner {
'migration-prefix'
=>
drush_get_option
(
'migration-prefix'
,
'upgrade_'
),
];
}
$this
->
options
=
array_merge
([
'legacy-db-key'
=>
''
,
'legacy-db-url'
=>
''
,
'legacy-db-prefix'
=>
''
,
'legacy-root'
=>
''
,
'debug'
=>
''
,
'migration-prefix'
=>
'upgrade_'
,
],
$this
->
options
);
}
/**
...
...
@@ -124,8 +132,6 @@ class MigrateUpgradeDrushRunner {
*/
public
function
configure
()
{
$legacy_db_key
=
$this
->
options
[
'legacy-db-key'
];
$db_url
=
$this
->
options
[
'legacy-db-url'
];
$db_prefix
=
$this
->
options
[
'legacy-db-prefix'
];
if
(
!
empty
(
$legacy_db_key
))
{
$connection
=
Database
::
getConnection
(
'default'
,
$legacy_db_key
);
$this
->
version
=
$this
->
getLegacyDrupalVersion
(
$connection
);
...
...
@@ -135,6 +141,8 @@ class MigrateUpgradeDrushRunner {
\Drupal
::
state
()
->
set
(
'migrate.fallback_state_key'
,
$database_state_key
);
}
else
{
$db_url
=
$this
->
options
[
'legacy-db-url'
];
$db_prefix
=
$this
->
options
[
'legacy-db-prefix'
];
// Maintain some simple BC with Drush 8. Only call Drush 9 if it exists.
// Otherwise fallback to the legacy Drush 8 method.
if
(
method_exists
(
SqlBase
::
class
,
'dbSpecFromDBUrl'
))
{
...
...
@@ -234,8 +242,9 @@ class MigrateUpgradeDrushRunner {
$process
=
$migration
->
getProcess
();
foreach
(
$process
as
$destination
=>
&
$plugins
)
{
foreach
(
$plugins
as
&
$plugin
)
{
if
(
$plugin
[
'plugin'
]
==
'd6_field_file'
)
{
$plugin
[
'migration'
]
=
$this
->
modifyId
(
$plugin
[
'migration'
]);
if
(
$plugin
[
'plugin'
]
===
'd6_field_file'
)
{
$file_migration
=
isset
(
$plugin
[
'migration'
])
?
$plugin
[
'migration'
]
:
'd6_file'
;
$plugin
[
'migration'
]
=
$this
->
modifyId
(
$file_migration
);
}
}
}
...
...
@@ -302,15 +311,20 @@ class MigrateUpgradeDrushRunner {
drush_print
(
dt
(
'Exporting @migration as @new_migration'
,
[
'@migration'
=>
$migration_id
,
'@new_migration'
=>
$this
->
modifyId
(
$migration_id
)]));
$migration_details
[
'id'
]
=
$migration_id
;
$migration_details
[
'class'
]
=
$migration
->
get
(
'class'
);
$migration_details
[
'cck_plugin_method'
]
=
$migration
->
get
(
'cck_plugin_method'
);
$migration_details
[
'field_plugin_method'
]
=
$migration
->
get
(
'field_plugin_method'
);
$migration_details
[
'label'
]
=
$migration
->
label
();
$plugin_definition
=
$migration
->
getPluginDefinition
();
$migration_details
[
'class'
]
=
$plugin_definition
[
'class'
];
if
(
isset
(
$plugin_definition
[
'field_plugin_method'
]))
{
$migration_details
[
'field_plugin_method'
]
=
$plugin_definition
[
'field_plugin_method'
];
}
if
(
isset
(
$plugin_definition
[
'cck_plugin_method'
]))
{
$migration_details
[
'cck_plugin_method'
]
=
$plugin_definition
[
'cck_plugin_method'
];
}
$migration_details
[
'migration_group'
]
=
$this
->
databaseStateKey
;
$migration_details
[
'migration_tags'
]
=
$migration
->
get
(
'migration_tags'
);
$migration_details
[
'label'
]
=
$migration
->
get
(
'label'
);
$migration_details
[
'migration_tags'
]
=
isset
(
$plugin_definition
[
'migration_tags'
])
?
$plugin_definition
[
'migration_tags'
]
:
[];
$migration_details
[
'source'
]
=
$migration
->
getSourceConfiguration
();
$migration_details
[
'destination'
]
=
$migration
->
getDestinationConfiguration
();
$migration_details
[
'process'
]
=
$migration
->
get
(
'process'
);
$migration_details
[
'process'
]
=
$migration
->
get
Process
(
);
$migration_details
[
'migration_dependencies'
]
=
$migration
->
getMigrationDependencies
();
$migration_details
=
$this
->
substituteIds
(
$migration_details
);
$migration_entity
=
Migration
::
load
(
$migration_details
[
'id'
]);
...
...
tests/src/Kernel/DrushTest.php
0 → 100644
View file @
f001e563
<?php
namespace
Drupal\Tests\migrate_upgrade\Kernel
{
use
Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait
;
use
Drupal\migrate_plus\Entity\Migration
;
use
Drupal\migrate_upgrade\Commands\MigrateUpgradeCommands
;
use
Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase
;
use
Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait
;
/**
* Tests the drush command runner for migrate upgrade.
*
* @group migrate_upgrade
*
* @requires module migrate_plus
*/
class
DrushTest
extends
MigrateDrupalTestBase
{
use
FileSystemModuleDiscoveryDataProviderTrait
;
use
CreateMigrationsTrait
;
/**
* The migration plugin manager.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManager
*/
protected
$migrationManager
;
/**
* The Migrate Upgrade Command drush service.
*
* @var \Drupal\migrate_upgrade\Commands\MigrateUpgradeCommands
*/
protected
$commands
;
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected
$state
;
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
// Enable all modules.
self
::
$modules
=
array_merge
(
array_keys
(
$this
->
coreModuleListDataProvider
()),
[
'migrate_plus'
,
'migrate_upgrade'
,
]);
parent
::
setUp
();
$this
->
installSchema
(
'system'
,
[
'key_value'
,
'key_value_expire'
]);
$this
->
installConfig
(
self
::
$modules
);
$this
->
installEntitySchema
(
'migration_group'
);
$this
->
installEntitySchema
(
'migration'
);
$this
->
migrationManager
=
\Drupal
::
service
(
'plugin.manager.migration'
);
$this
->
state
=
$this
->
container
->
get
(
'state'
);
$this
->
commands
=
new
MigrateUpgradeCommands
(
$this
->
state
);
}
/**
* Tests that all D6 migrations are generated as migrate plus entities.
*/
public
function
testD6Migrations
()
{
$skipped_migrations
=
[
'upgrade_d6_entity_reference_translation_comment__comment_forum'
,
];
$migrations
=
$this
->
drupal6Migrations
();
$options
=
[
'configure-only'
=>
TRUE
,
'legacy-db-key'
=>
$this
->
sourceDatabase
->
getKey
(),
];
$this
->
commands
->
upgrade
(
$options
);
$migrate_plus_migrations
=
Migration
::
loadMultiple
();
$this
->
assertMigrations
(
$migrations
,
$migrate_plus_migrations
,
$skipped_migrations
);
$optional
=
array_flip
(
$migrate_plus_migrations
[
'upgrade_d6_url_alias'
]
->
toArray
()[
'migration_dependencies'
][
'optional'
]);
$this
->
assertArrayHasKey
(
'upgrade_d6_node_translation_page'
,
$optional
);
}
/**
* Tests that all D7 migrations are generated as migrate plus entities.
*/
public
function
testD7Migrations
()
{
$skipped_migrations
=
[
'upgrade_d7_entity_reference_translation_comment__comment_forum'
,
];
$migrations
=
$this
->
drupal7Migrations
();
$this
->
sourceDatabase
->
update
(
'system'
)
->
fields
([
'status'
=>
1
])
->
condition
(
'name'
,
'profile'
)
->
execute
();
$options
=
[
'configure-only'
=>
TRUE
,
'legacy-db-key'
=>
$this
->
sourceDatabase
->
getKey
(),
];
$this
->
commands
->
upgrade
(
$options
);
$migrate_plus_migrations
=
Migration
::
loadMultiple
();
$this
->
assertMigrations
(
$migrations
,
$migrate_plus_migrations
,
$skipped_migrations
);
$optional
=
array_flip
(
$migrate_plus_migrations
[
'upgrade_d7_url_alias'
]
->
toArray
()[
'migration_dependencies'
][
'optional'
]);
$this
->
assertArrayHasKey
(
'upgrade_d7_node_translation_page'
,
$optional
);
}
/**
* Asserts that all migrations are exported as migrate plus entities.
*
* @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations
* The migrations.
* @param \Drupal\migrate_plus\Entity\MigrationInterface[] $migrate_plus_migrations
* The migrate plus config entities.
* @param array $skipped_migrations
* The migrations to skip.
*/
protected
function
assertMigrations
(
array
$migrations
,
array
$migrate_plus_migrations
,
array
$skipped_migrations
)
{
foreach
(
$migrations
as
$id
=>
$migration
)
{
$migration_id
=
'upgrade_'
.
str_replace
(
':'
,
'_'
,
$migration
->
id
());
if
(
in_array
(
$migration_id
,
$skipped_migrations
,
TRUE
))
{
continue
;
}
$this
->
assertArrayHasKey
(
$migration_id
,
$migrate_plus_migrations
);
}
}
}
}
namespace
{
if
(
!
function_exists
(
'drush_print'
))
{
/**
* Stub for drush_print.
*
* @param string $message
* The message to print.
* @param int $indent
* The indentation (space chars)
* @param resource $handle
* File handle to write to. NULL will write to standard output, STDERR
* will write to the standard error. See
* http://php.net/manual/en/features.commandline.io-streams.php.
* @param bool $newline
* Add a "\n" to the end of the output. Defaults to TRUE.
*/
function
drush_print
(
$message
=
''
,
$indent
=
0
,
$handle
=
NULL
,
$newline
=
TRUE
)
{
// Do nothing.
}
}
if
(
!
function_exists
(
'dt'
))
{
/**
* Stub for dt().
*
* @param string $message
* The text.
* @param array $replace
* The replacement values.
*
* @return string
* The text.
*/
function
dt
(
$message
,
array
$replace
=
[])
{
return
strtr
(
$message
,
$replace
);
}
}
if
(
!
function_exists
(
'drush_op'
))
{
/**
* Stub for drush_op.
*
* @param callable $callable
* The function to call.
*/
function
drush_op
(
callable
$callable
)
{
$args
=
func_get_args
();
array_shift
(
$args
);
call_user_func_array
(
$callable
,
$args
);
}
}
}
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