un-does the tag export/import, instead need to look at the internal of a simple publish (without save) to see if tags get written or not.

This commit is contained in:
Shannon
2014-06-30 17:05:34 +10:00
parent a66670263f
commit 59116fc7fa
2 changed files with 58 additions and 58 deletions

View File

@@ -270,17 +270,17 @@ namespace Umbraco.Core.Services
//set value as per normal
content.SetValue(propertyTypeAlias, propertyValue);
}
else
{
//check if this exists in tagProperties
var hasTags = tagProperties.XPathSelectElement(string.Format("//TagProperty[@docId=\"{0}\" and @propertyAlias=\"{1}\"]", id, propertyType.Alias));
if (hasTags != null)
{
var tags = JsonConvert.DeserializeObject<string[]>(hasTags.Value);
content.SetTags(propertyTypeAlias, tags, true, hasTags.Attribute("group").Value);
}
//else
//{
// //check if this exists in tagProperties
// var hasTags = tagProperties.XPathSelectElement(string.Format("//TagProperty[@docId=\"{0}\" and @propertyAlias=\"{1}\"]", id, propertyType.Alias));
// if (hasTags != null)
// {
// var tags = JsonConvert.DeserializeObject<string[]>(hasTags.Value);
// content.SetTags(propertyTypeAlias, tags, true, hasTags.Attribute("group").Value);
// }
}
//}
}
else

View File

@@ -147,63 +147,63 @@ namespace umbraco.cms.businesslogic.packager
AppendElement(documents);
//Create the TagProperties node - this is used to store a definition for all
// document properties that are tags, this ensures that we can re-import tags properly
XmlNode tagProps = _packageManifest.CreateElement("TagProperties");
////Create the TagProperties node - this is used to store a definition for all
//// document properties that are tags, this ensures that we can re-import tags properly
//XmlNode tagProps = _packageManifest.CreateElement("TagProperties");
//before we try to populate this, we'll do a quick lookup to see if any of the documents
// being exported contain published tags.
var allExportedIds = documents.SelectNodes("//@id").Cast<XmlNode>()
.Select(x => x.Value.TryConvertTo<int>())
.Where(x => x.Success)
.Select(x => x.Result)
.ToArray();
var allContentTags = new List<ITag>();
foreach (var exportedId in allExportedIds)
{
allContentTags.AddRange(
ApplicationContext.Current.Services.TagService.GetTagsForEntity(exportedId));
}
////before we try to populate this, we'll do a quick lookup to see if any of the documents
//// being exported contain published tags.
//var allExportedIds = documents.SelectNodes("//@id").Cast<XmlNode>()
// .Select(x => x.Value.TryConvertTo<int>())
// .Where(x => x.Success)
// .Select(x => x.Result)
// .ToArray();
//var allContentTags = new List<ITag>();
//foreach (var exportedId in allExportedIds)
//{
// allContentTags.AddRange(
// ApplicationContext.Current.Services.TagService.GetTagsForEntity(exportedId));
//}
//This is pretty round-about but it works. Essentially we need to get the properties that are tagged
// but to do that we need to lookup by a tag (string)
var allTaggedEntities = new List<TaggedEntity>();
foreach (var group in allContentTags.Select(x => x.Group).Distinct())
{
allTaggedEntities.AddRange(
ApplicationContext.Current.Services.TagService.GetTaggedContentByTagGroup(group));
}
////This is pretty round-about but it works. Essentially we need to get the properties that are tagged
//// but to do that we need to lookup by a tag (string)
//var allTaggedEntities = new List<TaggedEntity>();
//foreach (var group in allContentTags.Select(x => x.Group).Distinct())
//{
// allTaggedEntities.AddRange(
// ApplicationContext.Current.Services.TagService.GetTaggedContentByTagGroup(group));
//}
//Now, we have all property Ids/Aliases and their referenced document Ids and tags
var allExportedTaggedEntities = allTaggedEntities.Where(x => allExportedIds.Contains(x.EntityId))
.DistinctBy(x => x.EntityId)
.OrderBy(x => x.EntityId);
////Now, we have all property Ids/Aliases and their referenced document Ids and tags
//var allExportedTaggedEntities = allTaggedEntities.Where(x => allExportedIds.Contains(x.EntityId))
// .DistinctBy(x => x.EntityId)
// .OrderBy(x => x.EntityId);
foreach (var taggedEntity in allExportedTaggedEntities)
{
foreach (var taggedProperty in taggedEntity.TaggedProperties.Where(x => x.Tags.Any()))
{
XmlNode tagProp = _packageManifest.CreateElement("TagProperty");
var docId = _packageManifest.CreateAttribute("docId", "");
docId.Value = taggedEntity.EntityId.ToString(CultureInfo.InvariantCulture);
tagProp.Attributes.Append(docId);
//foreach (var taggedEntity in allExportedTaggedEntities)
//{
// foreach (var taggedProperty in taggedEntity.TaggedProperties.Where(x => x.Tags.Any()))
// {
// XmlNode tagProp = _packageManifest.CreateElement("TagProperty");
// var docId = _packageManifest.CreateAttribute("docId", "");
// docId.Value = taggedEntity.EntityId.ToString(CultureInfo.InvariantCulture);
// tagProp.Attributes.Append(docId);
var propertyAlias = _packageManifest.CreateAttribute("propertyAlias", "");
propertyAlias.Value = taggedProperty.PropertyTypeAlias;
tagProp.Attributes.Append(propertyAlias);
// var propertyAlias = _packageManifest.CreateAttribute("propertyAlias", "");
// propertyAlias.Value = taggedProperty.PropertyTypeAlias;
// tagProp.Attributes.Append(propertyAlias);
var group = _packageManifest.CreateAttribute("group", "");
group.Value = taggedProperty.Tags.First().Group;
tagProp.Attributes.Append(group);
// var group = _packageManifest.CreateAttribute("group", "");
// group.Value = taggedProperty.Tags.First().Group;
// tagProp.Attributes.Append(group);
tagProp.AppendChild(_packageManifest.CreateCDataSection(
JsonConvert.SerializeObject(taggedProperty.Tags.Select(x => x.Text).ToArray())));
// tagProp.AppendChild(_packageManifest.CreateCDataSection(
// JsonConvert.SerializeObject(taggedProperty.Tags.Select(x => x.Text).ToArray())));
tagProps.AppendChild(tagProp);
}
}
// tagProps.AppendChild(tagProp);
// }
//}
AppendElement(tagProps);
//AppendElement(tagProps);
}
}