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
We need an upgrade path for the Drupal 7 Image module.
Remaining Tasks
Write a migration (with tests) for image styles. These are configuration entities in Drupal 8. Any variables maintained by the image module will also need to be moved into configuration.
Image files and fields do not need to be migrated in this issue -- they're being handled elsewhere: #2416765: Migrate Drupal 7 Field/Instance/View mode settings
Comments
Comment #1
svendecabooterComment #2
svendecabooterAttached is a patch to migrate the image styles from D7 to D8.
Still needs tests and unit tests.
Comment #3
lostkangaroo CreditAttribution: lostkangaroo at APQC commentedIt would be beneficial to add a source_provider annotation to make sure this module exists as a source.
Comment #4
phenaproximaFound a few thangs...
Let's lose the machine_name and dedupe_entity plugins here -- we want to merge with existing styles by machine name, so this can just be a direct mapping (
name: name
).As @lostkangaroo said, please do add
source_provider = "image"
.'ims' is a strange alias for the table. Can it just be 'is'?
Need a space between foreach and the opening parenthesis.
'name' should not be changed to 'id'. The source plugins should stay as close as possible to the original data.
Why not simply inline the call to unserialize()?
'data' => unserialize($result['data'])
Comment #5
phenaproximaOh, and. :)
Comment #6
svendecabooterComment #7
svendecabooterAttached a new version of the patch, with tests added.
Some comments to the feedback of phenaproxima:
#3: I used alias "is" first, but that gave SQL errors when testing. After banging my head for a while, I realised "IS" is a reserved SQL keyword, making the queries crash. So I used alias "ims" instead.
#5: The plugin won't import the image style effects with key 'name' instead of 'id'. How would I go about fixing that then?
Comment #10
phenaproximaYou will need to change it in the process pipeline, within the migration entity itself.
This should be:
Other, minor things -- once these are fixed and DrupalCI approves, it's RTBC from me.
Please change this to {@inheritdoc} -- we're going to do that in another issue for all existing tests, so best to make it consistent here :)
The nit to end all nits: s/a/an
Missing documentation for the other parameters.
$expected_effect_config should have the array type hint.
Comment #11
phenaproximaDerp.
Comment #12
svendecabooterWith regards to the "id" vs "name" issue:
I can't change this in the process yml declaration, because that's for migrating the image styles, while the "id" issue is about the underlying image effect plugins (the "effects" process pipeline in d7_image_styles.yml).
So i'm not sure what the best way is to migrate to D8 plugins that within themselves reference other existing plugins.
Comment #13
svendecabooterAlso, I can't figure out why the PHPUnit test won't run. It looks exactly like other PHPUnit tests I wrote for migrate issues, so not sure what's going on. Probably something stupid I forgot, but it would be nice to have another pair of eyes on that...
Comment #14
svendecabooterAttached a new version with the minor issues fixed.
Comment #15
phenaproximaThe iterator process plugin might be the answer to this. https://www.drupal.org/node/2135345
Comment #16
MattA CreditAttribution: MattA commentedComment #19
svendecabooterHere's an updated version of the patch that uses the iterator process.
Only thing I can't figure out is why the PHPUnit test doesn't run properly. Checked with some guys here at Drupalcon, but no luck.
Comment #20
phenaproximaThis can just be
$effects[$key]['data'] = unserialize($result['data']
. No need to copy the name and weight verbatim.$expected_size is missing :) It might not even be necessary, since $expected_effect_plugins is being passed in anyway...?
Can you elaborate on this?
Comment #21
svendecabooter#1: Wouldn't it be more complete to migrate the weight of an image effect within an image style as well? I see no reason to leave that out, as it might changes the image style upon migration if left out I think.
#2: reworked this bit in the updated patch
#3: See the failed test results: https://qa.drupal.org/pifr/test/1159943 (PHPunit Test failed to complete, line 0) - it seems the (inherited) assertions in my Unit test don't get run or detected for some unknown reason.
Comment #22
svendecabooterOr for #1, do you mean I just unserialize $results[$key]['data'], and return that variable, instead of $effects? In that case there would be more stuff in the resulting array, rather than just name, weight & data, which seem to be the only useful fields as far as I know. Hence my approach.
Comment #23
phenaproximaFor #1, I mean this:
It's OK to include more stuff than just name, weight, and data. Generally I think source plugins should err on the side of returning as much data as is available and allow the migration to decide what, if anything, to do with it.
I'm not sure why the PHPUnit test is failing. Does it produce any warnings or fatals locally?
Comment #24
svendecabooterOK I see now. Will update the code.
As for the PHPUnit test - I'm having the same issue with another patch as well.
I get the error "No test results to display." when I run the test via the Testing module UI.
If I set some breakpoints in the class, it seems to find the class, but not the setUp() or testXXX() methods.
Structure of the classes is the same as found in other migrate Unit tests in D8 core, so I'm kind of baffled why it doesn't work.
Comment #25
svendecabooterFinally found out why I get "No test results to display." errors.
I was getting PHP errors in sites/default/files/simpletest/phpunit-xxx.xml. My debugger doesn't work on PHPUnit tests for some reason...
Would be cool if the testbot dumped out those PHP errors upon testing as well. Would have saved me tons of time :)
Anyway, I was missing some logic in the setUp function of the Unit test, which is now added.
Comment #26
phenaproximaWe should probably mention effects here, but I think that can be fixed on commit. Many existing source plugins do not return accurate field info.
Fantastic job, @svendecabooter!
Comment #29
webchickCommitted and pushed to 8.0.x. Thanks!