Cleanup some DTOs

This commit is contained in:
Stephan
2018-09-25 18:05:14 +02:00
parent c791050058
commit 14bd8a0851
8 changed files with 33 additions and 19 deletions

View File

@@ -167,7 +167,7 @@ namespace Umbraco.Core.Models
}
/// <inheritdoc />
public DateTime? GetCultureDate(string culture)
public DateTime? GetUpdateDate(string culture)
{
if (culture.IsNullOrWhiteSpace()) return null;
if (!ContentTypeBase.VariesByCulture()) return null;
@@ -202,6 +202,12 @@ namespace Umbraco.Core.Models
}
}
internal void TouchCulture(string culture)
{
if (ContentTypeBase.VariesByCulture() && _cultureInfos != null && _cultureInfos.TryGetValue(culture, out var infos))
_cultureInfos[culture] = (infos.Name, DateTime.Now);
}
protected void ClearCultureInfos()
{
_cultureInfos = null;

View File

@@ -80,13 +80,13 @@ namespace Umbraco.Core.Models
bool IsCultureAvailable(string culture);
/// <summary>
/// Gets the date a culture was created.
/// Gets the date a culture was updated.
/// </summary>
/// <remarks>
/// <para>When <paramref name="culture" /> is <c>null</c>, returns <c>null</c>.</para>
/// <para>If the specified culture is not available, returns <c>null</c>.</para>
/// </remarks>
DateTime? GetCultureDate(string culture);
DateTime? GetUpdateDate(string culture);
/// <summary>
/// List of properties, which make up all the data available for this Content object

View File

@@ -10,7 +10,7 @@ namespace Umbraco.Core.Persistence.Dtos
internal class ContentVersionCultureVariationDto
{
public const string TableName = Constants.DatabaseSchema.Tables.ContentVersionCultureVariation;
private int? _publishedUserId;
private int? _updateUserId;
[Column("id")]
[PrimaryKeyColumn]
@@ -33,13 +33,12 @@ namespace Umbraco.Core.Persistence.Dtos
[Column("name")]
public string Name { get; set; }
[Column("date")]
public DateTime Date { get; set; }
[Column("date")] // fixme: db rename to 'updateDate'
public DateTime UpdateDate { get; set; }
// fixme want?
[Column("availableUserId")]
[Column("availableUserId")] // fixme: db rename to 'updateDate'
[ForeignKey(typeof(UserDto))]
[NullSetting(NullSetting = NullSettings.Null)]
public int? PublishedUserId { get => _publishedUserId == 0 ? null : _publishedUserId; set => _publishedUserId = value; } //return null if zero
public int? UpdateUserId { get => _updateUserId == 0 ? null : _updateUserId; set => _updateUserId = value; } //return null if zero
}
}

View File

@@ -21,11 +21,11 @@ namespace Umbraco.Core.Persistence.Dtos
[ForeignKey(typeof(ContentDto))]
public int NodeId { get; set; }
[Column("versionDate")]
[Column("versionDate")] // fixme: db rename to 'updateDate'
[Constraint(Default = SystemMethods.CurrentDateTime)]
public DateTime VersionDate { get; set; }
[Column("userId")]
[Column("userId")] // fixme: db rename to 'updateUserId'
[ForeignKey(typeof(UserDto))]
[NullSetting(NullSetting = NullSettings.Null)]
public int? UserId { get => _userId == 0 ? null : _userId; set => _userId = value; } //return null if zero

View File

@@ -45,7 +45,7 @@ namespace Umbraco.Core.Persistence.Dtos
[Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_Trashed")]
public bool Trashed { get; set; }
[Column("nodeUser")] // fixme dbfix rename userId
[Column("nodeUser")] // fixme: db rename to 'createUserId'
[ForeignKey(typeof(UserDto))]
[NullSetting(NullSetting = NullSettings.Null)]
public int? UserId { get => _userId == 0 ? null : _userId; set => _userId = value; } //return null if zero
@@ -54,10 +54,10 @@ namespace Umbraco.Core.Persistence.Dtos
[NullSetting(NullSetting = NullSettings.Null)]
public string Text { get; set; }
[Column("nodeObjectType")] // fixme dbfix rename objectType
[Column("nodeObjectType")] // fixme: db rename to 'objectType'
[NullSetting(NullSetting = NullSettings.Null)]
[Index(IndexTypes.NonClustered, Name = "IX_" + TableName + "_ObjectType")]
public Guid? NodeObjectType { get; set; } // fixme dbfix rename ObjectType
public Guid? NodeObjectType { get; set; }
[Column("createDate")]
[Constraint(Default = SystemMethods.CurrentDateTime)]

View File

@@ -503,8 +503,17 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
// names also impact 'edited'
foreach (var (culture, name) in content.CultureNames)
if (name != content.GetPublishName(culture))
{
edited = true;
(editedCultures ?? (editedCultures = new HashSet<string>(StringComparer.OrdinalIgnoreCase))).Add(culture);
// fixme - change tracking
// at the moment, we don't do any dirty tracking on property values, so we don't know whether the
// culture has just been edited or not, so we don't update its update date - that date only changes
// when the name is set, and it all works because the controller does it - but, if someone uses a
// service to change a property value and save (without setting name), the update date does not change.
}
// replace the content version variations (rather than updating)
// only need to delete for the version that existed, the new version (if any) has no property data yet
var deleteContentVariations = Sql().Delete<ContentVersionCultureVariationDto>().Where<ContentVersionCultureVariationDto>(x => x.VersionId == versionToDelete);
@@ -1031,7 +1040,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
{
Culture = LanguageRepository.GetIsoCodeById(dto.LanguageId),
Name = dto.Name,
Date = dto.Date
Date = dto.UpdateDate
});
}
@@ -1076,7 +1085,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
LanguageId = LanguageRepository.GetIdByIsoCode(culture) ?? throw new InvalidOperationException("Not a valid culture."),
Culture = culture,
Name = name,
Date = content.GetCultureDate(culture) ?? DateTime.MinValue // we *know* there is a value
UpdateDate = content.GetUpdateDate(culture) ?? DateTime.MinValue // we *know* there is a value
};
// if not publishing, we're just updating the 'current' (non-published) version,
@@ -1091,7 +1100,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
LanguageId = LanguageRepository.GetIdByIsoCode(culture) ?? throw new InvalidOperationException("Not a valid culture."),
Culture = culture,
Name = name,
Date = content.GetPublishDate(culture) ?? DateTime.MinValue // we *know* there is a value
UpdateDate = content.GetPublishDate(culture) ?? DateTime.MinValue // we *know* there is a value
};
}

View File

@@ -108,7 +108,7 @@ namespace Umbraco.Web.Models.Mapping
// if we don't have a date for a culture, it means the culture is not available, and
// hey we should probably not be mapping it, but it's too late, return a fallback date
var date = source.GetCultureDate(culture);
var date = source.GetUpdateDate(culture);
return date ?? source.UpdateDate;
}
}

View File

@@ -1196,7 +1196,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
foreach (var (culture, name) in names)
{
cultureData[culture] = new CultureVariation { Name = name, Date = content.GetCultureDate(culture) ?? DateTime.MinValue };
cultureData[culture] = new CultureVariation { Name = name, Date = content.GetUpdateDate(culture) ?? DateTime.MinValue };
}
//the dictionary that will be serialized