Cleanup - repository events = todo
This commit is contained in:
@@ -5,14 +5,10 @@ using NPoco;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
|
||||
using Umbraco.Core.Persistence.Factories;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
|
||||
@@ -24,8 +20,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public MemberGroupRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, IMappingResolver mappingResolver)
|
||||
: base(work, cache, logger, mappingResolver)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
private readonly MemberGroupFactory _modelFactory = new MemberGroupFactory();
|
||||
|
||||
@@ -96,10 +91,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return list;
|
||||
}
|
||||
|
||||
protected override Guid NodeObjectTypeId
|
||||
{
|
||||
get { return new Guid(Constants.ObjectTypes.MemberGroup); }
|
||||
}
|
||||
protected override Guid NodeObjectTypeId => new Guid(Constants.ObjectTypes.MemberGroup);
|
||||
|
||||
protected override void PersistNewItem(IMemberGroup entity)
|
||||
{
|
||||
@@ -107,7 +99,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var group = (MemberGroup)entity;
|
||||
group.AddingEntity();
|
||||
var dto = _modelFactory.BuildDto(group);
|
||||
var o = Database.IsNew<NodeDto>(dto) ? Convert.ToInt32(Database.Insert(dto)) : Database.Update(dto);
|
||||
var o = Database.IsNew(dto) ? Convert.ToInt32(Database.Insert(dto)) : Database.Update(dto);
|
||||
group.Id = dto.NodeId; //Set Id on entity to ensure an Id is set
|
||||
|
||||
//Update with new correct path and id
|
||||
@@ -130,7 +122,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public IMemberGroup GetByName(string name)
|
||||
{
|
||||
return RuntimeCache.GetCacheItem<IMemberGroup>(
|
||||
string.Format("{0}.{1}", typeof (IMemberGroup).FullName, name),
|
||||
typeof (IMemberGroup).FullName + "." + name,
|
||||
() =>
|
||||
{
|
||||
var qry = QueryFactory.Create<IMemberGroup>().Where(group => group.Name.Equals(name));
|
||||
@@ -161,7 +153,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return null;
|
||||
}
|
||||
|
||||
// fixme - in a repository?!
|
||||
SavedMemberGroup.RaiseEvent(new SaveEventArgs<IMemberGroup>(grp), this);
|
||||
|
||||
return grp;
|
||||
@@ -284,11 +275,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
//get the groups that are currently assigned to any of these members
|
||||
|
||||
var assignedSql = Sql()
|
||||
.Select(string.Format(
|
||||
"{0},{1},{2}",
|
||||
SqlSyntax.GetQuotedColumnName("text"),
|
||||
SqlSyntax.GetQuotedColumnName("Member"),
|
||||
SqlSyntax.GetQuotedColumnName("MemberGroup")))
|
||||
.Select($"{SqlSyntax.GetQuotedColumnName("text")},{SqlSyntax.GetQuotedColumnName("Member")},{SqlSyntax.GetQuotedColumnName("MemberGroup")}")
|
||||
.From<NodeDto>()
|
||||
.InnerJoin<Member2MemberGroupDto>()
|
||||
.On<NodeDto, Member2MemberGroupDto>(dto => dto.NodeId, dto => dto.MemberGroup)
|
||||
@@ -345,6 +332,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public int MemberGroupId { get; set; }
|
||||
}
|
||||
|
||||
// todo - understand why we need these two repository-level events, move them back to service
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
|
||||
@@ -39,17 +39,17 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="entityIds"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<EntityPermission> GetUserPermissionsForEntities(int userId, params int[] entityIds)
|
||||
{
|
||||
var entityIdKey = string.Join(",", entityIds.Select(x => x.ToString(CultureInfo.InvariantCulture)));
|
||||
return _runtimeCache.GetCacheItem<IEnumerable<EntityPermission>>(
|
||||
string.Format("{0}{1}{2}", CacheKeys.UserPermissionsCacheKey, userId, entityIdKey),
|
||||
() =>
|
||||
{
|
||||
{
|
||||
|
||||
var whereBuilder = new StringBuilder();
|
||||
|
||||
|
||||
//where userId = @userId AND
|
||||
whereBuilder.Append(SqlSyntax.GetQuotedColumnName("userId"));
|
||||
whereBuilder.Append("=");
|
||||
@@ -85,13 +85,13 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return ConvertToPermissionList(result);
|
||||
|
||||
},
|
||||
//Since this cache can be quite large (http://issues.umbraco.org/issue/U4-2161) we will only have this exist in cache for 20 minutes,
|
||||
//Since this cache can be quite large (http://issues.umbraco.org/issue/U4-2161) we will only have this exist in cache for 20 minutes,
|
||||
// then it will refresh from the database.
|
||||
new TimeSpan(0, 20, 0),
|
||||
//Since this cache can be quite large (http://issues.umbraco.org/issue/U4-2161) we will make this priority below average
|
||||
priority: CacheItemPriority.BelowNormal);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns permissions for all users for a given entity
|
||||
@@ -148,7 +148,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
_unitOfWork.Database.BulkInsertRecords(SqlSyntax, toInsert);
|
||||
|
||||
//Raise the event
|
||||
// fixme - in the repository?
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(toInsert), false), this);
|
||||
}
|
||||
@@ -181,10 +180,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
_unitOfWork.Database.BulkInsertRecords(SqlSyntax, actions);
|
||||
|
||||
//Raise the event
|
||||
// fixme - in the repo?
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assigns one permission to an entity for multiple users
|
||||
@@ -199,7 +197,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
db.Execute("DELETE FROM umbracoUser2NodePermission WHERE nodeId=@nodeId AND permission=@permission AND userId in (@userIds)",
|
||||
new
|
||||
{
|
||||
nodeId = entity.Id,
|
||||
nodeId = entity.Id,
|
||||
permission = permission.ToString(CultureInfo.InvariantCulture),
|
||||
userIds = userIds
|
||||
});
|
||||
@@ -214,7 +212,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
_unitOfWork.Database.BulkInsertRecords(SqlSyntax, actions);
|
||||
|
||||
//Raise the event
|
||||
// fixme - in the repo?!
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this);
|
||||
}
|
||||
@@ -243,7 +240,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
_unitOfWork.Database.BulkInsertRecords(SqlSyntax, actions);
|
||||
|
||||
//Raise the event
|
||||
// fixme - in the repo?
|
||||
AssignedPermissions.RaiseEvent(
|
||||
new SaveEventArgs<EntityPermission>(ConvertToPermissionList(actions), false), this);
|
||||
}
|
||||
@@ -264,6 +260,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return permissions;
|
||||
}
|
||||
|
||||
// todo - understand why we need this repository-level event, move it back to service
|
||||
|
||||
public static event TypedEventHandler<PermissionRepository<TEntity>, SaveEventArgs<EntityPermission>> AssignedPermissions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user