I was wrong. It's broken since Hikashop 2.3.3(oldest version I have), but it worked partially and duplication of rows was much lower.
In 2.3.3 column #__virtuemart_medias.file_title were used to identify product's image.
It worked partially for first product's image as long as user didn't change title of image.
By default title of first product's image is file name.
In 2.3.4 it was changed and main column to identify product's image is #__virtuemart_medias.file_meta and this exposed the bug as file_meta (alt for image) is empty by default.
At first, because of limit in SQL query on line
1254
, not all images are copied and referenced in $meta_files array.
Next because condition at lines
1280-1283
is flawed, $meta_files is always empty.
It should be replaced with:
$meta_files[] = $this->db->Quote($file_name);
The line
1348
is where bug #1 come from.
Because vmm.file_meta and $meta_files are always empty, empty value is inserted in column #__hikashop_file.file_path for every row.
Duplication of rows come from line
1358
as it insert all images of not yet imported products.
Method importDownloads() is also flawed.
Because of missing file_url column in select on line 1999, no file is copied, otherwise all images will be copied to "uploadsecurefolder" as in Hikashop 2.3.3.
Also column #___virtuemart_medias.file_is_product_image is not used in VM and instead there should be `file_is_downloadable`
Here is fixed SQL query on lines
1999-2004
$sql = 'SELECT vmm.virtuemart_media_id,vmm.file_meta,vmm.vmm.file_meta,vmm.file_is_downloadable '.
'FROM `'.$this->vmprefix.'virtuemart_products` vmp ' .
"INNER JOIN `".$this->vmprefix."virtuemart_product_medias` AS vmpm ON vmp.virtuemart_product_id = vmpm.virtuemart_product_id " .
"INNER JOIN `".$this->vmprefix."virtuemart_medias` vmm ON vmpm.virtuemart_media_id = vmm.virtuemart_media_id " .
'WHERE vmm.virtuemart_media_id > '.$offset.
' AND vmm.file_is_downloadable = 1'.
' ORDER BY vmm.virtuemart_media_id ASC LIMIT '.$count.';';
Here is fied code from lines 2067-2079
$data = array(
'file_name' => 'vmm.file_title',
'file_description' => 'vmm.file_description',
'file_path' => "SUBSTRING_INDEX(SUBSTRING_INDEX(vmm.file_url, '/', -1), '\\\\', -1)",
'file_type' => "'file'",
'file_ref_id' => 'hkp.hk_id'
);
$sql = 'INSERT IGNORE INTO `#__hikashop_file` (`'.implode('`,`',array_keys($data)).'`) '.
'SELECT '.implode(',',$data).' FROM `'.$this->vmprefix.'virtuemart_products` vmp '.
"INNER JOIN `".$this->vmprefix."virtuemart_product_medias` AS vmpm ON vmp.virtuemart_product_id = vmpm.virtuemart_product_id ".
"INNER JOIN `".$this->vmprefix."virtuemart_medias` vmm ON vmpm.virtuemart_media_id = vmm.virtuemart_media_id " .
'INNER JOIN `#__hikashop_vm_prod` AS hkp ON vmm.virtuemart_media_id = hkp.vm_id '.
'WHERE vmm.virtuemart_media_id > '.$this->options->last_vm_pfile.
' AND vmm.file_is_downloadable = 1'.';';
Anyway method importDownloads() will also suffer the row duplication and missing records as importProducts().
I was trying to fix it, but because of lack of time I had to comment it out and run queries and copy files by hand.
Hope it helps.