Got xml public access structure being migrated to db now - need to do a check it hasn't already been migrated now.
This commit is contained in:
@@ -11,6 +11,12 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
public static class Conventions
|
||||
{
|
||||
public static class PublicAccess
|
||||
{
|
||||
public const string MemberIdClaimType = "MemberId";
|
||||
public const string MemberGroupClaimType = "MemberGroup";
|
||||
}
|
||||
|
||||
public static class Localization
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Insert.Expressions
|
||||
private string GetQuotedValue(object val)
|
||||
{
|
||||
var type = val.GetType();
|
||||
|
||||
switch (Type.GetTypeCode(type))
|
||||
{
|
||||
case TypeCode.Boolean:
|
||||
|
||||
@@ -1,9 +1,116 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero
|
||||
{
|
||||
[Migration("7.3.0", 7, GlobalSettings.UmbracoMigrationName)]
|
||||
public class MovePublicAccessXmlDataToDb : MigrationBase
|
||||
{
|
||||
public override void Up()
|
||||
{
|
||||
var xmlFile = IOHelper.MapPath(SystemFiles.AccessXml);
|
||||
using (var fileStream = File.OpenRead(xmlFile))
|
||||
{
|
||||
var xml = XDocument.Load(fileStream);
|
||||
|
||||
foreach (var page in xml.Root.Elements("page"))
|
||||
{
|
||||
var pageId = (int?) page.Attribute("id");
|
||||
var loginPageId = (int?) page.Attribute("loginPage");
|
||||
var noRightsPageId = (int?)page.Attribute("noRightsPage");
|
||||
if (pageId.HasValue == false || loginPageId.HasValue == false || noRightsPageId.HasValue == false)
|
||||
continue;
|
||||
|
||||
//ensure this page exists!
|
||||
var umbracoNode = Context.Database.FirstOrDefault<NodeDto>("WHERE id = @Id", new {Id = pageId.Value});
|
||||
if (umbracoNode != null)
|
||||
{
|
||||
var loginNode = Context.Database.FirstOrDefault<NodeDto>("WHERE id = @Id", new { Id = loginPageId.Value });
|
||||
if (loginNode != null)
|
||||
{
|
||||
var noRightsPage = Context.Database.FirstOrDefault<NodeDto>("WHERE id = @Id", new { Id = noRightsPageId.Value });
|
||||
if (noRightsPage != null)
|
||||
{
|
||||
var accessId = Guid.NewGuid();
|
||||
Insert.IntoTable("umbracoAccess").Row(new
|
||||
{
|
||||
id = accessId,
|
||||
nodeId = umbracoNode.UniqueId,
|
||||
loginNodeId = loginNode.UniqueId,
|
||||
noAccessNodeId = noRightsPage.UniqueId,
|
||||
createDate = DateTime.Now,
|
||||
updateDate = DateTime.Now
|
||||
});
|
||||
|
||||
//if a memberId has been specified, then add that as a rule
|
||||
var memberId = (string) page.Attribute("memberId");
|
||||
if (memberId.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
Insert.IntoTable("umbracoAccessRule").Row(new
|
||||
{
|
||||
id = Guid.NewGuid(),
|
||||
accessId = accessId,
|
||||
claim = memberId,
|
||||
claimType = Constants.Conventions.PublicAccess.MemberIdClaimType,
|
||||
createDate = DateTime.Now,
|
||||
updateDate = DateTime.Now
|
||||
});
|
||||
}
|
||||
|
||||
//now there should be a member group defined here
|
||||
var memberGroupElement = page.Element("group");
|
||||
if (memberGroupElement != null)
|
||||
{
|
||||
var memberGroup = (string)memberGroupElement.Attribute("id");
|
||||
if (memberGroup.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
//create a member group rule
|
||||
Insert.IntoTable("umbracoAccessRule").Row(new
|
||||
{
|
||||
id = Guid.NewGuid(),
|
||||
accessId = accessId,
|
||||
claim = memberGroup,
|
||||
claimType = Constants.Conventions.PublicAccess.MemberGroupClaimType,
|
||||
createDate = DateTime.Now,
|
||||
updateDate = DateTime.Now
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warn<AddPublicAccessTables>("No umbracoNode could be found with id " + noRightsPageId.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warn<AddPublicAccessTables>("No umbracoNode could be found with id " + loginPageId.Value);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warn<AddPublicAccessTables>("No umbracoNode could be found with id " + pageId.Value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Migration("7.3.0", 6, GlobalSettings.UmbracoMigrationName)]
|
||||
public class AddPublicAccessTables : MigrationBase
|
||||
{
|
||||
|
||||
@@ -9,14 +9,20 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
|
||||
{
|
||||
public override void Up()
|
||||
{
|
||||
Insert.IntoTable("umbracoRelationType").Row(new
|
||||
var exists = Context.Database.FirstOrDefault<RelationTypeDto>("WHERE alias=@alias", new {alias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias});
|
||||
if (exists == null)
|
||||
{
|
||||
dual = false,
|
||||
parentObjectType = Guid.Parse(Constants.ObjectTypes.Document),
|
||||
childObjectType = Guid.Parse(Constants.ObjectTypes.Document),
|
||||
name = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName,
|
||||
alias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias
|
||||
});
|
||||
Insert.IntoTable("umbracoRelationType").Row(new
|
||||
{
|
||||
dual = false,
|
||||
parentObjectType = Guid.Parse(Constants.ObjectTypes.Document),
|
||||
childObjectType = Guid.Parse(Constants.ObjectTypes.Document),
|
||||
name = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName,
|
||||
alias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user