Gets sln building and manually merges the entity/media service changes
This commit is contained in:
@@ -4,6 +4,7 @@ using Umbraco.Core.Migrations.Expressions.Alter.Expressions;
|
||||
using Umbraco.Core.Migrations.Expressions.Common.Expressions;
|
||||
using Umbraco.Core.Migrations.Expressions.Create.Expressions;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.DatabaseAnnotations;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
|
||||
namespace Umbraco.Core.Migrations.Expressions.Alter.Table
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Data;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Migrations.Expressions.Common.Expressions;
|
||||
using Umbraco.Core.Persistence.DatabaseAnnotations;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
|
||||
namespace Umbraco.Core.Migrations.Expressions.Create.Column
|
||||
|
||||
@@ -3,6 +3,7 @@ using NPoco;
|
||||
using Umbraco.Core.Migrations.Expressions.Common.Expressions;
|
||||
using Umbraco.Core.Migrations.Expressions.Create.Expressions;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.DatabaseAnnotations;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
|
||||
namespace Umbraco.Core.Migrations.Expressions.Create.Table
|
||||
|
||||
@@ -302,6 +302,9 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
// more dark magic ;-(
|
||||
internal static bool TryMatch(string text, out string path)
|
||||
{
|
||||
//fixme: In v8 we should allow exposing this via the property editor in a much nicer way so that the property editor
|
||||
// can tell us directly what any URL is for a given property if it contains an asset
|
||||
|
||||
path = null;
|
||||
if (string.IsNullOrWhiteSpace(text)) return false;
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
if (isContent)
|
||||
BuildVariants(entities.Cast<DocumentEntitySlim>());
|
||||
|
||||
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media
|
||||
if (isMedia)
|
||||
BuildProperties(entities, dtos);
|
||||
|
||||
@@ -110,14 +111,14 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
return GetEntity(sql, isContent, isMedia);
|
||||
}
|
||||
|
||||
public virtual IEntitySlim Get(int id)
|
||||
public IEntitySlim Get(int id)
|
||||
{
|
||||
var sql = GetBaseWhere(false, false, false, id);
|
||||
var dto = Database.FirstOrDefault<BaseDto>(sql);
|
||||
return dto == null ? null : BuildEntity(false, false, dto);
|
||||
}
|
||||
|
||||
public virtual IEntitySlim Get(int id, Guid objectTypeId)
|
||||
public IEntitySlim Get(int id, Guid objectTypeId)
|
||||
{
|
||||
var isContent = objectTypeId == Constants.ObjectTypes.Document || objectTypeId == Constants.ObjectTypes.DocumentBlueprint;
|
||||
var isMedia = objectTypeId == Constants.ObjectTypes.Media;
|
||||
@@ -126,21 +127,21 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
return GetEntity(sql, isContent, isMedia);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<IEntitySlim> GetAll(Guid objectType, params int[] ids)
|
||||
public IEnumerable<IEntitySlim> GetAll(Guid objectType, params int[] ids)
|
||||
{
|
||||
return ids.Length > 0
|
||||
? PerformGetAll(objectType, sql => sql.WhereIn<NodeDto>(x => x.NodeId, ids.Distinct()))
|
||||
: PerformGetAll(objectType);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<IEntitySlim> GetAll(Guid objectType, params Guid[] keys)
|
||||
public IEnumerable<IEntitySlim> GetAll(Guid objectType, params Guid[] keys)
|
||||
{
|
||||
return keys.Length > 0
|
||||
? PerformGetAll(objectType, sql => sql.WhereIn<NodeDto>(x => x.UniqueId, keys.Distinct()))
|
||||
: PerformGetAll(objectType);
|
||||
}
|
||||
|
||||
private IEnumerable<IEntitySlim> GetEntities(Sql<ISqlContext> sql, bool isContent, bool isMedia)
|
||||
private IEnumerable<IEntitySlim> GetEntities(Sql<ISqlContext> sql, bool isContent, bool isMedia, bool loadMediaProperties)
|
||||
{
|
||||
//isContent is going to return a 1:M result now with the variants so we need to do different things
|
||||
if (isContent)
|
||||
@@ -157,7 +158,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
var entities = dtos.Select(x => BuildEntity(false, isMedia, x)).ToArray();
|
||||
|
||||
if (isMedia)
|
||||
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media
|
||||
if (isMedia && loadMediaProperties)
|
||||
BuildProperties(entities, dtos);
|
||||
|
||||
return entities;
|
||||
@@ -169,17 +171,17 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
var isMedia = objectType == Constants.ObjectTypes.Media;
|
||||
|
||||
var sql = GetFullSqlForEntityType(isContent, isMedia, objectType, filter);
|
||||
return GetEntities(sql, isContent, isMedia);
|
||||
return GetEntities(sql, isContent, isMedia, true);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TreeEntityPath> GetAllPaths(Guid objectType, params int[] ids)
|
||||
public IEnumerable<TreeEntityPath> GetAllPaths(Guid objectType, params int[] ids)
|
||||
{
|
||||
return ids.Any()
|
||||
? PerformGetAllPaths(objectType, sql => sql.WhereIn<NodeDto>(x => x.NodeId, ids.Distinct()))
|
||||
: PerformGetAllPaths(objectType);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TreeEntityPath> GetAllPaths(Guid objectType, params Guid[] keys)
|
||||
public IEnumerable<TreeEntityPath> GetAllPaths(Guid objectType, params Guid[] keys)
|
||||
{
|
||||
return keys.Any()
|
||||
? PerformGetAllPaths(objectType, sql => sql.WhereIn<NodeDto>(x => x.UniqueId, keys.Distinct()))
|
||||
@@ -193,7 +195,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
return Database.Fetch<TreeEntityPath>(sql);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<IEntitySlim> GetByQuery(IQuery<IUmbracoEntity> query)
|
||||
public IEnumerable<IEntitySlim> GetByQuery(IQuery<IUmbracoEntity> query)
|
||||
{
|
||||
var sqlClause = GetBase(false, false, null);
|
||||
var translator = new SqlTranslator<IUmbracoEntity>(sqlClause, query);
|
||||
@@ -203,7 +205,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
return dtos.Select(x => BuildEntity(false, false, x)).ToList();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<IEntitySlim> GetByQuery(IQuery<IUmbracoEntity> query, Guid objectType)
|
||||
public IEnumerable<IEntitySlim> GetByQuery(IQuery<IUmbracoEntity> query, Guid objectType)
|
||||
{
|
||||
var isContent = objectType == Constants.ObjectTypes.Document || objectType == Constants.ObjectTypes.DocumentBlueprint;
|
||||
var isMedia = objectType == Constants.ObjectTypes.Media;
|
||||
@@ -214,7 +216,22 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
sql = translator.Translate();
|
||||
sql = AddGroupBy(isContent, isMedia, sql);
|
||||
|
||||
return GetEntities(sql, isContent, isMedia);
|
||||
return GetEntities(sql, isContent, isMedia, true);
|
||||
}
|
||||
|
||||
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media
|
||||
internal IEnumerable<IEntitySlim> GetMediaByQueryWithoutPropertyData(IQuery<IUmbracoEntity> query)
|
||||
{
|
||||
var isContent = false;
|
||||
var isMedia = true;
|
||||
|
||||
var sql = GetBaseWhere(isContent, isMedia, false, null, Constants.ObjectTypes.Media);
|
||||
|
||||
var translator = new SqlTranslator<IUmbracoEntity>(sql, query);
|
||||
sql = translator.Translate();
|
||||
sql = AddGroupBy(isContent, isMedia, sql);
|
||||
|
||||
return GetEntities(sql, isContent, isMedia, false);
|
||||
}
|
||||
|
||||
public UmbracoObjectTypes GetObjectType(int id)
|
||||
@@ -241,6 +258,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
return Database.ExecuteScalar<int>(sql) > 0;
|
||||
}
|
||||
|
||||
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media
|
||||
private void BuildProperties(EntitySlim entity, BaseDto dto)
|
||||
{
|
||||
var pdtos = Database.Fetch<PropertyDataDto>(GetPropertyData(dto.VersionId));
|
||||
@@ -248,6 +266,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
BuildProperty(entity, pdto);
|
||||
}
|
||||
|
||||
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media
|
||||
private void BuildProperties(EntitySlim[] entities, List<BaseDto> dtos)
|
||||
{
|
||||
var versionIds = dtos.Select(x => x.VersionId).Distinct().ToList();
|
||||
@@ -263,6 +282,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
}
|
||||
}
|
||||
|
||||
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media
|
||||
private void BuildProperty(EntitySlim entity, PropertyDataDto pdto)
|
||||
{
|
||||
// explain ?!
|
||||
|
||||
@@ -10,15 +10,6 @@ using Umbraco.Core.Persistence.Querying;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Moves an <see cref="IMedia"/> object to a new location
|
||||
/// </summary>
|
||||
/// <param name="media">The <see cref="IMedia"/> to move</param>
|
||||
/// <param name="parentId">Id of the Media's new Parent</param>
|
||||
/// <param name="userId">Id of the User moving the Media</param>
|
||||
/// <returns>True if moving succeeded, otherwise False</returns>
|
||||
Attempt<OperationStatus> Move(IMedia media, int parentId, int userId = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Defines the Media Service, which is an easy access to operations involving <see cref="IMedia"/>
|
||||
/// </summary>
|
||||
@@ -160,9 +151,9 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="media">The <see cref="IMedia"/> to move</param>
|
||||
/// <param name="parentId">Id of the Media's new Parent</param>
|
||||
/// <param name="userId">Id of the User moving the Media</param>
|
||||
void Move(IMedia media, int parentId, int userId = 0);
|
||||
/// <returns>True if moving succeeded, otherwise False</returns>
|
||||
Attempt<OperationResult> Move(IMedia media, int parentId, int userId = 0);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an <see cref="IMedia"/> object by moving it to the Recycle Bin
|
||||
/// </summary>
|
||||
|
||||
@@ -11,6 +11,7 @@ using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.Repositories.Implement;
|
||||
using Umbraco.Core.Scoping;
|
||||
|
||||
namespace Umbraco.Core.Services.Implement
|
||||
@@ -373,6 +374,22 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of children by the parent's Id and UmbracoObjectType without adding property data
|
||||
/// </summary>
|
||||
/// <param name="parentId">Id of the parent to retrieve children for</param>
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
internal IEnumerable<IEntitySlim> GetMediaChildrenWithoutPropertyData(int parentId)
|
||||
{
|
||||
using (ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
var query = Query<IUmbracoEntity>().Where(x => x.ParentId == parentId);
|
||||
|
||||
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media
|
||||
return ((EntityRepository)_entityRepository).GetMediaByQueryWithoutPropertyData(query);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual IEnumerable<IEntitySlim> GetDescendants(int id)
|
||||
{
|
||||
|
||||
@@ -888,7 +888,8 @@ namespace Umbraco.Core.Services.Implement
|
||||
|
||||
var originalPath = media.Path;
|
||||
|
||||
if (scope.Events.DispatchCancelable(Trashing, this, new MoveEventArgs<IMedia>(new MoveEventInfo<IMedia>(media, originalPath, Constants.System.RecycleBinMedia)), nameof(Trashing)))
|
||||
var moveEventArgs = new MoveEventArgs<IMedia>(true, evtMsgs, new MoveEventInfo<IMedia>(media, originalPath, Constants.System.RecycleBinMedia));
|
||||
if (scope.Events.DispatchCancelable(Trashing, this, moveEventArgs, nameof(Trashing)))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Attempt.Cancel(evtMsgs);
|
||||
@@ -899,8 +900,9 @@ namespace Umbraco.Core.Services.Implement
|
||||
scope.Events.Dispatch(TreeChanged, this, new TreeChange<IMedia>(media, TreeChangeTypes.RefreshBranch).ToEventArgs());
|
||||
var moveInfo = moves.Select(x => new MoveEventInfo<IMedia>(x.Item1, x.Item2, x.Item1.ParentId))
|
||||
.ToArray();
|
||||
|
||||
scope.Events.Dispatch(Trashed, this, new MoveEventArgs<IMedia>(false, evtMsgs, moveInfo), nameof(Trashed));
|
||||
moveEventArgs.MoveInfoCollection = moveInfo;
|
||||
moveEventArgs.CanCancel = false;
|
||||
scope.Events.Dispatch(Trashed, this, moveEventArgs, nameof(Trashed));
|
||||
Audit(AuditType.Move, userId, media.Id, "Move Media to recycle bin");
|
||||
|
||||
scope.Complete();
|
||||
@@ -915,13 +917,15 @@ namespace Umbraco.Core.Services.Implement
|
||||
/// <param name="media">The <see cref="IMedia"/> to move</param>
|
||||
/// <param name="parentId">Id of the Media's new Parent</param>
|
||||
/// <param name="userId">Id of the User moving the Media</param>
|
||||
public void Move(IMedia media, int parentId, int userId = 0)
|
||||
public Attempt<OperationResult> Move(IMedia media, int parentId, int userId = 0)
|
||||
{
|
||||
var evtMsgs = EventMessagesFactory.Get();
|
||||
|
||||
// if moving to the recycle bin then use the proper method
|
||||
if (parentId == Constants.System.RecycleBinMedia)
|
||||
{
|
||||
MoveToRecycleBin(media, userId);
|
||||
return;
|
||||
return OperationResult.Attempt.Succeed(evtMsgs);
|
||||
}
|
||||
|
||||
var moves = new List<Tuple<IMedia, string>>();
|
||||
@@ -935,11 +939,11 @@ namespace Umbraco.Core.Services.Implement
|
||||
throw new InvalidOperationException("Parent does not exist or is trashed."); // causes rollback // causes rollback
|
||||
|
||||
var moveEventInfo = new MoveEventInfo<IMedia>(media, media.Path, parentId);
|
||||
var moveEventArgs = new MoveEventArgs<IMedia>(moveEventInfo);
|
||||
var moveEventArgs = new MoveEventArgs<IMedia>(true, evtMsgs, moveEventInfo);
|
||||
if (scope.Events.DispatchCancelable(Moving, this, moveEventArgs, nameof(Moving)))
|
||||
{
|
||||
scope.Complete();
|
||||
return;
|
||||
return OperationResult.Attempt.Cancel(evtMsgs);
|
||||
}
|
||||
|
||||
// if media was trashed, and since we're not moving to the recycle bin,
|
||||
@@ -964,6 +968,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
Audit(AuditType.Move, userId, media.Id);
|
||||
scope.Complete();
|
||||
}
|
||||
return OperationResult.Attempt.Succeed(evtMsgs);
|
||||
}
|
||||
|
||||
// MUST be called from within WriteLock
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace Umbraco.Web.Editors
|
||||
Services.ContentTypeService.Save(collectionDocType);
|
||||
|
||||
// test if the parent exist and then allow the collection underneath
|
||||
var parentCt = Services.ContentTypeService.GetContentType(parentId);
|
||||
var parentCt = Services.ContentTypeService.Get(parentId);
|
||||
if (parentCt != null)
|
||||
{
|
||||
var allowedCts = parentCt.AllowedContentTypes.ToList();
|
||||
|
||||
@@ -427,7 +427,7 @@ namespace Umbraco.Web.Editors
|
||||
var destinationParentID = move.ParentId;
|
||||
var sourceParentID = toMove.ParentId;
|
||||
|
||||
var moveResult = Services.MediaService.WithResult().Move(toMove, move.ParentId);
|
||||
var moveResult = Services.MediaService.Move(toMove, move.ParentId);
|
||||
|
||||
if (sourceParentID == destinationParentID)
|
||||
{
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnWithException<PasswordChanger>("Could not change member password", ex);
|
||||
_logger.Warn<PasswordChanger>("Could not change member password", ex);
|
||||
return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex.Message + " (see log for full details)", new[] { "value" }) });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace Umbraco.Web.Trees
|
||||
return HasPathAccess(entity, queryStrings);
|
||||
}
|
||||
|
||||
internal override IEnumerable<IUmbracoEntity> GetChildrenFromEntityService(int entityId)
|
||||
internal override IEnumerable<IEntitySlim> GetChildrenFromEntityService(int entityId)
|
||||
=> Services.EntityService.GetChildren(entityId, UmbracoObjectType).ToList();
|
||||
|
||||
protected override IEnumerable<IEntitySlim> GetChildEntities(string id, FormDataCollection queryStrings)
|
||||
|
||||
@@ -197,9 +197,8 @@ namespace Umbraco.Web.Trees
|
||||
entityId = entity.Id;
|
||||
}
|
||||
|
||||
return GetChildrenFromEntityService(entityId);
|
||||
IEntitySlim[] result;
|
||||
|
||||
/*
|
||||
// if a request is made for the root node but user has no access to
|
||||
// root node, return start nodes instead
|
||||
if (entityId == Constants.System.Root && UserStartNodes.Contains(Constants.System.Root) == false)
|
||||
@@ -210,10 +209,10 @@ namespace Umbraco.Web.Trees
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Services.EntityService.GetChildren(entityId, UmbracoObjectType).ToArray();
|
||||
result = GetChildrenFromEntityService(entityId).ToArray();
|
||||
}
|
||||
|
||||
return result;*/
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -221,7 +220,7 @@ namespace Umbraco.Web.Trees
|
||||
/// </summary>
|
||||
/// <param name="entityId"></param>
|
||||
/// <returns></returns>
|
||||
internal abstract IEnumerable<IUmbracoEntity> GetChildrenFromEntityService(int entityId);
|
||||
internal abstract IEnumerable<IEntitySlim> GetChildrenFromEntityService(int entityId);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true or false if the current user has access to the node based on the user's allowed start node (path) access
|
||||
|
||||
@@ -17,6 +17,7 @@ using Umbraco.Web.WebApi.Filters;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Search;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
|
||||
namespace Umbraco.Web.Trees
|
||||
{
|
||||
@@ -163,7 +164,7 @@ namespace Umbraco.Web.Trees
|
||||
return _treeSearcher.ExamineSearch(Umbraco, query, UmbracoEntityTypes.Media, pageSize, pageIndex, out totalFound, searchFrom);
|
||||
}
|
||||
|
||||
internal override IEnumerable<IUmbracoEntity> GetChildrenFromEntityService(int entityId)
|
||||
internal override IEnumerable<IEntitySlim> GetChildrenFromEntityService(int entityId)
|
||||
// Not pretty having to cast the service, but it is the only way to get to use an internal method that we
|
||||
// do not want to make public on the interface. Unfortunately also prevents this from being unit tested.
|
||||
// See this issue for details on why we need this:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//TODO: Rebuild with new tree format and apis and then remove
|
||||
using umbraco.uicontrols;
|
||||
//using umbraco.uicontrols;
|
||||
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
|
||||
Reference in New Issue
Block a user