I am doing a migration where I have source files which contain body text, and I am extracting image files from IMG tags. I'm therefore using MigrateSourceList with MigrateListFiles as the list handler, to which I'm passing a custom subclass of MigrateContentParser. This analyses the body text, and extracts source IDs for the image files, which my migration can then use to retrieve the files from the site I'm importing from.

However, MigrateListFiles::getIDsFromFiles() only returns a chunk ID when a single file has multiple chunks. When a file happens to have only one IMG in the body, it returns just the file ID:

        if ($this->parser->getChunkCount() > 1) {
          foreach ($this->parser->getChunkIDs() as $chunk_id) {
            $ids[] = str_replace($this->baseDir, '', (string) $file->uri) . MIGRATE_CHUNK_SEPARATOR . $chunk_id;
        else {
          $ids[] = str_replace($this->baseDir, '', (string) $file->uri);

This is a problem because it means in that case my MigrateItem handler (or my migration) needs to parse the original file all over again. This is not very clean, as it creates a special case.

It would be handy to have an option somewhere to cause all IDs to have the chunk ID appended.

#2 2550793.migrate.always-append-chunk-ids.patch1.75 KBjoachim
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


joachim created an issue. See original summary.

joachim’s picture

Status: Active » Needs review
1.75 KB
PASSED: [[SimpleTest]]: [MySQL] 160 pass(es). View

Here's a patch. It's on top of the patch I've posted at #2505683: Pass item id to chunk parser for debugging purposes, hence it's going to fail tests right now.

I wasn't sure where to add the option. MigrateListFiles's __construct() is already loaded with parameters, and I figured this is something for the content parser to decide.

Status: Needs review » Needs work

The last submitted patch, 2: 2550793.migrate.always-append-chunk-ids.patch, failed testing.

Status: Needs work » Needs review

  • mikeryan committed 1456e40 on 7.x-2.x authored by joachim
    Issue #2550793 by joachim: add an option for MigrateListFiles to always...
mikeryan’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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