Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
This is a problem similar to that in #2859315: SQL error from profile_fields when migrating d6 (or d7) to d8 without Profile module. It was introduced in #2981000: Migrate Drupal 7 comment entity translations data to Drupal 8.
Steps to reproduce
Drupal 7 site without comment
module.
Drupal 8|9 site with comment
module and content_translation
module.
Attempting to load the list of migrations results in the following fatal error:
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal.comment' doesn't exist: SELECT COUNT(*) AS "expression" FROM (SELECT 1 AS "expression" FROM {entity_translation} "et" INNER JOIN {comment} "c" ON c.cid = et.entity_id INNER JOIN {node} "n" ON n.nid = c.nid WHERE ("et"."entity_type" = :db_condition_placeholder_0) AND ("et"."source" <> :db_condition_placeholder_1)) "subquery"; Array ( [:db_condition_placeholder_0] => comment [:db_condition_placeholder_1] => ) in Drupal\migrate\Plugin\migrate\source\SqlBase->doCount() (line 389 of core/modules/migrate/src/Plugin/migrate/source/SqlBase.php).
Drupal\Core\Database\Statement->execute(Array, Array) (Line: 740)
Drupal\Core\Database\Connection->query('SELECT COUNT(*) AS "expression"
FROM
(SELECT 1 AS "expression"
FROM
{entity_translation} "et"
INNER JOIN {comment} "c" ON c.cid = et.entity_id
INNER JOIN {node} "n" ON n.nid = c.nid
WHERE ("et"."entity_type" = :db_condition_placeholder_0) AND ("et"."source" <> :db_condition_placeholder_1)) "subquery"', Array, Array) (Line: 91)
Drupal\Core\Database\Driver\mysql\Connection->query('SELECT COUNT(*) AS "expression"
FROM
(SELECT 1 AS "expression"
FROM
{entity_translation} "et"
INNER JOIN {comment} "c" ON c.cid = et.entity_id
INNER JOIN {node} "n" ON n.nid = c.nid
WHERE ("et"."entity_type" = :db_condition_placeholder_0) AND ("et"."source" <> :db_condition_placeholder_1)) "subquery"', Array, Array) (Line: 510)
Drupal\Core\Database\Query\Select->execute() (Line: 389)
Proposed resolution
Add CommentEntityTranslation::checkRequirements()
similar to #2859315: SQL error from profile_fields when migrating d6 (or d7) to d8 without Profile module.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
None.
Comment | File | Size | Author |
---|---|---|---|
#22 | 3178966-22.patch | 2.92 KB | quietone |
#22 | interdiff-20-22.txt | 824 bytes | quietone |
#21 | 3178966-21.patch | 2.92 KB | quietone |
#21 | interdiff-20-21.txt | 847 bytes | quietone |
#20 | 3178966-20.patch | 2.94 KB | quietone |
Comments
Comment #2
Wim LeersBetter title.
Comment #3
Wim LeersComment #4
Wim LeersI wonder if this will be noticed faster in the
component 🤔Comment #5
quietone CreditAttribution: quietone as a volunteer commented@Wim Leers, yes it will. :-)
Comment #6
quietone CreditAttribution: quietone as a volunteer commentedI really prefer having the query method as the first method in a source plugin, can we move this to the bottom of the source plugin?
If we are going to report that comment is not installed then we should check if it is installed, not just for the presence of the comment table.
if (!$this->moduleExists('comment'))
{As always, this needs a test.
Comment #7
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedAddressed #6.1 and #6.2 of comment #6, still need works for tests.
Comment #8
quietone CreditAttribution: quietone as a volunteer commentedAdding test.
Comment #10
huzookaI've found only one minor thing:
C/P leftover
Comment #11
quietone CreditAttribution: quietone as a volunteer commentedOops. This should fix the comment.
Comment #12
huzookaThis is RTBC when the test passes (it will pass). I see no conflicts with core 9.2.x.
Comment #14
quietone CreditAttribution: quietone as a volunteer commentedSetting to RTBC based on the comment in #12.
Comment #15
huzookaBased on the query of this plugin (line #31 and #33), this source plugin also requires the
node
module. Same situation as in #3176394: Do not migrate comment related configurations if "comment" wasn't enabled on the source site. (This is because Drupal core only migrates node comments.)So we require three source module:
entity_translation
- reflected in the annotationcomment
–this will be added nownode
– this is missing.Comment #16
huzookaTest(s?) still need(s) to be updated.
Comment #17
Wim Leers#6.2: this thoroughly confused me for a moment — IMHO it's a huge DX problem that the method
moduleExists()
checks the source site, not the destination site.sourceModuleExists()
ormoduleExistsInSource()
would've been 10x clearer!This is very close now! 🥳
Comment #18
quietone CreditAttribution: quietone as a volunteer commented@Wim Leers, yes, I agree.
Re #15. \Drupal\comment\Plugin\migrate\source\d7\Comment::query does use the node module but that code won't be reached in the test, the checkRequirements will run first. The only modules that need to be installed are those that are needed to create an instance of 'd7_comment_entity_translation' and it's dependent migrations.
Edit: refer to #15
Comment #20
quietone CreditAttribution: quietone as a volunteer commentedAdding a test for when the node module is not enabled.
Comment #21
quietone CreditAttribution: quietone as a volunteer commentedSmall improvement to remove a local variable.
Comment #22
quietone CreditAttribution: quietone as a volunteer commentedThe patch in #21 can be ignored.
Forgot to update the comment.
Comment #23
Wim LeersÜbernit after the rework done since #15 (which also should've updated the issue title — did that just now).
s/comment/the given/
Note that this should also be committed to
9.1.x
, so queued a test against that too.Re-RTBC'ing given the earlier RTBC, plus the fact that the current patch looks almost nothing like my original patch anymore :)
Comment #26
larowlanCommitted 08350ae and pushed to 9.2.x. Thanks!
Fixed on commit per #23
Backported to 9.1.x because this is a major bug and the risk of disruption is low.
Tagging Bug Smash Initiative because I'm checking over RTBC bugs as part of the initiative.