I'm attempting to replicate Umbraco's (Umbraco v7) process of updating a node name when there is an existing node with the same name.
But in this case, I'm building an archive process which will copy the node from Umbraco database into an archived database. The issue I'm facing is trying to make the URL's unique as I'll need to do the look-up against my archive to ensure the node name is unique.
Currently I'm firing a custom save method when the Umbraco save event is triggered which looks up the name against the archive and checks if the URL is unique
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Saving += ContentService_Saving;
}
void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<IContent> e)
{
// create the content global ID
foreach (var entity in e.SavedEntities)
{
var url = Helper.GetNiceUrlPath(entity);
// fetch all items from the database with that name + url
var result = AppArchiver.GetContentByUrl(Helper.CreateUrlFromName(entity.Name)).ToList();
if(result.Any())
{
// do something here with the name if possible?
}
if (!entity.HasAppId())
{
entity.SetAppId();
}
}
}
I can't set the Name as its read only property... I can't set it using entity.SetValue("name", "blah (1)")
So what's my best bet to do this? Any suggestions? Because I'm banging my head against the wall searching through the Umbraco source code trying to work out how they do it.
The reason for storing these nodes in a database is because around 300 new nodes will be created a month and that will be unbearable to navigate them in Umbraco.
UPDATE: OK so it appears Umbraco does the URL unique check in the angular code before the item is posted back to the backend for saving. I'll have to create a service that does this if possible.