I have a question around the Config for Sync Source.
In the config settings you have the Sync Source setting where it saves any changes to disk. Can you tell me is this change is when you Save or when you Save and Publish?
If it is only when you Save, is there any way to modify the code so that it only writes to the disk when you Save and Publish?
The default is when you save (so also save and publish) - mainly because uSync deals with a lot of things that don't have the concept of publish so only save.
but you could extend it with your own code to be only publish (for content). first you would want to turn of save events.
you can then work through any items that are published, get the XML from uSync and save it how you wish.
private void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
{
foreach (var item in e.PublishedEntities)
{
var attempt = uSyncCoreContext.Instance.ContentSerializer.Serialize(item);
if (attempt.Success)
{
// at this point the attempt.item value is an XElement
// so you can save it somethere
// uSync builds a path based on parents, but if doesn't
// have to be that it can be anything
attempt.Item.Save("some/file/path");
}
}
}
uSync has a GetContentPath function which builds a path based on the node names, but it can be anything.
and if you did save this into the uSync/Content then a importing usync at the other end would import the content (which is i suspect what you want to do ?)
the actual folder names in the don't matter when it comes to importing all the data comes from the files.
the only thing to note about the folder structure if you are importing is that there there something to ensure the parent nodes are higher then their child nodes so they get imported first.
Sync Source config. Writes to disk on Save or Save and Publish?
I have a question around the Config for Sync Source.
In the config settings you have the Sync Source setting where it saves any changes to disk. Can you tell me is this change is when you Save or when you Save and Publish?
If it is only when you Save, is there any way to modify the code so that it only writes to the disk when you Save and Publish?
Thanks Darren
Hi Darren,
The default is when you save (so also save and publish) - mainly because uSync deals with a lot of things that don't have the concept of publish so only save.
but you could extend it with your own code to be only publish (for content). first you would want to turn of save events.
so if you register for umbraco's publish event :
you can then work through any items that are published, get the XML from uSync and save it how you wish.
uSync has a
GetContentPath
function which builds a path based on the node names, but it can be anything.and if you did save this into the uSync/Content then a importing usync at the other end would import the content (which is i suspect what you want to do ?)
the actual folder names in the don't matter when it comes to importing all the data comes from the files.
the only thing to note about the folder structure if you are importing is that there there something to ensure the parent nodes are higher then their child nodes so they get imported first.
Also worth noting if you don't want to turn the export of for everything then it can be done on a per handler basis - see the docs for some info.
https://usync.readthedocs.io/handler-config/
but without turning off the main
ExportOnSave
setting you could just turn off saves of content withwhich will just stop the built-in content handler from doing anything on that instance of the site. while everything else would still export on save.
is working on a reply...