I wonder if you can help me out. I'm using uSync and included the contentHandler in the sync. This means I'm also pushing out some content node updates. Problem is there are some nodes that hold data that cannot be overwritten. I have 2 questions for this:
1.) How can I specify which content nodes to include on the sync?
2.) How can I exclude certain node properties/ property groups in the sync?
To do this you will have to intercept some of the notifications that uSync fires when it imports/exports an item.
I think the simplest way might be to have a Notification Handler that handles the uSyncImportingItemNotification event, and then remove the properties by name from the node xml this passes ?
something like (sorry haven't had chance to actually test this code)
public class NotificationTest : INotificationHandler<uSyncImportingItemNotification>
{
private static string[] dontImportItems = new[]
{
"twitterUsername", "sku"
};
public void Handle(uSyncImportingItemNotification notification)
{
var properties = notification.Item.Element("Properties");
foreach(var element in properties.Elements())
{
if (dontImportItems.InvariantContains(element.Name.LocalName))
element.Remove();
}
}
}
for content uSync won't remove values that aren't in the xml, so by taking them out of the content xml - usync will ignore them on import (it only removes properties if they are missing from the doctype xml)
Thank you for the quick response. I will try the suggestion. Just a follow-up question. Where does this code have to sit in order for the intercept to fire. Will a Composer work or it should be someplace else?
Just to give an update on my progress. I haven't tried using the INotificationHandler route yet but I got curious by your comment that if I remove the XML property, that portion will not be imported. So tested it and it turns out it works:
However, If I remove just one of the properties, e.g., {"bgStyle":"solid"}, content import detects that as removing of the value on the target site which instead of leaving it alone. Perhaps, instead of removing it, I can assign empty value?
Anyway, as you can see I have some more testing to do. I'll also let you know once I've tried that INotificationHandler option.
USync Node and Property Level Exclusion
Hello Our,
I wonder if you can help me out. I'm using uSync and included the contentHandler in the sync. This means I'm also pushing out some content node updates. Problem is there are some nodes that hold data that cannot be overwritten. I have 2 questions for this:
1.) How can I specify which content nodes to include on the sync? 2.) How can I exclude certain node properties/ property groups in the sync?
I'm using:
Thanks in advance
Francis
Hi Fancis,
There is inbuilt config to ignore content on a path / doctype level but not properties or property groups :(
To do this you will have to intercept some of the notifications that uSync fires when it imports/exports an item.
I think the simplest way might be to have a Notification Handler that handles the
uSyncImportingItemNotification
event, and then remove the properties by name from the node xml this passes ?something like (sorry haven't had chance to actually test this code)
for content uSync won't remove values that aren't in the xml, so by taking them out of the content xml - usync will ignore them on import (it only removes properties if they are missing from the doctype xml)
Kevin
Hi Kevin,
Thank you for the quick response. I will try the suggestion. Just a follow-up question. Where does this code have to sit in order for the intercept to fire. Will a Composer work or it should be someplace else?
Regards,
Francis
Hi yes, you need to register the event in a composer.
e.g
I appreciate the help Kevin. I will try these suggestions and get back to you.
Thanks!
Hi Kevin,
Just to give an update on my progress. I haven't tried using the INotificationHandler route yet but I got curious by your comment that if I remove the XML property, that portion will not be imported. So tested it and it turns out it works:
So in this example, if I remove the entire "
However, If I remove just one of the properties, e.g., {"bgStyle":"solid"}, content import detects that as removing of the value on the target site which instead of leaving it alone. Perhaps, instead of removing it, I can assign empty value?
Anyway, as you can see I have some more testing to do. I'll also let you know once I've tried that INotificationHandler option.
Thanks.
is working on a reply...