I'm trying to migrate user pictures from a D6 to a D7 installation. So far, I have successfully migrated my D6 user roles. So in general, common arguments work correctly.

I used the following definition for picture migration:

  $role_arguments = comm_arguments + array(
      'machine_name' => 'UserPictureMapping',
      'description' => t('Import D6 user pictures'),
      'default_uid' => 1,
      'destination_dir' => 'private://pictures',
  );

  Migration::registerMigration('DrupalPicture6Migration', $role_arguments['machine_name'], $role_arguments); 

Migration finds all pictures to import, but running the import results in two error messages per picture:

  • /path_to_webroot/old_d6_upload_folder/pictures/picture-87.jpg Error The specified file /pictures/picture-87.jpg could not be copied to private://pictures/pictures/picture-87.jpg.
  • /path_to_webroot/old_d6_upload_folder/pictures/picture-87.jpg Error New object was not saved, no error provided

There are no error messages in server log and also all folder permissions seem to be fine.

As a result, pictures are not imported. However, what works is that the folder /pictures/pictures is created in my private download folder.

So what's wrong?

Comments

advseb’s picture

Version: 7.x-2.0 » 7.x-2.x-dev

We use latest 7.x-2.x commit.

advseb’s picture

Component: Documentation » Code
Category: support » bug

I have to change that into a bug report. I don't think that the current code is able to handle migration of pictures if private download method is used on D6 source. My colleague will provide additional details how we worked around it.

Miro Goepel’s picture

I'm the colleague advseb mentioned.
Let's take a closer look at the error message advseb cited: The specified file /pictures/picture-87.jpg could not be copied to private://pictures/pictures/picture-87.jpg

The entry in the D6 database (table 'users', column 'picture') regarding this file is:
/path/to/home_directory/upload_directory/pictures/picture-87.jpg

This entry is equivalent to the absolute path of the user's picture on our server. It differs from the much shorter path mentioned in the error message: /pictures/picture-87.jpg

My workaround was to reattach the preceding part of the original path to the path, which is used in the copy function:

// in migrate-7.x-2.5\migrate\plugins\destinations\file.inc  // <-- added by Miro
 protected function copyFile($destination) {
    // Perform the copy operation, with a cleaned-up path.
    //$this->sourcePath = self::urlencode($this->sourcePath); // <-- commented out by Miro
    $this->sourcePath = '/path/to/home_directory/upload_directory'.$this->sourcePath; // <-- added by Miro
    if (!@copy($this->sourcePath, $destination)) {
      $migration = Migration::currentMigration();
      $migration->saveMessage(t('The specified file %file could not be copied to ' .
              '%destination.',
              array('%file' => $this->sourcePath, '%destination' => $destination)));
      return FALSE;
    }
    else {
      return TRUE;
    }
  }

Once I edited 'migrate-7.x-2.5\migrate\plugins\destinations\file.inc' in this way, UserPictureMapping ran smoothly, that is all pictures were copied and all respective entries in the 'file_managed' table of the D7 database were created correctly.

I've not yet taken the time to run a backtrace to locate at which point and why the original working path got cropped. I agree with advseb however, that in this case the picture migration is not working as it's supposed to be.

mikeryan’s picture

Component: Code » Documentation
Category: bug » support
Status: Active » Postponed (maintainer needs more info)

You need to explicitly tell your installation where the pictures are - it has no way to automatically know anything about /path/to/home_directory/upload_directory. Add a source_dir argument:

  $role_arguments = comm_arguments + array(
      'machine_name' => 'UserPictureMapping',
      'description' => t('Import D6 user pictures'),
      'default_uid' => 1,
      'source_dir' => '/path/to/home_directory/upload_directory',
      'destination_dir' => 'private://pictures',
  );

The documentation at http://drupal.org/node/1819706 omitted this, I've added it in now.

Miro Goepel’s picture

Thank you, Mike. That solved our problem.

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Fixed
advseb’s picture

Thanks for directly updating the documentation!

Status: Fixed » Closed (fixed)

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