Migrate locks to their own umbracoLocks table
This commit is contained in:
@@ -25,9 +25,6 @@
|
||||
public const int DefaultContentListViewDataTypeId = -95;
|
||||
public const int DefaultMediaListViewDataTypeId = -96;
|
||||
public const int DefaultMembersListViewDataTypeId = -97;
|
||||
|
||||
// identifiers for lock objects
|
||||
public const int ServersLock = -331;
|
||||
}
|
||||
|
||||
public static class DatabaseProviders
|
||||
|
||||
29
src/Umbraco.Core/Models/Rdbms/LockDto.cs
Normal file
29
src/Umbraco.Core/Models/Rdbms/LockDto.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.DatabaseAnnotations;
|
||||
|
||||
namespace Umbraco.Core.Models.Rdbms
|
||||
{
|
||||
[TableName("umbracoLock")]
|
||||
[PrimaryKey("id")]
|
||||
[ExplicitColumns]
|
||||
internal class LockDto
|
||||
{
|
||||
public LockDto()
|
||||
{
|
||||
Value = 1;
|
||||
}
|
||||
|
||||
[Column("id")]
|
||||
[PrimaryKeyColumn(Name = "PK_umbracoLock")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("value")]
|
||||
[NullSetting(NullSetting = NullSettings.NotNull)]
|
||||
public int Value { get; set; }
|
||||
|
||||
[Column("name")]
|
||||
[NullSetting(NullSetting = NullSettings.NotNull)]
|
||||
[Length(64)]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
11
src/Umbraco.Core/Persistence/Constants-Locks.cs
Normal file
11
src/Umbraco.Core/Persistence/Constants-Locks.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
static partial class Constants
|
||||
{
|
||||
public static class Locks
|
||||
{
|
||||
public const int Servers = -331;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
ValidateDatabase(database);
|
||||
|
||||
database.Execute("UPDATE umbracoNode SET sortOrder = (CASE WHEN (sortOrder=1) THEN -1 ELSE 1 END) WHERE id=@id",
|
||||
database.Execute("UPDATE umbracoLock SET value = (CASE WHEN (value=1) THEN -1 ELSE 1 END) WHERE id=@id",
|
||||
new { @id = nodeId });
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
ValidateDatabase(database);
|
||||
|
||||
database.ExecuteScalar<int>("SELECT sortOrder FROM umbracoNode WHERE id=@id",
|
||||
database.ExecuteScalar<int>("SELECT value FROM umbracoLock WHERE id=@id",
|
||||
new { @id = nodeId });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,12 @@ namespace Umbraco.Core.Persistence.Migrations.Initial
|
||||
CreateUmbracNodeData();
|
||||
}
|
||||
|
||||
if(tableName.Equals("cmsContentType"))
|
||||
if (tableName.Equals("umbracoLock"))
|
||||
{
|
||||
CreateUmbracoLockData();
|
||||
}
|
||||
|
||||
if (tableName.Equals("cmsContentType"))
|
||||
{
|
||||
CreateCmsContentTypeData();
|
||||
}
|
||||
@@ -141,9 +146,12 @@ namespace Umbraco.Core.Persistence.Migrations.Initial
|
||||
//_database.Insert("umbracoNode", "id", false, new NodeDto { NodeId = 1038, Trashed = false, ParentId = -1, UserId = 0, Level = 1, Path = "-1,1038", SortOrder = 2, UniqueId = new Guid("1251c96c-185c-4e9b-93f4-b48205573cbd"), Text = "Simple Editor", NodeObjectType = new Guid(Constants.ObjectTypes.DataType), CreateDate = DateTime.Now });
|
||||
|
||||
//_database.Insert("umbracoNode", "id", false, new NodeDto { NodeId = 1042, Trashed = false, ParentId = -1, UserId = 0, Level = 1, Path = "-1,1042", SortOrder = 2, UniqueId = new Guid("0a452bd5-83f9-4bc3-8403-1286e13fb77e"), Text = "Macro Container", NodeObjectType = new Guid(Constants.ObjectTypes.DataType), CreateDate = DateTime.Now });
|
||||
}
|
||||
|
||||
private void CreateUmbracoLockData()
|
||||
{
|
||||
// all lock objects
|
||||
_database.Insert("umbracoNode", "id", false, new NodeDto { NodeId = Constants.System.ServersLock, Trashed = false, ParentId = -1, UserId = 0, Level = 1, Path = "-1," + Constants.System.ServersLock, SortOrder = 1, UniqueId = new Guid("0AF5E610-A310-4B6F-925F-E928D5416AF7"), Text = "LOCK: Servers", NodeObjectType = Constants.ObjectTypes.LockObjectGuid, CreateDate = DateTime.Now });
|
||||
_database.Insert("umbracoLock", "id", false, new LockDto { Id = Constants.Locks.Servers, Name = "Servers" });
|
||||
}
|
||||
|
||||
private void CreateCmsContentTypeData()
|
||||
|
||||
@@ -84,7 +84,8 @@ namespace Umbraco.Core.Persistence.Migrations.Initial
|
||||
{45, typeof (MigrationDto)},
|
||||
{46, typeof (UmbracoDeployChecksumDto)},
|
||||
{47, typeof (UmbracoDeployDependencyDto)},
|
||||
{48, typeof (RedirectUrlDto) }
|
||||
{48, typeof (RedirectUrlDto) },
|
||||
{49, typeof (LockDto) }
|
||||
};
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenFiveFive
|
||||
{
|
||||
[Migration("7.5.5", 101, GlobalSettings.UmbracoMigrationName)]
|
||||
public class AddLockObjects : MigrationBase
|
||||
{
|
||||
public AddLockObjects(ISqlSyntaxProvider sqlSyntax, ILogger logger)
|
||||
: base(sqlSyntax, logger)
|
||||
{ }
|
||||
|
||||
public override void Up()
|
||||
{
|
||||
EnsureLockObject(Constants.Locks.Servers, "Servers");
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
|
||||
private void EnsureLockObject(int id, string name)
|
||||
{
|
||||
Execute.Code(db =>
|
||||
{
|
||||
var exists = db.Exists<LockDto>(id);
|
||||
if (exists) return string.Empty;
|
||||
// be safe: delete old umbracoNode lock objects if any
|
||||
db.Execute("DELETE FROM umbracoNode WHERE id=@id;", new { id });
|
||||
// then create umbracoLock object
|
||||
db.Execute("INSERT umbracoLock (id, name, value) VALUES (@id, '@name', 1);", new { id, name });
|
||||
return string.Empty;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenFiveFive
|
||||
{
|
||||
[Migration("7.5.5", 100, GlobalSettings.UmbracoMigrationName)]
|
||||
public class AddLockTable : MigrationBase
|
||||
{
|
||||
public AddLockTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
|
||||
: base(sqlSyntax, logger)
|
||||
{ }
|
||||
|
||||
public override void Up()
|
||||
{
|
||||
var tables = SqlSyntax.GetTablesInSchema(Context.Database).ToArray();
|
||||
if (tables.InvariantContains("umbracoLock") == false)
|
||||
{
|
||||
Create.Table("umbracoLock")
|
||||
.WithColumn("id").AsInt32().PrimaryKey("PK_umbracoLock")
|
||||
.WithColumn("value").AsInt32().NotNullable()
|
||||
.WithColumn("name").AsString(64).NotNullable();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenFiveZer
|
||||
// for some reason it was not, so it was created during migrations but not during
|
||||
// new installs, so for ppl that upgrade, make sure they have it
|
||||
|
||||
EnsureLockObject(Constants.System.ServersLock, "0AF5E610-A310-4B6F-925F-E928D5416AF7", "LOCK: Servers");
|
||||
EnsureLockObject(Constants.Locks.Servers, "0AF5E610-A310-4B6F-925F-E928D5416AF7", "LOCK: Servers");
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
|
||||
Create.Column("isMaster").OnTable("umbracoServer").AsBoolean().NotNullable().WithDefaultValue(0);
|
||||
}
|
||||
|
||||
EnsureLockObject(Constants.System.ServersLock, "0AF5E610-A310-4B6F-925F-E928D5416AF7", "LOCK: Servers");
|
||||
EnsureLockObject(Constants.Locks.Servers, "0AF5E610-A310-4B6F-925F-E928D5416AF7", "LOCK: Servers");
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Umbraco.Core.Services
|
||||
private readonly static string CurrentServerIdentityValue = NetworkHelper.MachineName // eg DOMAIN\SERVER
|
||||
+ "/" + HttpRuntime.AppDomainAppId; // eg /LM/S3SVC/11/ROOT
|
||||
|
||||
private static readonly int[] LockingRepositoryIds = { Constants.System.ServersLock };
|
||||
private static readonly int[] LockingRepositoryIds = { Constants.Locks.Servers };
|
||||
private ServerRole _currentServerRole = ServerRole.Unknown;
|
||||
private readonly LockingRepository<IServerRegistrationRepository> _lrepo;
|
||||
|
||||
|
||||
@@ -406,6 +406,7 @@
|
||||
<Compile Include="Media\Exif\ExifTag.cs" />
|
||||
<Compile Include="Media\Exif\ExifTagFactory.cs" />
|
||||
<Compile Include="Models\Rdbms\AccessRuleDto.cs" />
|
||||
<Compile Include="Models\Rdbms\LockDto.cs" />
|
||||
<Compile Include="Models\Rdbms\RedirectUrlDto.cs" />
|
||||
<Compile Include="Models\Rdbms\DocumentPublishedReadOnlyDto.cs" />
|
||||
<Compile Include="Models\Rdbms\ExternalLoginDto.cs" />
|
||||
@@ -415,6 +416,7 @@
|
||||
<Compile Include="Models\UmbracoDomain.cs" />
|
||||
<Compile Include="Models\DoNotCloneAttribute.cs" />
|
||||
<Compile Include="Models\IDomain.cs" />
|
||||
<Compile Include="Persistence\Constants-Locks.cs" />
|
||||
<Compile Include="Persistence\DatabaseNodeLockExtensions.cs" />
|
||||
<Compile Include="Persistence\Factories\ExternalLoginFactory.cs" />
|
||||
<Compile Include="Persistence\Factories\MigrationEntryFactory.cs" />
|
||||
@@ -428,6 +430,8 @@
|
||||
<Compile Include="Persistence\Mappers\MigrationEntryMapper.cs" />
|
||||
<Compile Include="Persistence\Migrations\LocalMigrationContext.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionFourOneZero\AddPreviewXmlTable.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenFiveFive\AddLockObjects.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenFiveFive\AddLockTable.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenFiveZero\EnsureServersLockObject.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenFiveZero\AddRedirectUrlTable.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenFiveZero\RemoveStylesheetDataAndTablesAgain.cs" />
|
||||
|
||||
Reference in New Issue
Block a user