Hi Lyle,
Sorry this turned out kinda long but I was experiencing some funny behaviour trying to get our catalog updates imported with all the images so I narrowed the import file down to a couple products and went over it case by case. Using version 'alpha-7e'.
I found that
- If you import products that already exist, they lose their images
- If you are importing your images from the drupal files directory, they will have "_0" appended to the filename. In the files table the filepath column will refer to the imagefile with the _0 in the filename whereas the filename field will refer to the imagefile without the _0.
- If you import the same file twice, the second time the images will be placed in the 'ubercart_images' directory instead of the 'files' directory but no images show up for products. In the files table no images paths ever contained the 'ubercart_images' directory as part of the path
The import script will import images correctly only if the products don't already exist in the database.
Here are the steps I went through:
After testing the import/export routine on "Overwrite existing item" with the 'unique hash' and 'id' fields generated by export routine in the XML file this is what I have found:
-
drupal 'files' directory empty, ubercart_images directory exists & empty. no images in files table, no products in database.
- Importing using absolute file path outside wwwroot for image: OK
- Importing using URL on local server outside drupal directory: OK
- importing using URL on remote server: OK
Note however that the images were copied to the files directory and the ubercart_images directory remains empty! I don't think this is the desired behaviour given the code below.
if (module_exists('imagefield')){
foreach ($product_data->image as $image){
$image_path = (string)$image->path;
$path_info = pathinfo($image_path);
$local_path = file_create_path() .'/ubercart_images/'. $_SERVER['HTTP_HOST'];
if (!file_check_directory($local_path)){
$local_path = file_create_path() .'/ubercart_images';
}
$local_path .= '/'. rawurldecode(basename($image_path));
if (file_exists($local_path) || $size = file_put_contents($local_path, fopen($image_path, 'rb'))){
$product->field_image_cache[$i] = array(
'fid' => (file_exists($local_path) ? db_result(db_query("SELECT fid FROM {files} WHERE nid = %d AND filepath = '%s'", $nid, $local_path)) : 'upload'),
'title' => isset($image->title) ? html_entity_decode((string)$image->title) : '',
'alt' => isset($image->alt) ? html_entity_decode((string)$image->alt) : '',
'filename' => basename($image_path),
'filepath' => $local_path,
'filesize' => (file_exists($local_path) ? @filesize($local_path) : $size),
'filemime' => 'image/'. $path_info['extension'],
);
$i++;
}
}
} - Importing the same file again except: the products already exist from the previous import, All images are now in drupal 'files' directory and are correctly referenced in 'files' table.
- No images appear for any products on any pages, no img tags are generated. The images become disassociated with the products as when I delete the products the images are no longer removed from the files directory or the files table.
- the files table is unchanged: all images are listed with correct filenames and NIDs.
- All of image files have been copied to the ubercart_images directory this time!
- Now with the product fields 'unique hash' and undocumented 'id' removed to simulate importing a catalog from a source other than the export script. No products in the database, files and ubercart_images directories empty
same as case 1) above, all OK. - performing the same import again except all products already exist in database and image files are in the 'files' directory.
same as 2) above. Images don't show up for products and they have been copied to ubercart_images directory. - Above all of the images were stored outside of the drupal directory. This time the images accessed by absolute file path are in the drupal 'files' directory as are the images accessed by a URL to local machine. So the images already exist on the filesystem even though they don't exist in the database.
Images stored in drupal files directory, no unique_hash field in xml file, no files or products in the database.- files were copied to the files directory with _0 appended to the filename.
- references to the images in the files table have _0 in the filename in the filepath field, but the filename field has no _0.
- ubercart_images empty.
If the file already exists, why does it create a new copy?
- running the same import again, now with images with _0 in their filename in the files directory, ubercart_images directory is empty.
same as 2) and 4) above. images copied to ubercart_images directory and no images appear on pages.
