Adds tag support for any IContentBase and to the MediaRepository, adds test to ensure tags relations are removed.
This commit is contained in:
@@ -537,7 +537,7 @@ namespace Umbraco.Core.Models
|
||||
/// <param name="replaceTags">True to replace the tags on the current property with the tags specified or false to merge them with the currently assigned ones</param>
|
||||
/// <param name="tagGroup">The group/category to assign the tags, the default value is "default"</param>
|
||||
/// <returns></returns>
|
||||
public static void SetTags(this IContent content, string propertyTypeAlias, IEnumerable<string> tags, bool replaceTags, string tagGroup = "default")
|
||||
public static void SetTags(this IContentBase content, string propertyTypeAlias, IEnumerable<string> tags, bool replaceTags, string tagGroup = "default")
|
||||
{
|
||||
var property = content.Properties[propertyTypeAlias];
|
||||
if (property == null)
|
||||
@@ -572,7 +572,7 @@ namespace Umbraco.Core.Models
|
||||
/// <param name="propertyTypeAlias"></param>
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="tagGroup">The group/category that the tags are currently assigned to, the default value is "default"</param>
|
||||
public static void RemoveTags(this IContent content, string propertyTypeAlias, IEnumerable<string> tags, string tagGroup = "default")
|
||||
public static void RemoveTags(this IContentBase content, string propertyTypeAlias, IEnumerable<string> tags, string tagGroup = "default")
|
||||
{
|
||||
var property = content.Properties[propertyTypeAlias];
|
||||
if (property == null)
|
||||
|
||||
@@ -28,6 +28,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public ContentRepository(IDatabaseUnitOfWork work, IContentTypeRepository contentTypeRepository, ITemplateRepository templateRepository, ITagsRepository tagRepository)
|
||||
: base(work)
|
||||
{
|
||||
if (contentTypeRepository == null) throw new ArgumentNullException("contentTypeRepository");
|
||||
if (templateRepository == null) throw new ArgumentNullException("templateRepository");
|
||||
if (tagRepository == null) throw new ArgumentNullException("tagRepository");
|
||||
_contentTypeRepository = contentTypeRepository;
|
||||
_templateRepository = templateRepository;
|
||||
_tagRepository = tagRepository;
|
||||
@@ -38,6 +41,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public ContentRepository(IDatabaseUnitOfWork work, IRepositoryCacheProvider cache, IContentTypeRepository contentTypeRepository, ITemplateRepository templateRepository, ITagsRepository tagRepository)
|
||||
: base(work, cache)
|
||||
{
|
||||
if (contentTypeRepository == null) throw new ArgumentNullException("contentTypeRepository");
|
||||
if (templateRepository == null) throw new ArgumentNullException("templateRepository");
|
||||
if (tagRepository == null) throw new ArgumentNullException("tagRepository");
|
||||
_contentTypeRepository = contentTypeRepository;
|
||||
_templateRepository = templateRepository;
|
||||
_tagRepository = tagRepository;
|
||||
|
||||
@@ -20,19 +20,26 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
internal class MediaRepository : VersionableRepositoryBase<int, IMedia>, IMediaRepository
|
||||
{
|
||||
private readonly IMediaTypeRepository _mediaTypeRepository;
|
||||
private readonly ITagsRepository _tagRepository;
|
||||
|
||||
public MediaRepository(IDatabaseUnitOfWork work, IMediaTypeRepository mediaTypeRepository)
|
||||
public MediaRepository(IDatabaseUnitOfWork work, IMediaTypeRepository mediaTypeRepository, ITagsRepository tagRepository)
|
||||
: base(work)
|
||||
{
|
||||
if (mediaTypeRepository == null) throw new ArgumentNullException("mediaTypeRepository");
|
||||
if (tagRepository == null) throw new ArgumentNullException("tagRepository");
|
||||
_mediaTypeRepository = mediaTypeRepository;
|
||||
_tagRepository = tagRepository;
|
||||
|
||||
EnsureUniqueNaming = true;
|
||||
}
|
||||
|
||||
public MediaRepository(IDatabaseUnitOfWork work, IRepositoryCacheProvider cache, IMediaTypeRepository mediaTypeRepository)
|
||||
public MediaRepository(IDatabaseUnitOfWork work, IRepositoryCacheProvider cache, IMediaTypeRepository mediaTypeRepository, ITagsRepository tagRepository)
|
||||
: base(work, cache)
|
||||
{
|
||||
if (mediaTypeRepository == null) throw new ArgumentNullException("mediaTypeRepository");
|
||||
if (tagRepository == null) throw new ArgumentNullException("tagRepository");
|
||||
_mediaTypeRepository = mediaTypeRepository;
|
||||
_tagRepository = tagRepository;
|
||||
|
||||
EnsureUniqueNaming = true;
|
||||
}
|
||||
@@ -247,6 +254,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
property.Id = keyDictionary[property.PropertyTypeId];
|
||||
}
|
||||
|
||||
UpdatePropertyTags(entity);
|
||||
|
||||
((ICanBeDirty)entity).ResetDirtyProperties();
|
||||
}
|
||||
|
||||
@@ -324,6 +333,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
}
|
||||
|
||||
UpdatePropertyTags(entity);
|
||||
|
||||
((ICanBeDirty)entity).ResetDirtyProperties();
|
||||
}
|
||||
|
||||
@@ -359,6 +370,34 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Updates the tag repository with any tag enabled properties and their values
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
private void UpdatePropertyTags(IContentBase entity)
|
||||
{
|
||||
foreach (var tagProp in entity.Properties.Where(x => x.TagSupport.Enable))
|
||||
{
|
||||
if (tagProp.TagSupport.Behavior == PropertyTagBehavior.Remove)
|
||||
{
|
||||
//remove the specific tags
|
||||
_tagRepository.RemovePublishedTagsFromProperty(
|
||||
entity.Id,
|
||||
tagProp.Alias,
|
||||
tagProp.TagSupport.Tags.Select(x => new Tag { Text = x.Item1, Group = x.Item2 }));
|
||||
}
|
||||
else
|
||||
{
|
||||
//assign the tags
|
||||
_tagRepository.AssignPublishedTagsToProperty(
|
||||
entity.Id,
|
||||
tagProp.Alias,
|
||||
tagProp.TagSupport.Tags.Select(x => new Tag { Text = x.Item1, Group = x.Item2 }),
|
||||
tagProp.TagSupport.Behavior == PropertyTagBehavior.Replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PropertyCollection GetPropertyCollection(int id, Guid versionId, IMediaType contentType, DateTime createDate, DateTime updateDate)
|
||||
{
|
||||
var sql = new Sql();
|
||||
|
||||
@@ -27,7 +27,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
internal RepositoryBase(IUnitOfWork work, IRepositoryCacheProvider cache)
|
||||
{
|
||||
_work = work;
|
||||
if (work == null) throw new ArgumentNullException("work");
|
||||
if (cache == null) throw new ArgumentNullException("cache");
|
||||
_work = work;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,8 @@ namespace Umbraco.Core.Persistence
|
||||
return new MediaRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
CreateMediaTypeRepository(uow)) { EnsureUniqueNaming = _settings.Content.EnsureUniqueNaming };
|
||||
CreateMediaTypeRepository(uow),
|
||||
CreateTagsRepository(uow)) { EnsureUniqueNaming = _settings.Content.EnsureUniqueNaming };
|
||||
}
|
||||
|
||||
public virtual IMediaTypeRepository CreateMediaTypeRepository(IDatabaseUnitOfWork uow)
|
||||
|
||||
Reference in New Issue
Block a user