uSync.BackOffice 3.2.2.740, uSync.Core 5.5.2.740, Umbraco version 7.5.3 assembly: 1.0.6092.24019
I'm running into problems importing existing templates that have been renamed. It results in the following exception:
System.Data.SqlClient.SqlException (0x80131904): Cannot insert duplicate key row in object 'dbo.umbracoNode' with unique index 'IX_umbracoNodeUniqueID'. The duplicate key value is (1269d938-baa2-4bcd-838c-ab3210a4d018).
The statement has been terminated.
I have a feeling this is because I'm abusing uSync rather than a bug but I would appreciate any pointers.
I installed a copy of Umbraco as an Azure app and installed the Faroe starter package. I then exported the database from Azure to a local database and set up my local development version (copied Umbraco files over as well).
At this point the local and Azure versions were both identical and working as expected.
I then renamed a local master template from Test > Test2. I then published this to Azure making sure the /uSync/data directory contained the renamed template. There was no "Test.config" template but there was a "Test2.config".
The changes were detected by the report and I can see it says to rename the template. When I click import it errors with the above exception.
Am I doing this wrong?
EDIT:
I've been debugging the uSync source and found that when _fileService.SaveTemplate inside TemplateSerializer is called the ITemplate item has an alias, key, and has found the cshtml template.
If this is a top level master template should it also be marked as IsMasterTemplate = true?
Managed to resolve this by downloading the uSync source then altering the TemplateSerializer to look for template by Guid if alias doesn't find anything.
Kevin, if you see this please let me know what I was doing wrong as I'd prefer to use the uSync nuget rather than my shoddy hacks.
internal override SyncAttempt<ITemplate> DeserializeCore(XElement node)
{
if (node == null || node.Element("Alias") == null || node.Element("Name") == null)
throw new ArgumentException("Bad xml import");
string alias = node.Element("Alias").ValueOrDefault(string.Empty);
if (string.IsNullOrEmpty(alias))
SyncAttempt<ITemplate>.Fail(node.NameFromNode(), ChangeType.Import, "No Alias node in xml");
LogHelper.Debug<Events>("# Importing Template : {0}", () => alias);
Guid key = node.Element("Key").ValueOrDefault(Guid.Empty);
string name = node.Element("Name").ValueOrDefault(string.Empty);
ITemplate item = _fileService.GetTemplate(alias);
// first check by guid
if(item == null)
{
item = _fileService.GetTemplate(key);
if(item != null)
{
item.Alias = alias;
}
}
if (item == null)
{
string templatePath = IOHelper.MapPath(SystemDirectories.MvcViews + "/" + alias.ToSafeFileName() + ".cshtml");
if (!System.IO.File.Exists(templatePath))
{
templatePath = IOHelper.MapPath(SystemDirectories.Masterpages + "/" + alias.ToSafeFileName() + ".master");
if (!System.IO.File.Exists(templatePath))
{
// cannot find the master for this..
templatePath = string.Empty;
LogHelper.Warn<TemplateSerializer>("Cannot find underling template file, so we cannot create the template");
}
}
if (!string.IsNullOrEmpty(templatePath))
{
string content = System.IO.File.ReadAllText(templatePath);
item = new Template(name, alias);
item.Path = templatePath;
item.Content = content;
}
else
{
LogHelper.Warn<TemplateSerializer>("Can't get a template path?");
return SyncAttempt<ITemplate>.Fail(name, ChangeType.Import, "Failed to generate template path");
}
}
if (item == null)
{
LogHelper.Warn<TemplateSerializer>("Cannot create the template, something missing?");
return SyncAttempt<ITemplate>.Fail(name, ChangeType.Import, "Item create fail");
}
if (node.Element("Name").Value != item.Name)
item.Name = node.Element("Name").Value;
if (node.Element("Master") != null) {
var masterName = node.Element("Master").Value;
if (!string.IsNullOrEmpty(masterName))
{
var master = _fileService.GetTemplate(masterName);
if (master != null)
item.SetMasterTemplate(master);
}
}
//var key = node.Element("Key").ValueOrDefault(Guid.Empty);
if (key != Guid.Empty)
item.Key = key;
_fileService.SaveTemplate(item);
return SyncAttempt<ITemplate>.Succeed(item.Name, item, ChangeType.Import);
}
I don't think you where doing anything odd but I need to have a look because i was fairly sure renames of templates worked :(
however the guid thing is the answer long term, it was just that the guids of templates wasn't being set consistently until a fairly recent version (it might be 7.4).
I'll probibly absorb your change into the code and push out a new version - i don't think it's a shoddy hack :)
uSync - Cannot insert duplicate key row in object 'dbo.umbracoNode' when renaming template
uSync.BackOffice 3.2.2.740, uSync.Core 5.5.2.740, Umbraco version 7.5.3 assembly: 1.0.6092.24019
I'm running into problems importing existing templates that have been renamed. It results in the following exception:
I have a feeling this is because I'm abusing uSync rather than a bug but I would appreciate any pointers.
I installed a copy of Umbraco as an Azure app and installed the Faroe starter package. I then exported the database from Azure to a local database and set up my local development version (copied Umbraco files over as well).
At this point the local and Azure versions were both identical and working as expected.
I then renamed a local master template from Test > Test2. I then published this to Azure making sure the /uSync/data directory contained the renamed template. There was no "Test.config" template but there was a "Test2.config".
The changes were detected by the report and I can see it says to rename the template. When I click import it errors with the above exception.
Am I doing this wrong?
EDIT: I've been debugging the uSync source and found that when _fileService.SaveTemplate inside TemplateSerializer is called the ITemplate item has an alias, key, and has found the cshtml template.
If this is a top level master template should it also be marked as IsMasterTemplate = true?
Managed to resolve this by downloading the uSync source then altering the TemplateSerializer to look for template by Guid if alias doesn't find anything.
Kevin, if you see this please let me know what I was doing wrong as I'd prefer to use the uSync nuget rather than my shoddy hacks.
HI,
I don't think you where doing anything odd but I need to have a look because i was fairly sure renames of templates worked :(
however the guid thing is the answer long term, it was just that the guids of templates wasn't being set consistently until a fairly recent version (it might be 7.4).
I'll probibly absorb your change into the code and push out a new version - i don't think it's a shoddy hack :)
is working on a reply...