I successfully migrated external files via MigrateDestinationFile to Drupal files, and now I am trying to map these files to image fields for users, but they are not showing up for the user's image field.

Any tips on how to debug or succeed with such a migration? I am also unsure if my addFieldMappingline will take care of multiple values to the same field.

Here is the relevant code in MigrateDestinationUser:

    $this->addFieldMapping('field_pictures', 'pid')->sourceMigration('CoppermineFileCopy');

even adding MigrateFileFid did not help

            $this->addFieldMapping('field_pictures', 'pid')->sourceMigration('CoppermineFileCopy');

And the CoppermineFileCopy

    class CoppermineFileCopyMigration extends MyMigration {

    private $base_path;

    public function __construct() {
        $this->description = t('Profile images');

        $this->base_path = '/home/myurl/public_html/copperminephotos/albums/';

        $this->map = new MigrateSQLMap($this->machineName,
        array('pid' => array(
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
        'description' => 'Coppermine Photo ID',

        $query = db_select('coppermine_pictures', 'copp')
        ->fields('copp', array('pid','filepath','filename','title'));

        $this->source = new MigrateSourceSQL($query);
        $this->destination = new MigrateDestinationFile();

        // In the simplest case, just map the incoming URL to 'value'.
        $this->addFieldMapping( 'value', 'filepath_filename');


    public function prepareRow($row) {
        //dpm("Before Processing:");
        // Always include this fragment at the beginning of every prepareRow()
        // implementation, so parent classes can ignore rows.
        if (parent::prepareRow($row) === FALSE) {
            return FALSE;
        $row->{"filepath_filename"} = $row->filepath.$row->filename;

        //dpm("After Processing:");
        return TRUE;

Releated question Migrate images form external source (not drupal) to Node Destination

Also posted at https://www.drupal.org/node/2613266 maybe Mike can comment on it.

  • PS Meanwhile, a solution is to write custom logic that extracts the imported fileids that belong to the user in prepareRow. Hoped this task would be more straightforward with reusing the sourceMigration – giorgio79 Nov 11 '15 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.