Merge branch 'temp8' of https://github.com/StefanoChiodino/Umbraco-CMS into temp8-pr3583
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Umbraco.Core.Models
|
||||
public class Content : ContentBase, IContent
|
||||
{
|
||||
private IContentType _contentType;
|
||||
private ITemplate _template;
|
||||
private int? _templateId;
|
||||
private ContentScheduleCollection _schedule;
|
||||
private bool _published;
|
||||
private PublishedState _publishedState;
|
||||
@@ -83,7 +83,7 @@ namespace Umbraco.Core.Models
|
||||
// ReSharper disable once ClassNeverInstantiated.Local
|
||||
private class PropertySelectors
|
||||
{
|
||||
public readonly PropertyInfo TemplateSelector = ExpressionHelper.GetPropertyInfo<Content, ITemplate>(x => x.Template);
|
||||
public readonly PropertyInfo TemplateSelector = ExpressionHelper.GetPropertyInfo<Content, int?>(x => x.TemplateId);
|
||||
public readonly PropertyInfo PublishedSelector = ExpressionHelper.GetPropertyInfo<Content, bool>(x => x.Published);
|
||||
public readonly PropertyInfo ContentScheduleSelector = ExpressionHelper.GetPropertyInfo<Content, ContentScheduleCollection>(x => x.ContentSchedule);
|
||||
public readonly PropertyInfo PublishCultureInfosSelector = ExpressionHelper.GetPropertyInfo<Content, IReadOnlyDictionary<string, ContentCultureInfos>>(x => x.PublishCultureInfos);
|
||||
@@ -131,10 +131,10 @@ namespace Umbraco.Core.Models
|
||||
/// the Default template from the ContentType will be returned.
|
||||
/// </remarks>
|
||||
[DataMember]
|
||||
public ITemplate Template
|
||||
public int? TemplateId
|
||||
{
|
||||
get => _template ?? _contentType.DefaultTemplate;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _template, Ps.Value.TemplateSelector);
|
||||
get => _templateId;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _templateId, Ps.Value.TemplateSelector);
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace Umbraco.Core.Models
|
||||
|
||||
/// <inheritdoc />
|
||||
[IgnoreDataMember]
|
||||
public ITemplate PublishTemplate { get; internal set; } // set by persistence
|
||||
public int? PublishTemplateId { get; internal set; } // set by persistence
|
||||
|
||||
/// <inheritdoc />
|
||||
[IgnoreDataMember]
|
||||
@@ -457,9 +457,7 @@ namespace Umbraco.Core.Models
|
||||
public override void ResetDirtyProperties(bool rememberDirty)
|
||||
{
|
||||
base.ResetDirtyProperties(rememberDirty);
|
||||
|
||||
if (Template != null)
|
||||
Template.ResetDirtyProperties(rememberDirty);
|
||||
|
||||
if (ContentType != null)
|
||||
ContentType.ResetDirtyProperties(rememberDirty);
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace Umbraco.Core.Models
|
||||
ContentScheduleCollection ContentSchedule { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the template used to render the content.
|
||||
/// Gets or sets the template id used to render the content.
|
||||
/// </summary>
|
||||
ITemplate Template { get; set; }
|
||||
int? TemplateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content is published.
|
||||
@@ -45,10 +45,10 @@ namespace Umbraco.Core.Models
|
||||
bool Blueprint { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the template used to render the published version of the content.
|
||||
/// Gets the template id used to render the published version of the content.
|
||||
/// </summary>
|
||||
/// <remarks>When editing the content, the template can change, but this will not until the content is published.</remarks>
|
||||
ITemplate PublishTemplate { get; }
|
||||
int? PublishTemplateId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the published version of the content.
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// <summary>
|
||||
/// Gets the identifier of the template to use to render the content item.
|
||||
/// </summary>
|
||||
int TemplateId { get; }
|
||||
int? TemplateId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the identifier of the user who created the content item.
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
public virtual string Path => _content.Path;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual int TemplateId => _content.TemplateId;
|
||||
public virtual int? TemplateId => _content.TemplateId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual int CreatorId => _content.CreatorId;
|
||||
|
||||
@@ -282,7 +282,7 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
var dto = new DocumentVersionDto
|
||||
{
|
||||
Id = entity.VersionId,
|
||||
TemplateId = entity.Template?.Id,
|
||||
TemplateId = entity.TemplateId,
|
||||
Published = false, // always building the current, unpublished one
|
||||
|
||||
ContentVersionDto = BuildContentVersionDto(entity, contentDto)
|
||||
|
||||
@@ -273,8 +273,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
var publishing = content.PublishedState == PublishedState.Publishing;
|
||||
|
||||
// ensure that the default template is assigned
|
||||
if (entity.Template == null)
|
||||
entity.Template = entity.ContentType.DefaultTemplate;
|
||||
if (entity.TemplateId.HasValue == false)
|
||||
entity.TemplateId = entity.ContentType.DefaultTemplate?.Id;
|
||||
|
||||
// sanitize names
|
||||
SanitizeNames(content, publishing);
|
||||
@@ -404,7 +404,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
if (content.PublishedState == PublishedState.Publishing)
|
||||
{
|
||||
content.Published = true;
|
||||
content.PublishTemplate = content.Template;
|
||||
content.PublishTemplateId = content.TemplateId;
|
||||
content.PublisherId = content.WriterId;
|
||||
content.PublishName = content.Name;
|
||||
content.PublishDate = content.UpdateDate;
|
||||
@@ -414,7 +414,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
else if (content.PublishedState == PublishedState.Unpublishing)
|
||||
{
|
||||
content.Published = false;
|
||||
content.PublishTemplate = null;
|
||||
content.PublishTemplateId = null;
|
||||
content.PublisherId = null;
|
||||
content.PublishName = null;
|
||||
content.PublishDate = null;
|
||||
@@ -609,7 +609,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
if (content.PublishedState == PublishedState.Publishing)
|
||||
{
|
||||
content.Published = true;
|
||||
content.PublishTemplate = content.Template;
|
||||
content.PublishTemplateId = content.TemplateId;
|
||||
content.PublisherId = content.WriterId;
|
||||
content.PublishName = content.Name;
|
||||
content.PublishDate = content.UpdateDate;
|
||||
@@ -619,7 +619,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
else if (content.PublishedState == PublishedState.Unpublishing)
|
||||
{
|
||||
content.Published = false;
|
||||
content.PublishTemplate = null;
|
||||
content.PublishTemplateId = null;
|
||||
content.PublisherId = null;
|
||||
content.PublishName = null;
|
||||
content.PublishDate = null;
|
||||
@@ -1079,10 +1079,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
foreach (var temp in temps)
|
||||
{
|
||||
// complete the item
|
||||
if (temp.Template1Id.HasValue && templates.TryGetValue(temp.Template1Id.Value, out var template))
|
||||
temp.Content.Template = template;
|
||||
if (temp.Template2Id.HasValue && templates.TryGetValue(temp.Template2Id.Value, out template))
|
||||
temp.Content.PublishTemplate = template;
|
||||
// fixme - this makes no sense, no need to manage templates on TEMP anymore?!
|
||||
if (temp.Template1Id.HasValue && templates.ContainsKey(temp.Template1Id.Value))
|
||||
temp.Content.TemplateId = temp.Template1Id;
|
||||
if (temp.Template2Id.HasValue && templates.ContainsKey(temp.Template2Id.Value))
|
||||
temp.Content.PublishTemplateId = temp.Template2Id;
|
||||
|
||||
if (properties.ContainsKey(temp.VersionId))
|
||||
temp.Content.Properties = properties[temp.VersionId];
|
||||
@@ -1123,7 +1124,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
// get template
|
||||
if (dto.DocumentVersionDto.TemplateId.HasValue && dto.DocumentVersionDto.TemplateId.Value > 0)
|
||||
content.Template = _templateRepository.Get(dto.DocumentVersionDto.TemplateId.Value);
|
||||
content.TemplateId = dto.DocumentVersionDto.TemplateId;
|
||||
|
||||
// get properties - indexed by version id
|
||||
var versionId = dto.DocumentVersionDto.Id;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Umbraco.Core.Services
|
||||
xml.Add(new XAttribute("writerName", content.GetWriterProfile(userService)?.Name ?? "??"));
|
||||
xml.Add(new XAttribute("writerID", content.WriterId));
|
||||
|
||||
xml.Add(new XAttribute("template", content.Template?.Id.ToString(CultureInfo.InvariantCulture) ?? "0"));
|
||||
xml.Add(new XAttribute("template", content.TemplateId?.ToString(CultureInfo.InvariantCulture) ?? ""));
|
||||
|
||||
xml.Add(new XAttribute("isPublished", content.Published));
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
var store = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null), ServiceContext.MediaService, ServiceContext.UserService, new StaticCacheProvider(), ContentTypesCache);
|
||||
var doc = store.CreateFromCacheValues(store.ConvertFromSearchResult(result));
|
||||
|
||||
DoAssert(doc, 1234, key, 0, 0, "/media/test.jpg", "Image", 23, "Shannon", "Shannon", 0, 0, "-1,1234", DateTime.Parse("2012-07-17T10:34:09"), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
DoAssert(doc, 1234, key, templateIdVal: null, 0, "/media/test.jpg", "Image", 23, "Shannon", "Shannon", 0, 0, "-1,1234", DateTime.Parse("2012-07-17T10:34:09"), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
Assert.AreEqual(null, doc.Parent);
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null), ServiceContext.MediaService, ServiceContext.UserService, new StaticCacheProvider(), ContentTypesCache);
|
||||
var doc = cache.CreateFromCacheValues(cache.ConvertFromXPathNavigator(navigator, true));
|
||||
|
||||
DoAssert(doc, 2000, key, 0, 2, "image1", "Image", 23, "Shannon", "Shannon", 33, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
DoAssert(doc, 2000, key, templateIdVal: null, 2, "image1", "Image", 23, "Shannon", "Shannon", 33, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
Assert.AreEqual(null, doc.Parent);
|
||||
Assert.AreEqual(2, doc.Children.Count());
|
||||
Assert.AreEqual(2001, doc.Children.ElementAt(0).Id);
|
||||
@@ -336,7 +336,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
DictionaryPublishedContent dicDoc,
|
||||
int idVal = 1234,
|
||||
Guid keyVal = default(Guid),
|
||||
int templateIdVal = 0,
|
||||
int? templateIdVal = null,
|
||||
int sortOrderVal = 44,
|
||||
string urlNameVal = "testing",
|
||||
string nodeTypeAliasVal = "myType",
|
||||
@@ -367,7 +367,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
IPublishedContent doc,
|
||||
int idVal = 1234,
|
||||
Guid keyVal = default(Guid),
|
||||
int templateIdVal = 0,
|
||||
int? templateIdVal = null,
|
||||
int sortOrderVal = 44,
|
||||
string urlNameVal = "testing",
|
||||
string nodeTypeAliasVal = "myType",
|
||||
@@ -401,9 +401,6 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
Assert.AreEqual(createDateVal.Value, doc.CreateDate);
|
||||
Assert.AreEqual(updateDateVal.Value, doc.UpdateDate);
|
||||
Assert.AreEqual(levelVal, doc.Level);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,10 +227,7 @@ namespace Umbraco.Tests.Models
|
||||
content.ContentSchedule.Add(DateTime.Now, DateTime.Now.AddDays(1));
|
||||
//content.ChangePublishedState(PublishedState.Published);
|
||||
content.SortOrder = 5;
|
||||
content.Template = new Template((string) "Test Template", (string) "testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
};
|
||||
content.TemplateId = 88;
|
||||
content.Trashed = false;
|
||||
content.UpdateDate = DateTime.Now;
|
||||
content.WriterId = 23;
|
||||
@@ -289,10 +286,7 @@ namespace Umbraco.Tests.Models
|
||||
content.Path = "-1,4,10";
|
||||
content.ContentSchedule.Add(DateTime.Now, DateTime.Now.AddDays(1));
|
||||
content.SortOrder = 5;
|
||||
content.Template = new Template((string) "Test Template", (string) "testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
};
|
||||
content.TemplateId = 88;
|
||||
content.Trashed = false;
|
||||
content.UpdateDate = DateTime.Now;
|
||||
content.WriterId = 23;
|
||||
@@ -332,8 +326,8 @@ namespace Umbraco.Tests.Models
|
||||
Assert.AreEqual(clone.PublishedState, content.PublishedState);
|
||||
Assert.AreEqual(clone.SortOrder, content.SortOrder);
|
||||
Assert.AreEqual(clone.PublishedState, content.PublishedState);
|
||||
Assert.AreNotSame(clone.Template, content.Template);
|
||||
Assert.AreEqual(clone.Template, content.Template);
|
||||
Assert.AreNotSame(clone.TemplateId, content.TemplateId);
|
||||
Assert.AreEqual(clone.TemplateId, content.TemplateId);
|
||||
Assert.AreEqual(clone.Trashed, content.Trashed);
|
||||
Assert.AreEqual(clone.UpdateDate, content.UpdateDate);
|
||||
Assert.AreEqual(clone.VersionId, content.VersionId);
|
||||
@@ -408,16 +402,12 @@ namespace Umbraco.Tests.Models
|
||||
content.Level = 3;
|
||||
content.Path = "-1,4,10";
|
||||
content.SortOrder = 5;
|
||||
content.Template = new Template((string)"Test Template", (string)"testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
};
|
||||
content.TemplateId = 88;
|
||||
|
||||
content.Trashed = true;
|
||||
content.UpdateDate = DateTime.Now;
|
||||
content.WriterId = 23;
|
||||
|
||||
content.Template.UpdateDate = DateTime.Now; //update a child object
|
||||
|
||||
content.ContentType.UpdateDate = DateTime.Now; //update a child object
|
||||
|
||||
// Act
|
||||
@@ -425,18 +415,18 @@ namespace Umbraco.Tests.Models
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(content.WasDirty());
|
||||
Assert.IsTrue(content.WasPropertyDirty("Id"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("CreateDate"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("CreatorId"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("Key"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("Level"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("Path"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("ContentSchedule"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("SortOrder"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("Template"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("Trashed"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("UpdateDate"));
|
||||
Assert.IsTrue(content.WasPropertyDirty("WriterId"));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.Id)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.CreateDate)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.CreatorId)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.Key)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.Level)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.Path)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.ContentSchedule)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.SortOrder)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.TemplateId)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.Trashed)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.UpdateDate)));
|
||||
Assert.IsTrue(content.WasPropertyDirty(nameof(Content.WriterId)));
|
||||
foreach (var prop in content.Properties)
|
||||
{
|
||||
Assert.IsTrue(prop.WasDirty());
|
||||
@@ -457,7 +447,6 @@ namespace Umbraco.Tests.Models
|
||||
Assert.IsTrue(culture.Value.WasPropertyDirty("Date"));
|
||||
}
|
||||
//verify child objects were reset too
|
||||
Assert.IsTrue(content.Template.WasPropertyDirty("UpdateDate"));
|
||||
Assert.IsTrue(content.ContentType.WasPropertyDirty("UpdateDate"));
|
||||
}
|
||||
|
||||
@@ -484,10 +473,7 @@ namespace Umbraco.Tests.Models
|
||||
content.ContentSchedule.Add(DateTime.Now, DateTime.Now.AddDays(1));
|
||||
//content.ChangePublishedState(PublishedState.Publishing);
|
||||
content.SortOrder = 5;
|
||||
content.Template = new Template((string) "Test Template", (string) "testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
};
|
||||
content.TemplateId = 88;
|
||||
content.Trashed = false;
|
||||
content.UpdateDate = DateTime.Now;
|
||||
content.WriterId = 23;
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Umbraco.Tests.Models
|
||||
Assert.AreEqual(content.GetCreatorProfile(ServiceContext.UserService).Name, (string)element.Attribute("creatorName"));
|
||||
Assert.AreEqual(content.GetWriterProfile(ServiceContext.UserService).Name, (string)element.Attribute("writerName"));
|
||||
Assert.AreEqual(content.WriterId.ToString(), (string)element.Attribute("writerID"));
|
||||
Assert.AreEqual(content.Template == null ? "0" : content.Template.Id.ToString(), (string)element.Attribute("template"));
|
||||
Assert.AreEqual(content.TemplateId.ToString(), (string)element.Attribute("template"));
|
||||
|
||||
Assert.AreEqual(content.Properties["title"].GetValue().ToString(), element.Elements("title").Single().Value);
|
||||
Assert.AreEqual(content.Properties["bodyText"].GetValue().ToString(), element.Elements("bodyText").Single().Value);
|
||||
|
||||
@@ -432,8 +432,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
var fetched = repository.Get(textpage.Id);
|
||||
|
||||
Assert.NotNull(textpage.Template);
|
||||
Assert.AreEqual(textpage.Template, contentType.DefaultTemplate);
|
||||
Assert.True(textpage.TemplateId.HasValue);
|
||||
Assert.NotZero(textpage.TemplateId.Value);
|
||||
Assert.AreEqual(textpage.TemplateId, contentType.DefaultTemplate.Id);
|
||||
|
||||
scope.Complete();
|
||||
|
||||
@@ -557,12 +558,12 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var repository = CreateRepository((IScopeAccessor)provider, out _);
|
||||
|
||||
var content = repository.Get(NodeDto.NodeIdSeed + 2);
|
||||
content.Template = null;
|
||||
content.TemplateId = null;
|
||||
repository.Save(content);
|
||||
|
||||
var updatedContent = repository.Get(NodeDto.NodeIdSeed + 2);
|
||||
|
||||
Assert.IsNull(updatedContent.Template);
|
||||
Assert.False(updatedContent.TemplateId.HasValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -380,7 +380,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
};
|
||||
templateRepository.Save(template);
|
||||
|
||||
textpage.Template = template;
|
||||
textpage.TemplateId = template.Id;
|
||||
contentRepo.Save(textpage);
|
||||
|
||||
// Act
|
||||
|
||||
@@ -270,7 +270,7 @@ namespace Umbraco.Tests.Published
|
||||
|
||||
// ReSharper disable UnassignedGetOnlyAutoProperty
|
||||
public override int Id { get; }
|
||||
public override int TemplateId { get; }
|
||||
public override int? TemplateId { get; }
|
||||
public override int SortOrder { get; }
|
||||
public override string Name { get; }
|
||||
public override PublishedCultureInfo GetCulture(string culture = ".") => throw new NotSupportedException();
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
public IPublishedContent Parent { get; set; }
|
||||
public int Id { get; set; }
|
||||
public Guid Key { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public int? TemplateId { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public string Name { get; set; }
|
||||
public PublishedCultureInfo GetCulture(string culture = null) => throw new NotSupportedException();
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
|
||||
public int Id { get; set; }
|
||||
public Guid Key { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public int? TemplateId { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public string Name { get; set; }
|
||||
public PublishedCultureInfo GetCulture(string culture = null) => throw new NotSupportedException();
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Umbraco.Tests.TestHelpers.Stubs
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
public int TemplateId { get; set; }
|
||||
public int? TemplateId { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public string Name { get; set; }
|
||||
public IVariationContextAccessor VariationContextAccessor { get; set; }
|
||||
|
||||
@@ -1780,22 +1780,24 @@ namespace Umbraco.Web.Editors
|
||||
variantIndex++;
|
||||
}
|
||||
|
||||
//only set the template if it didn't change
|
||||
var templateChanged = (contentSave.PersistedContent.Template == null && contentSave.TemplateAlias.IsNullOrWhiteSpace() == false)
|
||||
|| (contentSave.PersistedContent.Template != null && contentSave.PersistedContent.Template.Alias != contentSave.TemplateAlias)
|
||||
|| (contentSave.PersistedContent.Template != null && contentSave.TemplateAlias.IsNullOrWhiteSpace());
|
||||
if (templateChanged)
|
||||
// If the template was set.
|
||||
// fixme review this - what if template has been cleared?
|
||||
if (contentSave.TemplateAlias != null)
|
||||
{
|
||||
//only set the template if it didn't change
|
||||
var template = Services.FileService.GetTemplate(contentSave.TemplateAlias);
|
||||
if (template == null && contentSave.TemplateAlias.IsNullOrWhiteSpace() == false)
|
||||
if (contentSave.PersistedContent.TemplateId != template.Id)
|
||||
{
|
||||
//ModelState.AddModelError("Template", "No template exists with the specified alias: " + contentItem.TemplateAlias);
|
||||
Logger.Warn<ContentController>("No template exists with the specified alias: {TemplateAlias}", contentSave.TemplateAlias);
|
||||
}
|
||||
else
|
||||
{
|
||||
//NOTE: this could be null if there was a template and the posted template is null, this should remove the assigned template
|
||||
contentSave.PersistedContent.Template = template;
|
||||
if (template == null && contentSave.TemplateAlias.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
//ModelState.AddModelError("Template", "No template exists with the specified alias: " + contentItem.TemplateAlias);
|
||||
Logger.Warn<ContentController>("No template exists with the specified alias: {TemplateAlias}", contentSave.TemplateAlias);
|
||||
}
|
||||
else
|
||||
{
|
||||
//NOTE: this could be null if there was a template and the posted template is null, this should remove the assigned template
|
||||
contentSave.PersistedContent.TemplateId = template.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using AutoMapper;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
@@ -8,17 +10,24 @@ namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
public string Resolve(IContent source, ContentItemDisplay destination, string destMember, ResolutionContext context)
|
||||
{
|
||||
if (source == null || source.Template == null) return null;
|
||||
if (source == null)
|
||||
return null;
|
||||
|
||||
var alias = source.Template.Alias;
|
||||
// If no template id was set...
|
||||
if (!source.TemplateId.HasValue)
|
||||
{
|
||||
// ... and no default template is set, return null...
|
||||
if (string.IsNullOrWhiteSpace(source.ContentType.DefaultTemplate?.Alias))
|
||||
return null;
|
||||
|
||||
//set default template if template isn't set
|
||||
if (string.IsNullOrEmpty(alias))
|
||||
alias = source.ContentType.DefaultTemplate == null
|
||||
? string.Empty
|
||||
: source.ContentType.DefaultTemplate.Alias;
|
||||
// ... otherwise return the content type default template alias.
|
||||
return source.ContentType.DefaultTemplate?.Alias;
|
||||
}
|
||||
|
||||
var fileService = DependencyResolver.Current.GetService<IFileService>();
|
||||
var template = fileService.GetTemplate(source.TemplateId.Value);
|
||||
|
||||
return alias;
|
||||
return template.Alias;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Umbraco.Web.Models
|
||||
public abstract string Path { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract int TemplateId { get; }
|
||||
public abstract int? TemplateId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract int CreatorId { get; }
|
||||
|
||||
@@ -30,9 +30,12 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
PrimitiveSerializer.Int32.WriteTo(value.VersionId, stream);
|
||||
PrimitiveSerializer.DateTime.WriteTo(value.VersionDate, stream);
|
||||
PrimitiveSerializer.Int32.WriteTo(value.WriterId, stream);
|
||||
PrimitiveSerializer.Int32.WriteTo(value.TemplateId, stream);
|
||||
if (value.TemplateId.HasValue)
|
||||
{
|
||||
PrimitiveSerializer.Int32.WriteTo(value.TemplateId.Value, stream);
|
||||
}
|
||||
PropertiesSerializer.WriteTo(value.Properties, stream);
|
||||
CultureVariationsSerializer.WriteTo(value.CultureInfos, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
public int VersionId { get; set; }
|
||||
public DateTime VersionDate { get; set; }
|
||||
public int WriterId { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public int? TemplateId { get; set; }
|
||||
public bool Published { get; set; }
|
||||
|
||||
public IDictionary<string, PropertyData[]> Properties { get; set; }
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
public override string Path => _contentNode.Path;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int TemplateId => _contentData.TemplateId;
|
||||
public override int? TemplateId => _contentData.TemplateId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int CreatorId => _contentNode.CreatorId;
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Umbraco.Web.PublishedCache
|
||||
|
||||
public override Guid Key => _member.Key;
|
||||
|
||||
public override int TemplateId => throw new NotSupportedException();
|
||||
public override int? TemplateId => throw new NotSupportedException();
|
||||
|
||||
public override int SortOrder => 0;
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
public override Guid Key => _key;
|
||||
|
||||
public override int TemplateId => 0;
|
||||
public override int? TemplateId => null;
|
||||
|
||||
public override int SortOrder => _sortOrder;
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
}
|
||||
}
|
||||
|
||||
public override int TemplateId
|
||||
public override int? TemplateId
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -133,10 +133,15 @@ namespace Umbraco.Web
|
||||
/// Returns the current template Alias
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns>Empty string if none is set.</returns>
|
||||
public static string GetTemplateAlias(this IPublishedContent content)
|
||||
{
|
||||
var template = Current.Services.FileService.GetTemplate(content.TemplateId);
|
||||
if(content.TemplateId.HasValue == false)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var template = Current.Services.FileService.GetTemplate(content.TemplateId.Value);
|
||||
return template == null ? string.Empty : template.Alias;
|
||||
}
|
||||
|
||||
|
||||
@@ -755,9 +755,9 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
}
|
||||
|
||||
private ITemplate GetTemplateModel(int templateId)
|
||||
private ITemplate GetTemplateModel(int? templateId)
|
||||
{
|
||||
if (templateId <= 0)
|
||||
if (templateId.HasValue == false)
|
||||
{
|
||||
_logger.Debug<PublishedRouter>("GetTemplateModel: No template.");
|
||||
return null;
|
||||
@@ -765,7 +765,10 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
_logger.Debug<PublishedRouter>("GetTemplateModel: Get template id={TemplateId}", templateId);
|
||||
|
||||
var template = _services.FileService.GetTemplate(templateId);
|
||||
if (templateId == null)
|
||||
throw new InvalidOperationException("The template is not set, the page cannot render.");
|
||||
|
||||
var template = _services.FileService.GetTemplate(templateId.Value);
|
||||
if (template == null)
|
||||
throw new InvalidOperationException("The template with Id " + templateId + " does not exist, the page cannot render.");
|
||||
_logger.Debug<PublishedRouter>("GetTemplateModel: Got template id={TemplateId} alias={TemplateAlias}", template.Id, template.Alias);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Web.Templates
|
||||
public TemplateRenderer(UmbracoContext umbracoContext, int pageId, int? altTemplateId)
|
||||
{
|
||||
PageId = pageId;
|
||||
AltTemplate = altTemplateId;
|
||||
AltTemplateId = altTemplateId;
|
||||
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Umbraco.Web.Templates
|
||||
/// <summary>
|
||||
/// Gets/sets the alt template to render if there is one
|
||||
/// </summary>
|
||||
public int? AltTemplate { get; }
|
||||
public int? AltTemplateId { get; }
|
||||
|
||||
public void Render(StringWriter writer)
|
||||
{
|
||||
@@ -86,20 +86,22 @@ namespace Umbraco.Web.Templates
|
||||
//set the doc that was found by id
|
||||
contentRequest.PublishedContent = doc;
|
||||
//set the template, either based on the AltTemplate found or the standard template of the doc
|
||||
contentRequest.TemplateModel = Current.Configs.Settings().WebRouting.DisableAlternativeTemplates || AltTemplate.HasValue == false
|
||||
? FileService.GetTemplate(doc.TemplateId)
|
||||
: FileService.GetTemplate(AltTemplate.Value);
|
||||
var templateId = Current.Configs.Settings().WebRouting.DisableAlternativeTemplates || !AltTemplateId.HasValue
|
||||
? doc.TemplateId
|
||||
: AltTemplateId.Value;
|
||||
if (templateId.HasValue)
|
||||
contentRequest.TemplateModel = FileService.GetTemplate(templateId.Value);
|
||||
|
||||
//if there is not template then exit
|
||||
if (contentRequest.HasTemplate == false)
|
||||
{
|
||||
if (AltTemplate.HasValue == false)
|
||||
if (AltTemplateId.HasValue == false)
|
||||
{
|
||||
writer.Write("<!-- Could not render template for Id {0}, the document's template was not found with id {0}-->", doc.TemplateId);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write("<!-- Could not render template for Id {0}, the altTemplate was not found with id {0}-->", AltTemplate);
|
||||
writer.Write("<!-- Could not render template for Id {0}, the altTemplate was not found with id {0}-->", AltTemplateId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,10 +88,10 @@ namespace umbraco
|
||||
doc.WriterName, doc.CreatorName, doc.CreateDate, doc.UpdateDate,
|
||||
doc.Path, doc.Parent == null ? -1 : doc.Parent.Id);
|
||||
|
||||
if (doc.TemplateId > 0)
|
||||
if (doc.TemplateId.HasValue)
|
||||
{
|
||||
//set the template to whatever is assigned to the doc
|
||||
_template = doc.TemplateId;
|
||||
_template = doc.TemplateId.Value;
|
||||
_elements["template"] = _template.ToString();
|
||||
}
|
||||
|
||||
@@ -357,10 +357,7 @@ namespace umbraco
|
||||
get { return _key; }
|
||||
}
|
||||
|
||||
public int TemplateId
|
||||
{
|
||||
get { return _inner.Template == null ? 0 : _inner.Template.Id; }
|
||||
}
|
||||
public int? TemplateId => _inner.TemplateId;
|
||||
|
||||
public int SortOrder
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user