Files: fixed removing file method

This commit is contained in:
pavelbannov 2020-03-04 10:42:43 +03:00
parent db5a4586f1
commit c780a881df
6 changed files with 35 additions and 17 deletions

View File

@ -26,6 +26,7 @@
using System;
using System.Linq;
using Newtonsoft.Json;
namespace ASC.Common.Threading
@ -44,7 +45,7 @@ namespace ASC.Common.Threading
}
set
{
DistributedTaskCache.InstanceId = value;
DistributedTaskCache.InstanceId = value?.ToString() ?? "";
}
}
public string Id
@ -55,7 +56,7 @@ namespace ASC.Common.Threading
}
private set
{
DistributedTaskCache.Id = value;
DistributedTaskCache.Id = value?.ToString() ?? "";
}
}
@ -79,7 +80,7 @@ namespace ASC.Common.Threading
}
internal set
{
DistributedTaskCache.Exception = value.ToString();
DistributedTaskCache.Exception = value?.ToString() ?? "";
}
}
@ -90,6 +91,10 @@ namespace ASC.Common.Threading
Id = Guid.NewGuid().ToString()
};
}
public DistributedTask(DistributedTaskCache distributedTaskCache)
{
DistributedTaskCache = distributedTaskCache;
}
public T GetProperty<T>(string name)

View File

@ -28,6 +28,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -46,6 +47,8 @@ namespace ASC.Common.Threading
{
Cancelations = new ConcurrentDictionary<string, CancellationTokenSource>();
Cache = AscCache.Memory;
this.notify = notify;
notify.Subscribe((c) =>
@ -156,7 +159,7 @@ namespace ASC.Common.Threading
public IEnumerable<DistributedTask> GetTasks()
{
var tasks = new List<DistributedTask>(cache.HashGetAll<DistributedTask>(key).Values);
var tasks = cache.HashGetAll<DistributedTaskCache>(key).Values.Select(r => new DistributedTask(r)).ToList();
tasks.ForEach(t =>
{
if (t.Publication == null)
@ -169,7 +172,7 @@ namespace ASC.Common.Threading
public DistributedTask GetTask(string id)
{
var task = cache.HashGet<DistributedTask>(key, id);
var task = new DistributedTask(cache.HashGet<DistributedTaskCache>(key, id));
if (task != null && task.Publication == null)
{
task.Publication = GetPublication();

View File

@ -102,6 +102,8 @@ namespace ASC.Core
internal CoreBaseSettings CoreBaseSettings { get; set; }
internal CoreSettings CoreSettings { get; set; }
public Tenant CurrentTenant { get; set; }
static TenantManager()
{
thisCompAddresses.Add("localhost");
@ -215,6 +217,11 @@ namespace ASC.Core
public Tenant GetCurrentTenant(bool throwIfNotFound, HttpContext context)
{
Tenant tenant = null;
if (CurrentTenant != null)
{
return CurrentTenant;
}
if (context != null)
{
tenant = context.Items[CURRENT_TENANT] as Tenant;
@ -249,7 +256,7 @@ namespace ASC.Core
{
if (tenant != null)
{
CallContext.SetData(CURRENT_TENANT, tenant);
CurrentTenant = tenant;
if (HttpContext != null)
{
HttpContext.Items[CURRENT_TENANT] = tenant;

View File

@ -669,17 +669,18 @@ namespace ASC.Files.Core.Data
{
if (fileId == null) return null;
var fileIdString = fileId.ToString();
using (var tx = FilesDbContext.Database.BeginTransaction())
{
var fromFolders = Query(FilesDbContext.Files)
.Where(r => r.Id == (int)fileId)
.GroupBy(r => r.Id)
.SelectMany(r => r.Select(a => a.FolderId))
.Where(r => r.Id.ToString() == fileIdString)
.Select(r => r.FolderId)
.Distinct()
.ToList();
var toUpdate = Query(FilesDbContext.Files)
.Where(r => r.Id == (int)fileId);
.Where(r => r.Id.ToString() == fileIdString)
.ToList();
foreach (var f in toUpdate)
{
@ -699,9 +700,10 @@ namespace ASC.Files.Core.Data
RecalculateFilesCount(toFolderId);
}
var toFolderIdString = toFolderId.ToString();
var parentFoldersIds =
FilesDbContext.Tree
.Where(r => r.FolderId == (int)toFolderId)
.Where(r => r.FolderId.ToString() == toFolderIdString)
.OrderByDescending(r => r.Level)
.Select(r => r.ParentId)
.ToList();

View File

@ -128,8 +128,9 @@ namespace ASC.Files.Core.Data
public Folder GetRootFolderByFile(object fileId)
{
var fileIdString = fileId.ToString();
var subq = Query(FilesDbContext.Files)
.Where(r => r.Id == (int)fileId && r.CurrentVersion)
.Where(r => r.Id.ToString() == fileIdString && r.CurrentVersion)
.Select(r => r.FolderId)
.Distinct();

View File

@ -123,7 +123,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
protected FileOperation(IServiceProvider serviceProvider, T fileOperationData)
{
principal = Thread.CurrentPrincipal;
principal = serviceProvider.GetService<Microsoft.AspNetCore.Http.IHttpContextAccessor>()?.HttpContext?.User ?? Thread.CurrentPrincipal;
culture = Thread.CurrentThread.CurrentCulture.Name;
TaskInfo = new DistributedTask();
@ -204,7 +204,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
TaskInfo.SetProperty(FileOperation.SOURCE, string.Join(FileOperation.SPLIT_CHAR, Folders.Select(f => "folder_" + f).Concat(Files.Select(f => "file_" + f)).ToArray()));
TaskInfo.SetProperty(FileOperation.OPERATION_TYPE, OperationType);
TaskInfo.SetProperty(FileOperation.OWNER, ((IAccount)Thread.CurrentPrincipal.Identity).ID);
TaskInfo.SetProperty(FileOperation.OWNER, ((IAccount)(principal ?? Thread.CurrentPrincipal).Identity).ID);
TaskInfo.SetProperty(FileOperation.PROGRESS, progress < 100 ? progress : 100);
TaskInfo.SetProperty(FileOperation.RESULT, Status);
TaskInfo.SetProperty(FileOperation.ERROR, Error);