Skip to content

Data importer always inserts new pictures and does not detect equal pictures while importing #1268

@iherwald

Description

@iherwald

Occures with CategoryImporter (ProductImporter and CustomerImporter?) in SmartStore v3.0.3.

CategoryImporter:
After getting an existing Category by 'categoryRepository.GetById(...)' the navigation property 'Picture' has a value for 'MediaStorageId' but 'MediaStorage' is NULL.
So the succeeding function 'ProductService.FindEqualPicture(...)' does not get any bytes of an existing picture from 'MediaStorageProvider' to compare with the new picture:

namespace SmartStore.Services.Media.Storage
{
    public class DatabaseMediaStorageProvider : IMediaStorageProvider, ISupportsMediaMoving
    {
        public byte[] Load(MediaItem media)
        {
            ...
            return media.Entity?.**MediaStorage**?.Data ?? new byte[0];
        }
    }
}

A solution that seems to work is to (temporary) enable proxy creation in 'CategoryImporter' for the DbContext:

try
{
	// We have to enable proxy creation to load binary values of current pictures. 
	// Otherwise FindEqualPicture does not work correctly.
	context.Services.DbContext.ProxyCreationEnabled = true;
	ProcessPictures(context, batch);
}
catch (Exception ex)
{
	context.Result.AddError(ex, segmenter.CurrentSegment, "ProcessPictures");
}
finally
{
	context.Services.DbContext.ProxyCreationEnabled = false;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions