When importing products with feeds some products have reference to the same image. Any ideas how to prevent multiple images from being created with file endings like _1 _2 .. Everytime i import it seems some products always gets resaved so the images just keep piling up.

Comments

toelli’s picture

As a temporary solution to this problem i run the following code to remove orphaned images.

$result = db_query("SELECT fm.*
FROM file_managed AS fm
LEFT OUTER JOIN file_usage AS fu ON ( fm.fid = fu.fid )
LEFT OUTER JOIN node AS n ON ( fu.id = n.nid )
WHERE (fu.type = 'node' OR fu.type IS NULL) AND n.nid IS NULL");
foreach ($result as $file) {
	if(!empty($file->uri)) {
		file_delete($file);
	}
}