Problem/Motivation

Currently, image fields on a D7 upgrade don't actually get linked to their respective image files (although the images themselves are indeed migrate and in the file table).

Proposed resolution

Add a CckFieldPlugin for image fields to customize the process config for image fields and use the iterator plugin to map the D7 fid, alt, title, width, and height sub-fields to their d8 equivalents. Attached patch does just that.

Remaining tasks

Patch Review
Write Tests

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drclaw created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, migrate-d7_image_fields-0.patch, failed testing.

The last submitted patch, migrate-d7_image_fields-0.patch, failed testing.

skyredwang’s picture

Just tested this patch, and tried 7.39->8.0.0-rc3 upgrade. Still don't see image field values being saved in the new d8 site.

drclaw’s picture

Version: 8.0.x-dev » 8.0.0-rc3
FileSize
1.17 KB

Oh yeah, they changed the Annotation for CckFieldPlugins in 8.0.0-rc3. Here's an updated patch! (I also updated the version of the patch on the issue)

drclaw’s picture

Also, I should mention that you need to re-run your upgrade in order for this patch to work. Under the hood, all it does is properly set the process plugin for your image field during the upgrade process. So, if you've already upgraded, the configuration is already entered into the database incorrectly.

You can manually fix any image field migrations, however, by updating the migration configuration. For example, if you had a D7 node type called Blog Post, you would go to the Single Item configuration Export page (admin/config/development/configuration/single/export) and select "Migration" for your Configuration Type and "Nodes (Blog Post)" for your Configuration Name. Then copy the configuration and edit it in a text editor. In the process section of the configuration, locate your image field name. It may look something like this

process:
  field_image_field: field_image_field

And replace it with:

process:
  field_image_field:
    plugin: iterator
    source: field_image_field
    process:
      target_id: fid
      alt: alt
      title: title
      width: width
      height: height

Be sure to replace any occurances of field_image_field value with your image field name.

skyredwang’s picture

Version: 8.0.0-rc3 » 8.0.x-dev
Status: Needs work » Needs review

I just tested patch in #5 with a "fresh" migrate, and it works well.

Status: Needs review » Needs work

The last submitted patch, 5: migrate-d7_image_fields-5.patch, failed testing.

skyredwang’s picture

Status: Needs work » Needs review
FileSize
1.2 KB

To follow Migration API naming convention, I changed "Image" to "ImageField". Patch is in the attachment.

mikeryan’s picture

Title: Migrate Drupal 7 Image Fields » Migrate Drupal 7 image and file fields
Issue tags: +Needs tests
FileSize
3.7 KB

D7 file fields are similarly broken, so I borrowed the image field plugin here to make one for those.

mikeryan’s picture

Status: Needs review » Needs work

Over at #2612914: Images transfer but are not linked in content @joergM reports:

I tried the patch and both, file fields and image fields, were migrated successfully.

Looks like the next step here is tests.

grahl’s picture

I attempted to rerun my migration with a clean database with the combined patch in #10 after I noticed files were missing and #5 had worked for images.

However, images were now no longer being associated correctly, I thus reverted ImageField to Image and my migration completed as expected. That trivial change is attached.

bloomt’s picture

Patch (migrate_drupal_7_image-2604484-11.patch) failed with error "fatal: corrupt patch at line 144"

bloomt’s picture

Also my images fields are still not linking after patch 10

dobe’s picture

Attached is a patch to fix #10 where change from image to imagefield didn't import the image fields. I also moved imagefield to d7 folder as I don't think this will be compatible with d6.

dobe’s picture

Status: Needs work » Needs review

The last submitted patch, 12: migrate_drupal_7_image-2604484-11.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 15: migrate_drupal_7_image-2604484-15.patch, failed testing.

dobe’s picture

Something went weird with git diff... Reuploading

The last submitted patch, 5: migrate-d7_image_fields-5.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 19: migrate_drupal_7_image-2604484-16.patch, failed testing.

dobe’s picture

I am not sure what is going on here... I pulled latest dev head.. WITHOUT applying this patch. Installed a fresh install and cannot get drupal to pass Drupal\migrate_drupal\Tests\d6\EntityContentBaseTest.... Which should be passing.... right? I have no idea... I dunno how to debug drupal 8... lol.

steinmb’s picture

Issue tags: +Migrate D7 critical
steveOR’s picture

Doing a drush based migration from 7.41 to 8.0.0, confirming with patch 10 the files are coming through but not the images. With patch 16 both files and images are importing! However this patch forgets to import the file descriptions, which can be done with the addition of a "description" field value in FileField.php processCckFieldValues() line 55:

  'target_id' => 'fid',
  'display' => 'display',
  'title' => 'title',
  'description' => 'description',

