Troubleshoot variants migration
This commit is contained in:
@@ -7,12 +7,14 @@ using Umbraco.Core.Models.EntityBase;
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Language
|
||||
/// Represents a Language.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class Language : Entity, ILanguage
|
||||
{
|
||||
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
|
||||
|
||||
private string _isoCode;
|
||||
private string _cultureName;
|
||||
|
||||
@@ -21,8 +23,7 @@ namespace Umbraco.Core.Models
|
||||
IsoCode = isoCode;
|
||||
}
|
||||
|
||||
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
|
||||
|
||||
// ReSharper disable once ClassNeverInstantiated.Local
|
||||
private class PropertySelectors
|
||||
{
|
||||
public readonly PropertyInfo IsoCodeSelector = ExpressionHelper.GetPropertyInfo<Language, string>(x => x.IsoCode);
|
||||
@@ -35,8 +36,8 @@ namespace Umbraco.Core.Models
|
||||
[DataMember]
|
||||
public string IsoCode
|
||||
{
|
||||
get { return _isoCode; }
|
||||
set { SetPropertyValueAndDetectChanges(value, ref _isoCode, Ps.Value.IsoCodeSelector); }
|
||||
get => _isoCode;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _isoCode, Ps.Value.IsoCodeSelector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,17 +46,14 @@ namespace Umbraco.Core.Models
|
||||
[DataMember]
|
||||
public string CultureName
|
||||
{
|
||||
get { return _cultureName; }
|
||||
set { SetPropertyValueAndDetectChanges(value, ref _cultureName, Ps.Value.CultureNameSelector); }
|
||||
get => _cultureName;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _cultureName, Ps.Value.CultureNameSelector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="CultureInfo"/> object for the current Language
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public CultureInfo CultureInfo
|
||||
{
|
||||
get { return CultureInfo.GetCultureInfo(IsoCode); }
|
||||
}
|
||||
public CultureInfo CultureInfo => CultureInfo.GetCultureInfo(IsoCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,6 @@ namespace Umbraco.Core.Models.Rdbms
|
||||
[ForeignKey(typeof(ContentTypeDto), Column = "NodeId")]
|
||||
public int ContentTypeId { get; set; }
|
||||
|
||||
[Column("writerUserId")]
|
||||
public int WriterUserId { get; set; }
|
||||
|
||||
[Column("updateDate")]
|
||||
[Constraint(Default = SystemMethods.CurrentDateTime)]
|
||||
public DateTime UpdateDate { get; set; }
|
||||
|
||||
[ResultColumn]
|
||||
[Reference(ReferenceType.OneToOne, ColumnName = "NodeId")]
|
||||
public NodeDto NodeDto { get; set; }
|
||||
|
||||
@@ -38,9 +38,9 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
content.Trashed = nodeDto.Trashed;
|
||||
|
||||
content.CreatorId = nodeDto.UserId ?? 0;
|
||||
content.WriterId = contentDto.WriterUserId;
|
||||
content.WriterId = contentVersionDto.UserId;
|
||||
content.CreateDate = nodeDto.CreateDate;
|
||||
content.UpdateDate = contentDto.UpdateDate;
|
||||
content.UpdateDate = contentVersionDto.VersionDate;
|
||||
|
||||
content.Published = dto.Published;
|
||||
content.Edited = dto.Edited;
|
||||
@@ -94,8 +94,6 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
ContentTypeId = entity.ContentTypeId,
|
||||
WriterUserId = entity.WriterId,
|
||||
UpdateDate = entity.UpdateDate,
|
||||
|
||||
NodeDto = BuildNodeDto(entity, objectType)
|
||||
};
|
||||
|
||||
@@ -34,9 +34,9 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
content.Trashed = nodeDto.Trashed;
|
||||
|
||||
content.CreatorId = nodeDto.UserId ?? 0;
|
||||
content.WriterId = dto.WriterUserId;
|
||||
content.WriterId = contentVersionDto.UserId;
|
||||
content.CreateDate = nodeDto.CreateDate;
|
||||
content.UpdateDate = dto.UpdateDate;
|
||||
content.UpdateDate = contentVersionDto.VersionDate;
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
content.ResetDirtyProperties(false);
|
||||
@@ -64,8 +64,6 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
ContentTypeId = entity.ContentTypeId,
|
||||
WriterUserId = entity.WriterId,
|
||||
UpdateDate = entity.UpdateDate,
|
||||
|
||||
NodeDto = BuildNodeDto(entity, objectType)
|
||||
};
|
||||
|
||||
@@ -34,9 +34,9 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
content.Trashed = nodeDto.Trashed;
|
||||
|
||||
content.CreatorId = nodeDto.UserId ?? 0;
|
||||
content.WriterId = dto.ContentDto.WriterUserId;
|
||||
content.WriterId = contentVersionDto.UserId;
|
||||
content.CreateDate = nodeDto.CreateDate;
|
||||
content.UpdateDate = dto.ContentDto.UpdateDate;
|
||||
content.UpdateDate = contentVersionDto.VersionDate;
|
||||
|
||||
content.ProviderUserKey = content.Key; // fixme explain
|
||||
|
||||
@@ -76,8 +76,6 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
ContentTypeId = entity.ContentTypeId,
|
||||
WriterUserId = entity.WriterId,
|
||||
UpdateDate = entity.UpdateDate,
|
||||
|
||||
NodeDto = BuildNodeDto(entity, objectType)
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
@@ -29,6 +30,30 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionEight
|
||||
MigrateContent();
|
||||
MigrateVersions();
|
||||
|
||||
Execute.Code(context =>
|
||||
{
|
||||
if (context.Database.Fetch<dynamic>(@"SELECT uContentVersion.nodeId, COUNT(uContentVersion.id)
|
||||
FROM uContentVersion
|
||||
JOIN uDocumentVersion ON uContentVersion.id=uDocumentVersion.id
|
||||
WHERE uDocumentVersion.published=1
|
||||
GROUP BY uContentVersion.nodeId
|
||||
HAVING COUNT(uContentVersion.id) > 1").Any())
|
||||
{
|
||||
Debugger.Break();
|
||||
throw new Exception("Migration failed: duplicate 'published' document versions.");
|
||||
}
|
||||
if (context.Database.Fetch<dynamic>(@"SELECT v1.nodeId, v1.id, COUNT(v2.id)
|
||||
FROM uContentVersion v1
|
||||
LEFT JOIN uContentVersion v2 ON v1.nodeId=v2.nodeId AND v2.[current]=1
|
||||
GROUP BY v1.nodeId, v1.id
|
||||
HAVING COUNT(v2.id) <> 1").Any())
|
||||
{
|
||||
Debugger.Break();
|
||||
throw new Exception("Migration failed: missing or duplicate 'current' content versions.");
|
||||
}
|
||||
return string.Empty;
|
||||
});
|
||||
|
||||
// re-create *all* keys and indexes
|
||||
//Create.KeysAndIndexes<PropertyDataDto>();
|
||||
foreach (var x in DatabaseSchemaCreation.OrderedTables)
|
||||
@@ -93,32 +118,6 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionEight
|
||||
if (ColumnExists(PreTables.Content, "contentType"))
|
||||
ReplaceColumn<ContentDto>(PreTables.Content, "contentType", "contentTypeId");
|
||||
|
||||
// add columns
|
||||
// fixme - why? why cannot we do it with the current version? we don't need those two columns!
|
||||
if (!ColumnExists(PreTables.Content, "writerUserId"))
|
||||
{
|
||||
AddColumn<ContentDto>(PreTables.Content, "writerUserId", out var sqls);
|
||||
Execute.Sql($"UPDATE {PreTables.Content} SET writerUserId=0");
|
||||
foreach (var sql in sqls) Execute.Sql(sql);
|
||||
}
|
||||
if (!ColumnExists(PreTables.Content, "updateDate"))
|
||||
{
|
||||
AddColumn<ContentDto>(PreTables.Content, "updateDate", out var sqls);
|
||||
var getDate = Context.SqlContext.DatabaseType.IsMySql() ? "CURRENT_TIMESTAMP" : "GETDATE()"; // sqlSyntax should do it!
|
||||
Execute.Sql($"UPDATE {PreTables.Content} SET updateDate=" + getDate);
|
||||
foreach (var sql in sqls) Execute.Sql(sql);
|
||||
}
|
||||
|
||||
// copy data for added columns
|
||||
Execute.Code(context =>
|
||||
{
|
||||
// SQLCE does not support UPDATE...FROM
|
||||
var temp = context.Database.Fetch<dynamic>($"SELECT nodeId, documentUser, updateDate FROM {PreTables.Document} WHERE newest=1");
|
||||
foreach (var t in temp)
|
||||
context.Database.Execute($@"UPDATE {PreTables.Content} SET writerUserId=@userId, updateDate=@updateDate", new { userId = t.documentUser, updateDate = t.updateDate });
|
||||
return string.Empty;
|
||||
});
|
||||
|
||||
// drop columns
|
||||
if (ColumnExists(PreTables.Content, "pk"))
|
||||
Delete.Column("pk").FromTable(PreTables.Content);
|
||||
@@ -196,32 +195,43 @@ WHERE cver.versionId NOT IN (SELECT versionId FROM {SqlSyntax.GetQuotedTableName
|
||||
Execute.Sql($@"INSERT INTO {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.DocumentVersion)} (id, templateId, published)
|
||||
SELECT cver.id, doc.templateId, doc.published
|
||||
FROM {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cver
|
||||
JOIN {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc ON doc.versionId=cver.versionId");
|
||||
JOIN {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc ON doc.nodeId=cver.nodeId AND doc.versionId=cver.versionId");
|
||||
|
||||
// need to add extra rows for where published=newest
|
||||
// 'cos INSERT above has inserted the 'published' document version
|
||||
// and v8 always has a 'edited' document version too
|
||||
Execute.Code(context =>
|
||||
{
|
||||
var temp = context.Database.Fetch<dynamic>($@"SELECT doc.nodeId, doc.versionId, doc.updateDate, doc.documentUser, doc.text, doc.templateId
|
||||
var temp = context.Database.Fetch<dynamic>($@"SELECT doc.nodeId, doc.updateDate, doc.documentUser, doc.text, doc.templateId, cver.id versionId
|
||||
FROM {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc
|
||||
JOIN {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cver ON doc.nodeId=cver.nodeId AND doc.versionId=cver.versionId
|
||||
WHERE doc.newest=1 AND doc.published=1");
|
||||
var getIdentity = context.SqlContext.DatabaseType.IsMySql()
|
||||
? "LAST_INSERT_ID()"
|
||||
: "@@@@IDENTITY";
|
||||
foreach (var t in temp)
|
||||
{
|
||||
context.Database.Execute($@"INSERT INTO {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} (nodeId, versionId, versionDate, userId, {SqlSyntax.GetQuotedColumnName("current")}, text)
|
||||
VALUES (@nodeId, @versionId, @versionDate, @userId, 1, @text)", new { nodeId=t.nodeId, versionId= Guid.NewGuid(), versionDate=t.updateDate, userId=t.documentUser, text=t.text });
|
||||
var id = context.Database.ExecuteScalar<int>($@"SELECT @@@@IDENTITY"); // fixme mysql
|
||||
VALUES (@nodeId, @versionId, @versionDate, @userId, 1, @text)", new { nodeId=t.nodeId, versionId=Guid.NewGuid(), versionDate=t.updateDate, userId=t.documentUser, text=t.text });
|
||||
var id = context.Database.ExecuteScalar<int>("SELECT " + getIdentity);
|
||||
context.Database.Execute($"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} SET {SqlSyntax.GetQuotedColumnName("current")}=0 WHERE nodeId=@0 AND id<>@1", (int) t.nodeId, id);
|
||||
context.Database.Execute($@"INSERT INTO {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.DocumentVersion)} (id, templateId, published)
|
||||
VALUES (@id, @templateId, 1)", new { id=id, templateId=t.templateId });
|
||||
VALUES (@id, @templateId, 0)", new { id=id, templateId=t.templateId });
|
||||
|
||||
var versionId = (int) t.versionId;
|
||||
var pdatas = context.Database.Fetch<PropertyDataDto>(Sql().Select<PropertyDataDto>().From<PropertyDataDto>().Where<PropertyDataDto>(x => x.VersionId == versionId));
|
||||
foreach (var pdata in pdatas)
|
||||
{
|
||||
pdata.VersionId = id;
|
||||
context.Database.Insert(pdata);
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
});
|
||||
|
||||
// fixme these extra rows need propertydata too!
|
||||
|
||||
// reduce document to 1 row per content
|
||||
Execute.Sql($@"DELETE FROM {PreTables.Document}
|
||||
WHERE versionId NOT IN (SELECT (versionId) FROM {PreTables.ContentVersion} WHERE {SqlSyntax.GetQuotedColumnName("current")} = 1)");
|
||||
WHERE versionId NOT IN (SELECT (versionId) FROM {PreTables.ContentVersion} WHERE {SqlSyntax.GetQuotedColumnName("current")} = 1) AND (published<>1 OR newest<>1)");
|
||||
|
||||
// drop some document columns
|
||||
Delete.Column("text").FromTable(PreTables.Document);
|
||||
|
||||
@@ -740,7 +740,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
case "UPDATER":
|
||||
// fixme orders by id not letter = bad
|
||||
return GetDatabaseFieldNameForOrderBy(Constants.DatabaseSchema.Tables.Document, "writerUserId");
|
||||
return GetDatabaseFieldNameForOrderBy(Constants.DatabaseSchema.Tables.ContentVersion, "userId");
|
||||
case "PUBLISHED":
|
||||
// fixme kill
|
||||
return GetDatabaseFieldNameForOrderBy(Constants.DatabaseSchema.Tables.Document, "published");
|
||||
|
||||
Reference in New Issue
Block a user