This commit is contained in:
@@ -78,7 +78,7 @@ namespace AyaNova.Biz
|
||||
int chunkSize = 100;
|
||||
do
|
||||
{
|
||||
var chunk = await ct.FileAttachment.AsNoTracking().OrderBy(z => z.Id).Skip(skip).Take(chunkSize).Select(z => new { z.Id, z.StoredFileName, z.Exists }).ToListAsync();
|
||||
var chunk = await ct.FileAttachment.AsNoTracking().OrderBy(z => z.Id).Skip(skip).Take(chunkSize).ToListAsync();
|
||||
if (chunk.Count < chunkSize)
|
||||
{
|
||||
//we've reached the end
|
||||
@@ -90,17 +90,26 @@ namespace AyaNova.Biz
|
||||
var FullPathName = FileUtil.GetPermanentAttachmentFilePath(i.StoredFileName);
|
||||
AllDBFileFullPath.Add(FullPathName);
|
||||
var FileExistsInReality = AllAttachmentFilesOnDisk.Contains(FullPathName);
|
||||
var ParentBizObjectExistsInReality = await BizObjectExistsInDatabase.ExistsAsync(i.AttachToObjectType, i.AttachToObjectId, ct);
|
||||
//does the db record reflect the same status as reality?
|
||||
if (FileExistsInReality != i.Exists)
|
||||
if (FileExistsInReality != i.Exists || !ParentBizObjectExistsInReality)
|
||||
{
|
||||
//Nope so update it to be the same
|
||||
var f = await ct.FileAttachment.FirstOrDefaultAsync(z => z.Id == i.Id);
|
||||
if (f != null)
|
||||
{
|
||||
f.Exists = FileExistsInReality;
|
||||
if (!ParentBizObjectExistsInReality)
|
||||
{
|
||||
//switch it to notype
|
||||
f.AttachToObjectType = AyaType.NoType;
|
||||
f.AttachToObjectId = 0;
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
//DOES THE PARENT OBJECT EXIST?
|
||||
|
||||
}
|
||||
|
||||
} while (moreRecords);
|
||||
@@ -125,7 +134,8 @@ namespace AyaNova.Biz
|
||||
|
||||
// ORPHANED FILES CHECK
|
||||
var FilesOnDiskNotInDb = AllAttachmentFilesOnDisk.Except(AllDBFileFullPath);
|
||||
await JobsBiz.LogJobAsync(job.GId, $"Found {FilesOnDiskNotInDb.Count()} physical files not known to be existing Attachments, creating attachment records tied to 'NoType' so they show in UI");
|
||||
if (FilesOnDiskNotInDb.Count() > 0)
|
||||
await JobsBiz.LogJobAsync(job.GId, $"Found {FilesOnDiskNotInDb.Count()} physical files not known to be existing Attachments, creating attachment records tied to 'NoType' so they show in UI");
|
||||
|
||||
// FOREIGN FILES placed in folder directly outside of attachment system
|
||||
// user thinks they can just drop them in or accidentally copies them here
|
||||
|
||||
Reference in New Issue
Block a user