Hi,
I’ve written a tool that basically renames images. As far as I know, to do this I need to create a copy of the original file and then add that new file SystemId to the BaseProduct or Variant that uses the image.
var imageFile = FileService.Get(image).MakeWritableClone();
BlobContainer blobContainer = BlobService.Get(imageFile.BlobUri);
var filename = $"{productName}_{productImages.IndexOf(image)}.jpg";
using (SecurityContextService.ActAsSystem())
{
var file = new LitiumFile(SystemConfiguration.Instance.ImportImageFieldTemplateId, imageFile.FolderSystemId,
blobContainer.Uri, filename.ToCleanFileName())
{
FileSize = imageFile.FileSize,
AccessControlList = new HashSet<AccessControlEntry>()
{
new AccessControlEntry(new Operation(Operations.Entity.Read),
SystemConfiguration.Instance.VisitorGroupSystemId)
}
};
NewIndexes.Add(imageFile.SystemId, file.SystemId);
FileService.Delete(imageFile);
FileService.Create(file);
return file.SystemId;
When I run the tool I sooner or later encounter the following error:
Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
When trying to run .Update on either my BaseProduct- or VariantService, it seems to me like it’s completely random when it happens.
I looked through the slack channel and found a thread about this re: version 5.5.1 where it was advised to run a SQL-query to clean up indexes. So I tried that once with some success but after about 1000 baseproducts later I encountered the same problem, so I went as far as to run the script after every base product change
(I get a baseproduct and fix all variants and the bp itself in each iteration of this loop)
SO basically I’m asking for anything that can assist me with this? is there an easier way to rename 22000 images or should I consider doing it some other way?
thanks in advance
Litium version: 6.2.0