Scenario - I have a file migration which grabs user avatars and creates file objects for them. My user migration then uses sourceMigration() to get those fids into $account->picture. Works nicely on initial import, but running with --update clears the pictures. This is because user_save(), on update only (not insert) expects $account->picture to be a file object rather than a fid. MigrateDestinationUser needs to deal with this.

Comments

mikeryan’s picture

Status: Active » Patch (to be ported)

Committed to D7.

mikeryan’s picture

Status: Patch (to be ported) » Closed (fixed)

Not relevant to D6.

mototribe’s picture

Hi Mike,

I'm using the 7.2.2 version and am trying to update the user picture (after I migrated the image first). It doesn't update the "picture" column in the users table. I tried the dev version but ran into errors and went back to 7.2.2.

I copied the extra code from from the dev version of plugins/destinations/user.inc but still no success.

   // While user_save is happy to see a fid in $account->picture on insert,
    // when updating an existing account it wants a file object.
    if ($updating && ($fid = $account->picture)) {
      $account->picture = file_load($fid);
    }

When I add the fid manually to the users.picture field the picture shows up ok.

I followed the examples and it's updating other fields, just not the picture field. Here is the relevant code:


    $this->systemOfRecord = Migration::DESTINATION;

    // Mapped fields
    $this->addFieldMapping('uid', 'user_id')
         ->sourceMigration('CCCUser')
         ->description(t('get the uid from the CCCUser migration'));

	//need to pass the unique key from the userpicture migration to picture. I guess migrate will translate into fid
	$this->addFieldMapping('picture', 'kauid')
		 ->sourceMigration('UserPicture')
		 ->description(t('get the picture id from the UserPicture migration'));

Any help is appreciated. Thanks!
UWE

mototribe’s picture

got a workaround - I added this to the image import migration:

//Called after the file is imported
  public function complete($file, $row) {        
      $sql = "UPDATE users set picture = :fid where uid = :uid";
      if (db_query($sql, array(':fid' => $file->fid, ':uid' => $file->uid)))
        watchdog(WATCHDOG_INFO, "Edited user $account->uid to set picture = $file->fid");        
  }

thanks to http://drupal.org/node/1120136#comment-4320404