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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
dc222737
Commit
dc222737
authored
Jan 26, 2018
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2817833
by Jo Fitzgerald, ckaotik, svendecabooter: Delay sql map table creation
parent
df209e95
Branches
Branches containing commit
Tags
Tags containing commit
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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+32
-27
32 additions, 27 deletions
core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
+19
-0
19 additions, 0 deletions
core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
with
51 additions
and
27 deletions
core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+
32
−
27
View file @
dc222737
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Drupal\migrate\Plugin\migrate\id_map
;
namespace
Drupal\migrate\Plugin\migrate\id_map
;
use
Drupal\Component\Utility\Unicode
;
use
Drupal\Component\Utility\Unicode
;
use
Drupal\Core\Database\DatabaseException
;
use
Drupal\Core\Field\BaseFieldDefinition
;
use
Drupal\Core\Field\BaseFieldDefinition
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Plugin\PluginBase
;
use
Drupal\Core\Plugin\PluginBase
;
...
@@ -161,6 +162,18 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
...
@@ -161,6 +162,18 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$this
->
migration
=
$migration
;
$this
->
migration
=
$migration
;
$this
->
eventDispatcher
=
$event_dispatcher
;
$this
->
eventDispatcher
=
$event_dispatcher
;
$this
->
message
=
new
MigrateMessage
();
$this
->
message
=
new
MigrateMessage
();
if
(
!
isset
(
$this
->
database
))
{
$this
->
database
=
\Drupal
::
database
();
}
// Default generated table names, limited to 63 characters.
$machine_name
=
str_replace
(
':'
,
'__'
,
$this
->
migration
->
id
());
$prefix_length
=
strlen
(
$this
->
database
->
tablePrefix
());
$this
->
mapTableName
=
'migrate_map_'
.
Unicode
::
strtolower
(
$machine_name
);
$this
->
mapTableName
=
Unicode
::
substr
(
$this
->
mapTableName
,
0
,
63
-
$prefix_length
);
$this
->
messageTableName
=
'migrate_message_'
.
Unicode
::
strtolower
(
$machine_name
);
$this
->
messageTableName
=
Unicode
::
substr
(
$this
->
messageTableName
,
0
,
63
-
$prefix_length
);
}
}
/**
/**
...
@@ -246,7 +259,6 @@ protected function destinationIdFields() {
...
@@ -246,7 +259,6 @@ protected function destinationIdFields() {
* The map table name.
* The map table name.
*/
*/
public
function
mapTableName
()
{
public
function
mapTableName
()
{
$this
->
init
();
return
$this
->
mapTableName
;
return
$this
->
mapTableName
;
}
}
...
@@ -257,7 +269,6 @@ public function mapTableName() {
...
@@ -257,7 +269,6 @@ public function mapTableName() {
* The message table name.
* The message table name.
*/
*/
public
function
messageTableName
()
{
public
function
messageTableName
()
{
$this
->
init
();
return
$this
->
messageTableName
;
return
$this
->
messageTableName
;
}
}
...
@@ -278,9 +289,6 @@ public function getQualifiedMapTableName() {
...
@@ -278,9 +289,6 @@ public function getQualifiedMapTableName() {
* The database connection object.
* The database connection object.
*/
*/
public
function
getDatabase
()
{
public
function
getDatabase
()
{
if
(
!
isset
(
$this
->
database
))
{
$this
->
database
=
\Drupal
::
database
();
}
$this
->
init
();
$this
->
init
();
return
$this
->
database
;
return
$this
->
database
;
}
}
...
@@ -291,13 +299,6 @@ public function getDatabase() {
...
@@ -291,13 +299,6 @@ public function getDatabase() {
protected
function
init
()
{
protected
function
init
()
{
if
(
!
$this
->
initialized
)
{
if
(
!
$this
->
initialized
)
{
$this
->
initialized
=
TRUE
;
$this
->
initialized
=
TRUE
;
// Default generated table names, limited to 63 characters.
$machine_name
=
str_replace
(
':'
,
'__'
,
$this
->
migration
->
id
());
$prefix_length
=
strlen
(
$this
->
getDatabase
()
->
tablePrefix
());
$this
->
mapTableName
=
'migrate_map_'
.
Unicode
::
strtolower
(
$machine_name
);
$this
->
mapTableName
=
Unicode
::
substr
(
$this
->
mapTableName
,
0
,
63
-
$prefix_length
);
$this
->
messageTableName
=
'migrate_message_'
.
Unicode
::
strtolower
(
$machine_name
);
$this
->
messageTableName
=
Unicode
::
substr
(
$this
->
messageTableName
,
0
,
63
-
$prefix_length
);
$this
->
ensureTables
();
$this
->
ensureTables
();
}
}
}
}
...
@@ -696,21 +697,17 @@ public function prepareUpdate() {
...
@@ -696,21 +697,17 @@ public function prepareUpdate() {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
processedCount
()
{
public
function
processedCount
()
{
return
$this
->
getDatabase
()
->
select
(
$this
->
mapTableName
())
return
$this
->
countHelper
(
NULL
,
$this
->
mapTableName
());
->
countQuery
()
->
execute
()
->
fetchField
();
}
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
importedCount
()
{
public
function
importedCount
()
{
return
$this
->
getDatabase
()
->
select
(
$this
->
mapTableName
())
return
$this
->
countHelper
([
->
condition
(
'source_row_status'
,
[
MigrateIdMapInterface
::
STATUS_IMPORTED
,
MigrateIdMapInterface
::
STATUS_NEEDS_UPDATE
],
'IN'
)
MigrateIdMapInterface
::
STATUS_IMPORTED
,
->
countQuery
()
MigrateIdMapInterface
::
STATUS_NEEDS_UPDATE
,
->
execute
()
]);
->
fetchField
();
}
}
/**
/**
...
@@ -737,20 +734,28 @@ public function messageCount() {
...
@@ -737,20 +734,28 @@ public function messageCount() {
/**
/**
* Counts records in a table.
* Counts records in a table.
*
*
* @param int $status
* @param int
|array
$status
*
An integer fo
r the source_row_status column.
*
(optional) Status code(s) to filte
r the source_row_status column.
* @param string $table
* @param string $table
* (optional) The table to work. Defaults to NULL.
* (optional) The table to work. Defaults to NULL.
*
*
* @return int
* @return int
* The number of records.
* The number of records.
*/
*/
protected
function
countHelper
(
$status
,
$table
=
NULL
)
{
protected
function
countHelper
(
$status
=
NULL
,
$table
=
NULL
)
{
$query
=
$this
->
getDatabase
()
->
select
(
$table
?:
$this
->
mapTableName
());
// Use database directly to avoid creating tables.
$query
=
$this
->
database
->
select
(
$table
?:
$this
->
mapTableName
());
if
(
isset
(
$status
))
{
if
(
isset
(
$status
))
{
$query
->
condition
(
'source_row_status'
,
$status
);
$query
->
condition
(
'source_row_status'
,
$status
,
is_array
(
$status
)
?
'IN'
:
'='
);
}
try
{
$count
=
$query
->
countQuery
()
->
execute
()
->
fetchField
();
}
catch
(
DatabaseException
$e
)
{
// The table does not exist, therefore there are no records.
$count
=
0
;
}
}
return
$
query
->
countQuery
()
->
execute
()
->
fetchField
()
;
return
$
count
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
+
19
−
0
View file @
dc222737
...
@@ -1010,4 +1010,23 @@ private function getIdMapContents() {
...
@@ -1010,4 +1010,23 @@ private function getIdMapContents() {
return
$contents
;
return
$contents
;
}
}
public
function
testMapTableCreation
()
{
$id_map
=
$this
->
getIdMap
();
$map_table_name
=
$id_map
->
mapTableName
();
$message_table_name
=
$id_map
->
messageTableName
();
$this
->
assertEquals
(
'migrate_map_sql_idmap_test'
,
$map_table_name
);
$this
->
assertEquals
(
'migrate_message_sql_idmap_test'
,
$message_table_name
);
// Check that tables don't exist.
$this
->
assertFalse
(
$this
->
database
->
schema
()
->
tableExists
(
$map_table_name
));
$this
->
assertFalse
(
$this
->
database
->
schema
()
->
tableExists
(
$message_table_name
));
$id_map
->
getDatabase
();
// Check that tables do exist.
$this
->
assertTrue
(
$this
->
database
->
schema
()
->
tableExists
(
$map_table_name
));
$this
->
assertTrue
(
$this
->
database
->
schema
()
->
tableExists
(
$message_table_name
));
}
}
}
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