I am trying to migrate multi-value file-fields.
I checked out the wine.inc but the sample provided doesn't work for me.
I tried to use JSON-encoded arrays that didn't work either and i read somewhere that method is now obsolete.

How to do this?

Here's what i have:

$this->addFieldMapping('field_case_file_upload', 'file_upload_url');
$this->addFieldMapping('field_case_file_upload:description', 'file_upload_title');
 $this->addFieldMapping('field_case_file_upload:destination_dir')
			 ->defaultValue('public://pdfs/sun_files');


		public function prepareRow($current_row) {
		    $result = db_select('tbl_myfiles', 'f')
		              ->fields('f', array('file_upload_url', 'file_upload_filepath', 'file_upload_title'))
					  ->condition('content_id',$current_row->content_id)
					  ->condition('f.file_upload_url', '%pdf%', 'LIKE')
		              ->execute();
			foreach ($result as $row) {
	      		  $current_row->file_upload_url[] = $row->file_upload_url;
		      	  $current_row->file_upload_filepath[] = $row->file_upload_filepath;
		      	  $current_row->file_upload_title[] = $row->file_upload_title;
		    return TRUE;
		  	 }	
               }

I am sure im not doing something right. Can someone cool please point me in the right direction? :)

Comments

Sunflower’s picture

Issue summary: View changes

change

Sunflower’s picture

Issue summary: View changes

updated code

Sunflower’s picture

Status: Active » Closed (fixed)

Figured this out. I just needed to add the fields to $source_fields as done in the sample wine.inc.

		$source_fields = array(
	      'file_upload_filename' => t('Filenames of files attached to this node; populated in prepareRow()'),
	      'file_upload_filepath' => t('Filepaths of files attached to this node; populated in prepareRow()'),
	      'file_upload_title' => t('File titles of files attached to this node; populated in prepareRow()'),
    	);
	
		$this->source = new MigrateSourceSQL($query, $source_fields);
Sunflower’s picture

Issue summary: View changes

blah