I was trying to upgrade around 5k nodes with image field, all went supposedly good (no errors). But the operation ended up having a bunch of user pictures replaced with files from those node fields. Puzzled.
Less busy content type (a few dozen nodes) was upgraded just perfect.
Any pointers where to look to try to track/fix this behavior?
Comments
Comment #1
protoplasm commentedI'm having the same issue. Files are being overwritten in files_managed table and it appears permanent status in the table does not mean it can't be overwritten. This is what is currently holding up my upgrade of a large social network to D7. Has anyone figured out a solution for this?
Comment #2
protoplasm commentedI'm changing this priority to critical.I've managed to jump every undocumented hurdle on upgrading a social network from D6 to D7 so far except this one. No matter how I tweak it, migrating content is overwriting my account user pictures which are already in the files_managed table. Does anyone have any insight into why or how this might occur?Comment #3
protoplasm commentedWell, I've found the issue and so I will answer my own question. I'm not sure how it has happened, but some files have the same FID as the FID of the user pictures and so when content is migrated, the files FID is overwriting the existing picture in the files managed section. Don't know how or when this occurred or how to fix it yet, but that appears to be the issue.
So I'm beginning to doubt this is a bug in content migrate.Comment #4
protoplasm commentedComment #5
betarobot commented@protoplasm checked my db and spotted the same: some files would have same FID in d7. But for me it would happen after conversion. Initial database looks just fine. Checking for other pointers, but still see none.
Comment #6
protoplasm commentedHard to imagine no one else has had this issue.
Comment #7
melvix commentedI am having this issue. It is absolutely a bug in content_migrate. I would classify it as critical, since it will destroy your data and prevent you from successfully upgrading and deploying a stable site.
It looks like content_migrate_filefield_data_record_alter() will overwrite any records that already exist in the files_managed table, which is where your user avatars will be after you've run all the user module updates.
More specifically, it is the use of db_merge() instead of file_save().
Comment #8
protoplasm commentedThis very issue has me at a complete standstill in upgrading to D7. In the last six years of using Drupal, I've never found an issue so frustrating as this or stopped me in my tracks. Clearly, the issue begins with content_migrate's overwriting so I believe you're right.
Do you have a work around or solution?
Comment #9
melvix commentedThis isn't really a solution, but what I did was stash a copy of the users table before the upgrade, then re-import the avatars after content_migrate was done doing its thing using a custom script.
Comment #10
adams.garfield commentedEven i have the same problem.Gonna try out this. Importing the avatars after content_migrate will do the trick.!!!
Thanks
Comment #12
protoplasm commented@melvix, do you have a solution you can share?
Comment #13
winniepoo commentedI have the same problem.
It's needed to change file fid in content_migrate module if there is file in file_managed table with this fid.
Any solutions?
Comment #14
fugazi commentedsame problem
Comment #15
protoplasm commentedStill an issue, still can't upgrade to 7. If someone could detail their solution, it would be most appreciated.
Comment #16
mrsean commentedThis is still an issue occurring during a D6 to D7 migration that I am doing...
It would certainly be wonderful if someone would be able to contribute their custom script... @melvix, care to share?
Thanks!
Comment #17
mrsean commentedOK I fixed this myself. here is my fix. It also fixes the format of the picture uri's so that Drupal 7 can create image-styles for all of the user pictures, which was broken after i migrated from D6 to D7.
Feel free to use as you wish. I'm not respsonsible if this breaks your site and you dont have a backup of your db. Backup your db and test this on a test version of your site first before doing on prod!
1) before migration, save the following in your D6 webroot as get_user_pictures.php. Then go to the page in a browser to get a list of users who have pictures (www.drupal6site.com/get_user_pictures.php).
Code:
2) Drop the following into your D7 upgraded site webroot as fix_user_pictures.php:
3) Copy the output from the script in step 1 into the script created in step 2, above the comment "COPY OUTPUT OF... HERE", within the $user_picture_files array.
4) On your d7 site, go to "drupal7site.com/fix_user_pictures.php".
5) Read the output to see what was fixed and what wasn't.
6) View the user profiles on your d7 site to see if the broken pictures were fixed!
Comment #18
darkdimHi!
# 17 I'm afraid this is not a correct approach.
If we correct user picture (avatar), we thus be overwritten migrated cck field.
Or am I wrong?
Comment #19
darkdimWho were able to solve this problem?
Comment #20
xqi commentedI also run into this issue when upgrading my site (drupal 6) to drupal 7.26.
some users' pictures are removed from the database. some users' pictures got replaced by irrelevant files, such as PDF etc... the physical files are still there but not showing in the database.
this is definitely a bug and I wonder there is any patch for this or not. I googled this issue but it looks like only a small amount of sites run into this issue. it makes me wonder if it has something to do with the site's configuration, such as orphaned data
anyway i am subscribing.
Comment #21
rfayI definitely have this exact problem. I'm hoping it might be related to #1732944: Corrupted file URI after filefield migration. The example given there is a files directory named "files" (not sites/default/files) so wondering if all of you have legacy "files" directories like the site I'm working on.
Comment #22
rfayAs described above, the problem here is that user pictures are corrupted by the file migration in content_migrate. The path and other information in the file_managed entity for an unlimited number of user pictures is replaced by random pictures which existed in filefields or imagefields.
Here is a complete description of this critical problem, which has the potential to affect EVERY upgrade where there are user pictures and filefields or imagefields.
1. The core upgrade of uploads takes place in system_update_7061(). It makes the assumption that no managed_file entities exist, and just creates new entities numbered exactly the same
2. The core upgrade of user pictures from simple paths to file_managed entities, takes place in user_update_7012(). It creates many new file entities. user_update_dependencies(), however, includes code to ensure that user_update_7012() runs *after* system_update_7061():
3. The bug: file_content_migrate_data_record_alter() (in content_migrate) comes along, which states clearly
Since the content migration is done after the core upgrade, the user picture entities have already been added as managed_file entities, and the assumption made in system_update_7061 (that no file_managed entities exist, and therefore the copied code can just create/update entities with the same fid value that existed in the D6 files table) is no longer valid, and leads to massive data corruption (improper image values).
I'm not sure how this can be fixed easily, because it would require knowing updating entities reference a particular file.
Here is a workaround:
1. Before core upgrade, comment out the section of user module's user.install starting with user_update_7012().
2. Complete the core upgrade.
3. Run the content_migration
4. Replace user.install with its normal contents
5. Run update.php again to finish the user module's processing of pictures, which adds new fids to file_managed.
Comment #23
gumanov commentedOther than the workaround posted above, does anyone have any recommendations for a patch?
I ran into the same issue, see here:
https://www.drupal.org/node/2881907#comment-12105651
Really surprised this hasn't been addressed. Seems like a major bug.