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:
@@ -38,6 +38,8 @@ namespace Umbraco.Core
|
||||
_services = serviceContext;
|
||||
ApplicationCache = cache;
|
||||
ProfilingLogger = logger;
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -60,6 +62,8 @@ namespace Umbraco.Core
|
||||
public ApplicationContext(CacheHelper cache)
|
||||
{
|
||||
ApplicationCache = cache;
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -190,16 +194,10 @@ namespace Umbraco.Core
|
||||
// GlobalSettings.CurrentVersion returns the hard-coded "current version"
|
||||
// the system is configured if they match
|
||||
// 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
|
||||
{
|
||||
// todo - we should not do this - ok for now
|
||||
get
|
||||
{
|
||||
return Configured;
|
||||
}
|
||||
get { return _configured.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -233,37 +231,51 @@ namespace Umbraco.Core
|
||||
/// </remarks>
|
||||
internal string OriginalRequestUrl { get; set; }
|
||||
|
||||
private bool _versionsDifferenceReported;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
private Lazy<bool> _configured;
|
||||
|
||||
if (ok == false && _versionsDifferenceReported == false)
|
||||
{
|
||||
// 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
|
||||
_versionsDifferenceReported = true;
|
||||
private void Init()
|
||||
{
|
||||
|
||||
//Create the lazy value to resolve whether or not the application is 'configured'
|
||||
_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 + "'");
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private string ConfigurationStatus
|
||||
{
|
||||
|
||||
@@ -242,6 +242,7 @@ namespace Umbraco.Core.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Move these to constants!
|
||||
public const string UmbracoConnectionName = "umbracoDbDSN";
|
||||
public const string UmbracoMigrationName = "Umbraco";
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using Umbraco.Core.Models;
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IMigrationEntryRepository : IRepositoryQueryable<int, IMigrationEntry>
|
||||
{
|
||||
|
||||
IMigrationEntry FindEntry(string migrationName, Version version);
|
||||
}
|
||||
}
|
||||
@@ -112,5 +112,18 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,9 +54,7 @@ namespace Umbraco.Core.Services
|
||||
var uow = UowProvider.GetUnitOfWork();
|
||||
using (var repo = RepositoryFactory.CreateMigrationEntryRepository(uow))
|
||||
{
|
||||
var query = Query<IMigrationEntry>.Builder
|
||||
.Where(x => x.MigrationName.ToUpper() == migrationName.ToUpper() && x.Version == version);
|
||||
return repo.GetByQuery(query).FirstOrDefault();
|
||||
return repo.FindEntry(migrationName, version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Umbraco.Core.Sync
|
||||
/// </summary>
|
||||
public sealed class DatabaseServerRegistrar : IServerRegistrar
|
||||
{
|
||||
private readonly Lazy<ServerRegistrationService> _registrationService;
|
||||
private readonly Lazy<IServerRegistrationService> _registrationService;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the registrar options.
|
||||
@@ -21,7 +21,7 @@ namespace Umbraco.Core.Sync
|
||||
/// </summary>
|
||||
/// <param name="registrationService">The registration service.</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 (options == null) throw new ArgumentNullException("options");
|
||||
|
||||
@@ -59,9 +59,15 @@
|
||||
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*@
|
||||
<script type="text/javascript" src="lib/rgrove-lazyload/lazyload.js"></script>
|
||||
|
||||
@@ -37,30 +37,23 @@ namespace Umbraco.Web.Install.Controllers
|
||||
[HttpGet]
|
||||
public ActionResult Index()
|
||||
{
|
||||
//if this is not an upgrade we will log in with the default user.
|
||||
// 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)
|
||||
if (ApplicationContext.Current.IsConfigured)
|
||||
{
|
||||
Version current;
|
||||
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('/'));
|
||||
}
|
||||
}
|
||||
return Redirect(SystemDirectories.Umbraco.EnsureEndsWith('/'));
|
||||
}
|
||||
|
||||
if (ApplicationContext.Current.IsUpgrading)
|
||||
{
|
||||
var result = _umbracoContext.Security.ValidateCurrentUser(false);
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case ValidateRequestAttempt.FailedNoPrivileges:
|
||||
case ValidateRequestAttempt.FailedNoContextId:
|
||||
return Redirect(SystemDirectories.Umbraco + "/AuthorizeUpgrade?redir=" + Server.UrlEncode(Request.RawUrl));
|
||||
case ValidateRequestAttempt.FailedNoContextId:
|
||||
return Redirect(SystemDirectories.Umbraco + "/AuthorizeUpgrade?redir=" + Server.UrlEncode(Request.RawUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//gen the install base url
|
||||
ViewBag.InstallApiBaseUrl = Url.GetUmbracoApiService("GetSetup", "InstallApi", "UmbracoInstall").TrimEnd("GetSetup");
|
||||
|
||||
Reference in New Issue
Block a user