Closed (cannot reproduce)
Project:
Migrate
Version:
7.x-2.3
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
11 May 2012 at 16:34 UTC
Updated:
3 Jul 2012 at 08:20 UTC
I am migrating to a custom content type from an external data source. I have the images I want to use stored in a directory on my server but they are vast in numbers. So instead of copying to them, I am hoping to just link to them. I created a symbolic link at /sites/default/files/ that points to the dir with the images.
The following code is not performing like I describe above. It's not linking to any image files at all. Any help would be appreciated.
I'd also like to prevent file deletion on rollback as stated here http://drupal.org/node/1061560, how do I do that within the MigrateFileFieldHandler?
// install file settings for image field in custom content type
Array=(
'listing_image' => array(
'field_name' => 'listing_image',
'label' => $t('Pictures'),
'required' => FALSE,
'widget' => array(
'type' => 'image_image',
'weight' => 0.18
),
'display' => array(
'default' => array(
'type' => 'galleryformatter_default'
),
'teaser' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_style' => 'galleryformatter_thumb',
'image_link' => 'content'
)
),
),
));
I put the following in my module.inc file
// the following is the field mapping in __construct()
$arguments = MigrateFileFieldHandler::arguments('/var/www/html/example/sites/default/files/rets_images/resi/', 'file_link', FILE_EXISTS_RENAME);
$this->addFieldMapping('listing_image', 'src_images')->arguments($arguments);
//This is what I used in prepareRow($row) to pull a list of files and set the image data json encoding
$row->src_images = array();
$files = glob('/var/www/html/example/sites/default/files/rets_images/resi/'.$row->listingrid.'*');
if($files && !empty($files))
foreach($files as $key => $file){
$file = str_replace('/var/www/html/example/sites/default/files/rets_images/resi/','',$file);
$img_data = array(
'path'=> $file,
'alt' => $row->src_title,
'title' => 'MLS '.$row->mlnumber.' image #'.$key+1
);
$row->src_images[] = drupal_json_encode($img_data);
}
Comments
Comment #1
mikeryanI don't see anything obviously wrong. I'd simplify it and make sure you get the linkage first before trying to get the alt and title values in there:
Does that at least get the file entities created and saved in the field?
Comment #2
joeyda3rd commentedThere was a human error in the code, however, it's still not migrating correctly. Notice the field mapping and file glob don't match? Durr. Anyways...
The database is implementing the file entities in 'field_data_listing_image' table, complete with matching nid and appropriate fid. However, the files won't display or are not present when editing the node.
I am getting the following error on rollback:
The specified file /var/www/html/example/sites/default/files/rets_images/resi/2096553_1.jpg could not be deleted, because it is not a valid URI. More information is available in the system log.Log just adds: "This may be caused by improper use of file_delete() or a missing stream wrapper."
I know apache can read the images fine.
I also changed the...
...so the files aren't deleted, but it appears to be attempting to delete them.
Any thoughts?
Comment #3
mikeryanAhh, I'm thinking (haven't used the old file_link support in a long time, and everything's been refactored for Migrate 2.4) that you may need to express the source directory in terms of a Drupal stream wrapper. I.e., instead of the full file path, it would be 'public://rets_images/resi/'. Give that a try and let me know how it goes.
Comment #4
mikeryanComment #5
joeyda3rd commentedSorry, I had to wait for the other development team to get the images back drupal deleted on rollback.
It seems to be deleting images fine, but when I changed the code to below as recommended, it doesn't even populate the instances.
Comment #6
mikeryanSorry, not much more I can tell you, other than that looking at old code where I used 'file_link', it did use absolute paths as the first argument, not stream wrappers. All I can suggest is debugging the processing in the file field handler.
Comment #7
joeyda3rd commentedNew to Drupal development. Please give me some pointers on how to debug this in the file field handler.I'm going to upgrade to D7.14 and Migrate 2.4 and if I have any problems, I'll create an issue on that branch.
Comment #8
joeyda3rd commentedComment #9
farse commentedi haven't been able to find any references to 'file_link' in the new migrate. so far this works, but how to I make it a link instead of copying the file?
$this->addFieldMapping('field_migrate_example_image', 'url');
$this->addFieldMapping('field_migrate_example_image:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_migrate_example_image:alt', 'image_alt');
$this->addFieldMapping('field_migrate_example_image:title', 'image_title');
Comment #10
joeyda3rd commentedYou'll probably want to make a new issue for the 2.4 version and make it active.
Comment #11
farse commentedyes, thanks, i've done that here http://drupal.org/node/1665334