Gets the IsConfigured check checking the migration data, updates the install controller to ensure there's no infinite redirects and to use the IsUpgrading flag. Now to add entries to the table when the migrations have executed.

This commit is contained in:
Shannon
2015-06-22 16:22:47 +02:00
parent a1d7f2d8b3
commit 8e1e7a8676
8 changed files with 85 additions and 61 deletions

View File

@@ -38,6 +38,8 @@ namespace Umbraco.Core
_services = serviceContext; _services = serviceContext;
ApplicationCache = cache; ApplicationCache = cache;
ProfilingLogger = logger; ProfilingLogger = logger;
Init();
} }
/// <summary> /// <summary>
@@ -60,6 +62,8 @@ namespace Umbraco.Core
public ApplicationContext(CacheHelper cache) public ApplicationContext(CacheHelper cache)
{ {
ApplicationCache = cache; ApplicationCache = cache;
Init();
} }
/// <summary> /// <summary>
@@ -190,16 +194,10 @@ namespace Umbraco.Core
// GlobalSettings.CurrentVersion returns the hard-coded "current version" // GlobalSettings.CurrentVersion returns the hard-coded "current version"
// the system is configured if they match // the system is configured if they match
// if they don't, install runs, updates web.config (presumably) and updates GlobalSettings.ConfiguredStatus // if they don't, install runs, updates web.config (presumably) and updates GlobalSettings.ConfiguredStatus
//
// then there is Application["umbracoNeedConfiguration"] which makes no sense... getting rid of it... SD: I have actually remove that now!
//
public bool IsConfigured public bool IsConfigured
{ {
// todo - we should not do this - ok for now get { return _configured.Value; }
get
{
return Configured;
}
} }
/// <summary> /// <summary>
@@ -233,37 +231,51 @@ namespace Umbraco.Core
/// </remarks> /// </remarks>
internal string OriginalRequestUrl { get; set; } internal string OriginalRequestUrl { get; set; }
private bool _versionsDifferenceReported;
/// <summary> private Lazy<bool> _configured;
/// Checks if the version configured matches the assembly version
/// </summary>
private bool Configured
{
get
{
try
{
var configStatus = ConfigurationStatus;
var currentVersion = UmbracoVersion.Current.ToString(3);
var ok = configStatus == currentVersion;
if (ok == false && _versionsDifferenceReported == false) private void Init()
{ {
// remember it's been reported so we don't flood the log
// no thread-safety so there may be a few log entries, doesn't matter //Create the lazy value to resolve whether or not the application is 'configured'
_versionsDifferenceReported = true; _configured = new Lazy<bool>(() =>
{
try
{
var configStatus = ConfigurationStatus;
var currentVersion = UmbracoVersion.Current.ToString(3);
var ok = configStatus == currentVersion;
if (ok)
{
//The versions are the same in config, but are they the same in the database. We can only check this
// if we have a db context available, if we don't then we are not installed anyways
if (DatabaseContext.IsDatabaseConfigured && DatabaseContext.CanConnect)
{
var found = Services.MigrationEntryService.FindEntry(GlobalSettings.UmbracoMigrationName, UmbracoVersion.Current);
if (found == null)
{
//we haven't executed this migration in this environment, so even though the config versions match,
// this db has not been updated.
ProfilingLogger.Logger.Debug<ApplicationContext>("The migration for version: '" + currentVersion + " has not been executed, there is no record in the database");
ok = false;
}
}
}
else
{
ProfilingLogger.Logger.Debug<ApplicationContext>("CurrentVersion different from configStatus: '" + currentVersion + "','" + configStatus + "'"); ProfilingLogger.Logger.Debug<ApplicationContext>("CurrentVersion different from configStatus: '" + currentVersion + "','" + configStatus + "'");
} }
return ok; return ok;
} }
catch catch
{ {
return false; return false;
} }
}
} });
}
private string ConfigurationStatus private string ConfigurationStatus
{ {

View File

@@ -242,6 +242,7 @@ namespace Umbraco.Core.Configuration
} }
} }
//TODO: Move these to constants!
public const string UmbracoConnectionName = "umbracoDbDSN"; public const string UmbracoConnectionName = "umbracoDbDSN";
public const string UmbracoMigrationName = "Umbraco"; public const string UmbracoMigrationName = "Umbraco";

View File

@@ -1,9 +1,10 @@
using Umbraco.Core.Models; using System;
using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories namespace Umbraco.Core.Persistence.Repositories
{ {
public interface IMigrationEntryRepository : IRepositoryQueryable<int, IMigrationEntry> public interface IMigrationEntryRepository : IRepositoryQueryable<int, IMigrationEntry>
{ {
IMigrationEntry FindEntry(string migrationName, Version version);
} }
} }

View File