Very happy to have file and image fields finally associated to D8 nodes!

quietone’s picture

Here's a test for d7 file and image field values.

Still needs tests for d6. And doing should help confirm if ImageField.php needs a d6 and d7 version, as suggested in #15.

quietone’s picture

Status: Needs work » Needs review
quietone’s picture

It isn't clear to me what to do about D6 testing. Aren't file fields contrib in D6?

quietone’s picture

Make the D7 file and image tests explicit. Added file field data to the D7 dump to do this.

Don't know what I was thinking about the D6 fields and contrib. That aside, the D6 MigrateNodeTest doesn't have any file field data. The D6 process plugin, d6_cck_file, tries to lookup the ID of the migrated file. If it isn't found an empty fid is returned. So, no data to test. The D7 migration does not do this lookup. Should it?

quietone’s picture

Anyone know why the D6 file process, d6_cck_file, does a lookup on the fid while the D7 process doesn't? See http://cgit.drupalcode.org/drupal/tree/core/modules/file/src/Plugin/migr...

Plus that process has a todo, waiting for #2487568: Process plugins should not be allowed to skip rows. Since that is fixed, this needs a bit of review itself to see what should be happening here.

quietone’s picture

Talked to chx on IRC about the fid lookup being done in the d6_cck_file. He said it wasn't necessary because the drupal-to-drupal migrations keeps the ids. So, I removed the lookup code from /d6/CckFile.php. With that gone it was straightforward to test the filefield data in MigrateNodeTest.

Still need to do the same for D6 image files.

Status: Needs review » Needs work

The last submitted patch, 30: 2604484-30.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
FileSize
13.55 KB
2.29 KB

Need to install the file entity schema for those tests. Lets see if I fixed them all.

quietone’s picture

Add an image field to a test node in the D6 dump. This will cause a fatal error, in the preSave method in ImageItem.php.

Call to a member function getFileUri() on a non-object PHP Fatal error ImageItem.php 321

The preSave method ensures that the width and height are not empty. If either are empty, which seems to be true for D6, preSave attempts to get the dimensions using the image factory service. And somewhere in getFileUri() it fails.

Status: Needs review » Needs work

The last submitted patch, 33: 2604484-33.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review

That is the error I expected, just occurring in more tests. However, this issue is to add D7 image and file fields, not improve D6 image and file field testing. I've become distracted. Lets return to solving this issue only.

The tests for this issue are resolved in patch #28 and that is the patch that should be reviewed. At some later time I'll make an issue about the changes made for D6 file fields which are in the later patches. It is too late in the day to do that now.

To any reviewers, please review patch #28, ignore the later ones.

quietone’s picture

Correct whitespace error.

flocondetoile’s picture

Patch #28 tested for migrating D7 site to D8. Works fine. Image are now linked to their node. Note that i have to do the upgrade process from a new D8 site. In the previous D8 site, with the migrate-revert and migrate-import drush commands, I don't succeed to link images to their nodes.

KarenS’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed that this fixes images problems in a D7 migration. I used the last patch, #36.

ckng’s picture

Tested D7 image field migration with path #36 - Working.

joel_guesclin’s picture

I have the same problem, but with a D6 => D8 migration. Could this be added to this issue, or is there a separate one?

quietone’s picture

The D6 issue is #2640842: Make related file migration ID configurable in d6_cck_file. Back in #35 I removed the D6 work from this issue but forgot to report back here.
At that time I thought the issue just needed to add tests for the D6 image and file migration but if it is more than that, as suggested in #40, please change the IS as needed.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 36: 2604484-36.patch, failed testing.

The last submitted patch, 36: 2604484-36.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review

Looks like testbot made a mistake. The test is passing.

quietone’s picture

Sorry, I was rushing off to the airport and made a mistake. This should be RTBC as per #38.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

Yicks, I did it again. This time resetting to RTBC as per #38. The tests are passing even though testbot thought otherwise.

  • alexpott committed 53b7b92 on 8.1.x
    Issue #2604484 by quietone, dobe, drclaw, skyredwang, mikeryan, grahl:...

  • alexpott committed e66fbef on
    Issue #2604484 by quietone, dobe, drclaw, skyredwang, mikeryan, grahl:...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

Committed e66fbef and pushed to 8.0.x and 8.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

AniaMi’s picture

Version: 8.0.x-dev » 9.x-dev

Any patch for Drupal core 8.1.7?

AdamPS’s picture

Version: 9.x-dev » 8.0.x-dev

Looks like version was changed by mistake in #51

yurg’s picture

yurg’s picture