When generating users the picture files are registered under file_usage

Steps to reproduce:

drush --yes site-install
drush --yes en devel_generate
drush sql-query "select * from file_usage"
drush --yes genu 5
drush sql-query "select * from file_usage"

The file_usage should contain 5 references to the user type.

Next create a new user by hand:

  1. Visit admin/people/create
  2. Add picture

Next run

drush sql-query "select * from file_usage"
fid	module	type	id	count
26	user	user	17	1

This user picture is managed.

This could be of

function user_save($account, $edit = array(), $category = 'account') {
...
        if (!$picture->status) {

as we generate a managed file

function devel_create_users($num, $kill, $age = 0, $roles = array()) {
...
        // Create an empty, managed file where we want the user's picture to
        // be so we can have GD overwrite it with the image.
        $picture_directory =  variable_get('file_default_scheme', 'public') . '://' . variable_get('user_picture_path', 'pictures');
        file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY);

XRef Discovered by deleting files belonging to nodes and users using drush entity #1330504: Test the File entity which failed for nodes due to file_usage.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

clemens.tolboom’s picture

Status: Active » Needs review
FileSize
1.53 KB

The attached patch creates a temporary:// file which when set $file->status = 0 triggers user_save to copy the image into it's final destination.

less is more :)

moshe weitzman’s picture

I believe this is a dupe.

clemens.tolboom’s picture

This is not a dup of #1288674: Devel generates files without filenames which only fixes the file name.

This patch links the file to the user as the issue summary tries to tell. Just running

drush sql-query "select * from file_usage"

on a devel genu / genc site should convince you.

Files for nodes are in file_usage table but the files for users are not.

willzyx’s picture

Issue summary: View changes
Status: Needs review » Closed (works as designed)

Closing for lack of activity. Feel free to reopen if the issue still exists