@@ -112,5 +112,18 @@ namespace Umbraco.Core.Persistence.Repositories
entity.ResetDirtyProperties(); entity.ResetDirtyProperties();
} }
public IMigrationEntry FindEntry(string migrationName, Version version)
{
var sql = new Sql().Select("*")
.From<MigrationDto>(SqlSyntax)
.Where<MigrationDto>(x => x.Name.InvariantEquals(migrationName) && x.Version == version.ToString());
var result = Database.FirstOrDefault<MigrationDto>(sql);
var factory = new MigrationEntryFactory();
return result == null ? null : factory.BuildEntity(result);
}
} }
} }

View File

@@ -54,9 +54,7 @@ namespace Umbraco.Core.Services
var uow = UowProvider.GetUnitOfWork(); var uow = UowProvider.GetUnitOfWork();
using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow)) using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow))
{ {
var query = Query<IMigrationEntry>.Builder return repo.FindEntry(migrationName, version);
.Where(x => x.MigrationName.ToUpper() == migrationName.ToUpper() && x.Version == version);
return repo.GetByQuery(query).FirstOrDefault();
} }
} }

View File

@@ -9,7 +9,7 @@ namespace Umbraco.Core.Sync
/// </summary> /// </summary>
public sealed class DatabaseServerRegistrar : IServerRegistrar public sealed class DatabaseServerRegistrar : IServerRegistrar
{ {
private readonly Lazy<ServerRegistrationService> _registrationService; private readonly Lazy<IServerRegistrationService> _registrationService;
/// <summary> /// <summary>
/// Gets or sets the registrar options. /// Gets or sets the registrar options.
@@ -21,7 +21,7 @@ namespace Umbraco.Core.Sync
/// </summary> /// </summary>
/// <param name="registrationService">The registration service.</param> /// <param name="registrationService">The registration service.</param>
/// <param name="options">Some options.</param> /// <param name="options">Some options.</param>
public DatabaseServerRegistrar(Lazy<ServerRegistrationService> registrationService, DatabaseServerRegistrarOptions options) public DatabaseServerRegistrar(Lazy<IServerRegistrationService> registrationService, DatabaseServerRegistrarOptions options)
{ {
if (registrationService == null) throw new ArgumentNullException("registrationService"); if (registrationService == null) throw new ArgumentNullException("registrationService");
if (options == null) throw new ArgumentNullException("options"); if (options == null) throw new ArgumentNullException("options");

View File

@@ -59,9 +59,15 @@
redirectUrl = Url.Action("AuthorizeUpgrade", "BackOffice") redirectUrl = Url.Action("AuthorizeUpgrade", "BackOffice")
}); });
} }
@Html.BareMinimumServerVariables(Url, externalLoginUrl) @Html.BareMinimumServerVariablesScript(Url, externalLoginUrl)
@Html.AngularExternalLoginInfoValues((IEnumerable<string>)ViewBag.ExternalSignInError) <script type="text/javascript">
document.angularReady = function (app) {
@Html.AngularExternalLoginInfoValuesScript((IEnumerable<string>)ViewBag.ExternalSignInError)
}
</script>
@*And finally we can load in our angular app*@ @*And finally we can load in our angular app*@
<script type="text/javascript" src="lib/rgrove-lazyload/lazyload.js"></script> <script type="text/javascript" src="lib/rgrove-lazyload/lazyload.js"></script>

View File

@@ -37,30 +37,23 @@ namespace Umbraco.Web.Install.Controllers
[HttpGet] [HttpGet]
public ActionResult Index() public ActionResult Index()
{ {
//if this is not an upgrade we will log in with the default user. if (ApplicationContext.Current.IsConfigured)
// It's not considered an upgrade if the ConfigurationStatus is missing or empty or if the db is not configured.
if (string.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus) == false
&& ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured)
{ {
Version current; return Redirect(SystemDirectories.Umbraco.EnsureEndsWith('/'));
if (Version.TryParse(GlobalSettings.ConfigurationStatus, out current)) }
{
//check if we are on the current version, and not let the installer execute
if (current == UmbracoVersion.Current)
{
return Redirect(SystemDirectories.Umbraco.EnsureEndsWith('/'));
}
}
if (ApplicationContext.Current.IsUpgrading)
{
var result = _umbracoContext.Security.ValidateCurrentUser(false); var result = _umbracoContext.Security.ValidateCurrentUser(false);
switch (result) switch (result)
{ {
case ValidateRequestAttempt.FailedNoPrivileges: case ValidateRequestAttempt.FailedNoPrivileges:
case ValidateRequestAttempt.FailedNoContextId: case ValidateRequestAttempt.FailedNoContextId:
return Redirect(SystemDirectories.Umbraco + "/AuthorizeUpgrade?redir=" + Server.UrlEncode(Request.RawUrl)); return Redirect(SystemDirectories.Umbraco + "/AuthorizeUpgrade?redir=" + Server.UrlEncode(Request.RawUrl));
} }
} }
//gen the install base url //gen the install base url
ViewBag.InstallApiBaseUrl = Url.GetUmbracoApiService("GetSetup", "InstallApi", "UmbracoInstall").TrimEnd("GetSetup"); ViewBag.InstallApiBaseUrl = Url.GetUmbracoApiService("GetSetup", "InstallApi", "UmbracoInstall").TrimEnd("GetSetup");