While migrating from Drupal 6 to Drupal 7 (into a new blank site), I noticed that files attached to comments are not handled by the Migrate module. The D6 site uses a contributed module „Comment Uploads“ that associates files with comments in a table comment_upload:

| fid  | nid  | cid   | description          | list | weight | legacy_fid |
| 1002 | 1001 |  1000 | under_149.jpg        |    0 |      0 |          0 |
| 1774 | 1969 |  6855 | ruler.png            |    0 |      0 |          0 |
| 1706 | 1712 |  6009 | 1.png                |    1 |    127 |          0 |
| 1703 | 1712 |  6006 | 2.png                |    1 |    127 |          0 |
| 1704 | 1712 |  6006 | 3.png                |    1 |    127 |          0 |

Nodes, comments and files already migrated successfully to D7 using the migrate_d2d module and its user interface. Node attachments went through fine. Except comments no longer have files attached now. Since files and comments exist, it should be possible to attach the files to their original comments, using the above table.

Q: How would I go about and migrate comment attachments properly?

a) Would it make sense to hack the migration class for D6 comments? The issue is: The comment attachments do not appear as a source field in the Migrate user interface, as they do for nodes. Maybe if this could be achieved, this would be the best solution.

b) Why not grab that above table’s data (some 1000 rows only), iterate over it and call the appropriate D7 API to attach each file (fid) to its original comment (cid)? If so, which API calls should be used and where do I place this code?

Despite doing software development for decades, Drupal’s inner underpinnings are new to me. Any help is highly appreciated.

Edit: I don't want to use the Comment Upload module under D7 anymore.

3 Answers 3


Consider looking at this Github link mentioned in Comment #35 of Issue # 554986 ...

If it works for you, then please add an appropriate comment about that in that issue (which currently has status "needs review" ...). And of course let us know about it around here also ...

  • Thanks for your help. Since I didn't want to use the Comment Upload module under D7 anymore, I had to migrate to the new D7 File field that's also available for comments. Posted the solution here
    – Anders
    Jul 14, 2015 at 13:36

Maybe not perfect, but this worked for me: Find a solution here. It boiled down to extending the query in migrate_d2d to include all attached file IDs and map them to the new D7 File field.


You can bring the source file field info over directly from the comment_upload file by adding this code to drupal d2d ui comment migration:

    $query->leftJoin('comment_upload','cu','c.cid = cu.cid');
    $query->addExpression("GROUP_CONCAT(cu.fid SEPARATOR ',')", 'comment_upload_fid');
    $query->addExpression("GROUP_CONCAT(cu.description SEPARATOR ',')", 'comment_upload_description');
    $query->addExpression("GROUP_CONCAT(cu.list SEPARATOR ',')", 'comment_upload_list');
    $query->addExpression("GROUP_CONCAT(cu.weight SEPARATOR ',')", 'comment_upload_weight');

Then you map the d6 comment_upload file fields (created above) to d7 comment file fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.