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.
In #2121299: Migrate in Core: Drupal 6 to Drupal 8 (the web tests) we introduced a mechanic where you pass file paths to a prepare() method, to specify the dumps to load.
Imo this is not the most elegant way to do this.
Some proposed refactoring:
- Pass around objects instead of file paths. The IDE will love us back with type checking and refactoring options.
- More meaningful method names: loadDrupal6Dump() instead of prepare().
- Composition and method arguments over inheritance:
Currently every Dump class inherits from a base class, which receives the database in the constructor.
I propose to instead pass the database (or rather, a database wrapper with additional methods) to the load() method, and let the Dump classes only implement an interface. - The Drupal6DbWrapper also gives us a dedicated place for the "migrateTables" array that prevents tables from being created twice.
- Clarify what is for Drupal in general and what is for Drupal 6 only.
Patch will clarify.
Comment | File | Size | Author |
---|---|---|---|
#9 | D8-2254157-9-migrate_drupal--noVariableSet.patch | 218.62 KB | donquixote |
#9 | D8-2254157-9-migrate_drupal--squashed.patch | 239.21 KB | donquixote |
#9 | D8-2254157-9-migrate_drupal--history.patch | 349.34 KB | donquixote |
Comments
Comment #1
donquixote CreditAttribution: donquixote commentedLocal testing showed a hickup in
MigrateCommentVariableInstance
, but let's see what testbot says.Comment #2
sunCould we...
1) rename the argument to
$database
?2) rename
getDbConnection()
togetConnection()
?It's also a bit weird that
insert()
is located on a connection, butcreateTable()
is not...?Normally, it's Database::getConnection()->schema()->createTable()
i.e.,
createTable()
lives onschema()
, and bothschema()
+insert()
lives on a$connection
.Comment #3
donquixote CreditAttribution: donquixote commentedThis could be misleading. What does $database mean these days? A db connection? Or something else?
Unlike schema()->createTable(), our wrapper method createTable() does not complain if the same table is added twice.
Maybe it should be renamed createTableOnce(), similar to include_once.
I did not invent this, it is from Drupal6DumpBase::createTable().
We could simply add one or two more shortcut methods on the wrapper, since most of the time it is just insert().
(and sometimes merge())
Comment #4
donquixote CreditAttribution: donquixote commentedIn fact, a lot of it is insert('variable'), which could be short-cutted to $dbWrapper->variableSet($key, $value) or $dbWrapper->variableSetMultiple(array($key => $value)).
Comment #5
dawehnerI do agree with some that getDbConnection is kinda off, given that drupal is really written with the database in mind at the moment.
Let's please adapt the documentation, given how often this class is used ...
We could also just go with ensureTable
I wonder whether we could split the refactoring into smaller pieces. For example the introduction of MigrateDrupal6TestBase does not seem to be required for the other bit
Comment #6
donquixote CreditAttribution: donquixote commentedI am fine with getConnection() then..
Yes.
This leads to the question whether we still want a want a wrapper, or rather pass around the db connection itself.
This would give us one big but repetitive part, and one smaller part. I am ok with it.
On a more general level, we can wonder if anyone has "bigger plans" for this system.
The change I suggested here is something that seems reasonable without looking too much at the details.
Comment #7
donquixote CreditAttribution: donquixote commentedThe only reason of existence for this class is
- to create and hold an instance of the Drupal6DbWrapper.
- to pass the Drupal6DbWrapper instance around to dump objects.
- to provide methods loadDrupal6Dump() and loadDrupal6Dumps() to load the dumps using the Drupal6DbWrapper.
So, creating an empty MigrateDrupal6TestBase as a separate commit, without any Drupal6DbWrapper, seems a bit pointless..
Comment #8
donquixote CreditAttribution: donquixote commentedI am tempted to introduce variableSet() and variableSetMultiple() on the db wrapper class.
I already started to replace some of the insert('variable') queries with these shortcuts, and it looks great.
However, now this makes me think: Maybe these dumps were actually auto-generated in some way? In this case, the variableSet() would actually make our life more difficult instead of easier.
Comment #9
donquixote CreditAttribution: donquixote commentedSome renames and comment improvements since #1, as suggested by sun and dawehner.
Not changed:
(but I am still sceptical about naming it $database, since this is often used for a db connection.)
Preview, but probably better off in a follow-up:
The latter shows that variableSet() and variableSetMultiple() can make the Dump classes easier to read.
On the other hand, they become harder to create with the core/scripts/generate-d6-content.sh script.
So I'd say do this in a follow-up, which may include some changes to this script. Or even a different version of the script.
EDIT:
The last two commits introduce the variableSet() stuff, and use it to replace some of the insert('variable') queries. It does not replace all those queries, it is rather meant as a preview.
Comment #10
mikeryanNearly a year later - definitely some major rerolling necessary.
Comment #11
mikeryanA lot of water under the bridge since this was opened - plenty of changes to dumps made over that time, and a major refactoring is on the way at #2550291: Improve and generalize database dump tools, we expect that issue should address all remaining concerns (feel free to weigh in over there if you spot any holes).
@donquixote: Sorry we never got back to your patch when it would have helped.