Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
d394fef4
Commit
d394fef4
authored
10 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2404397
by mikeryan: Support injection of database configuration in SqlBase
parent
37c5acf1
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
+18
-10
18 additions, 10 deletions
core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
core/modules/migrate/src/Tests/SqlBaseTest.php
+24
-2
24 additions, 2 deletions
core/modules/migrate/src/Tests/SqlBaseTest.php
with
42 additions
and
12 deletions
core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
+
18
−
10
View file @
d394fef4
...
...
@@ -15,14 +15,11 @@
/**
* Sources whose data may be fetched via DBTNG.
*
* You can specify a 'target' configuration key to specify the database target
* to use for a specific migration source. You can specify an additional
* database target in settings.php. For example:
* @code
* $databases['migrate']['other_database'] = [ ... ];
* @endcode
* Given that you can specify 'target: other_database' in the 'source' part of
* a migration configuration entity.
* By default, an existing database connection with key 'migrate' and target
* 'default' is used. These may be overridden with explicit 'key' and/or
* 'target' configuration keys. In addition, if the configuration key 'database'
* is present, it is used as a database connection information array to define
* the connection.
*/
abstract
class
SqlBase
extends
SourcePluginBase
{
...
...
@@ -66,11 +63,22 @@ public function __toString() {
*/
public
function
getDatabase
()
{
if
(
!
isset
(
$this
->
database
))
{
$target
=
'default'
;
if
(
isset
(
$this
->
configuration
[
'target'
]))
{
$target
=
$this
->
configuration
[
'target'
];
}
$this
->
database
=
Database
::
getConnection
(
$target
,
'migrate'
);
else
{
$target
=
'default'
;
}
if
(
isset
(
$this
->
configuration
[
'key'
]))
{
$key
=
$this
->
configuration
[
'key'
];
}
else
{
$key
=
'migrate'
;
}
if
(
isset
(
$this
->
configuration
[
'database'
]))
{
Database
::
addConnectionInfo
(
$key
,
$target
,
$this
->
configuration
[
'database'
]);
}
$this
->
database
=
Database
::
getConnection
(
$target
,
$key
);
}
return
$this
->
database
;
}
...
...
This diff is collapsed.
Click to expand it.
core/modules/migrate/src/Tests/SqlBaseTest.php
+
24
−
2
View file @
d394fef4
...
...
@@ -22,14 +22,36 @@ class SqlBaseTest extends MigrateTestBase {
*/
public
function
testConnectionTypes
()
{
$sql_base
=
new
TestSqlBase
();
// Check the default values.
$this
->
assertIdentical
(
$sql_base
->
getDatabase
()
->
getTarget
(),
'default'
);
$this
->
assertIdentical
(
$sql_base
->
getDatabase
()
->
getKey
(),
'migrate'
);
$target
=
'test_db_target'
;
$config
=
array
(
'target'
=>
$target
);
$key
=
'test_migrate_connection'
;
$config
=
array
(
'target'
=>
$target
,
'key'
=>
$key
);
$sql_base
->
setConfiguration
(
$config
);
Database
::
addConnectionInfo
(
'migrate'
,
$target
,
Database
::
getConnectionInfo
(
'default'
)[
'default'
]);
Database
::
addConnectionInfo
(
$key
,
$target
,
Database
::
getConnectionInfo
(
'default'
)[
'default'
]);
// Validate we've injected our custom key and target.
$this
->
assertIdentical
(
$sql_base
->
getDatabase
()
->
getTarget
(),
$target
);
$this
->
assertIdentical
(
$sql_base
->
getDatabase
()
->
getKey
(),
$key
);
// Now test we can have SqlBase create the connection from an info array.
$sql_base
=
new
TestSqlBase
();
$target
=
'test_db_target2'
;
$key
=
'test_migrate_connection2'
;
$database
=
Database
::
getConnectionInfo
(
'default'
)[
'default'
];
$config
=
array
(
'target'
=>
$target
,
'key'
=>
$key
,
'database'
=>
$database
);
$sql_base
->
setConfiguration
(
$config
);
// Call getDatabase() to get the connection defined.
$sql_base
->
getDatabase
();
// Validate the connection has been created with the right values.
$this
->
assertIdentical
(
Database
::
getConnectionInfo
(
$key
)[
$target
],
$database
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment