Installer logic working for a new installer on sqlce
This commit is contained in:
@@ -24,34 +24,36 @@ namespace Umbraco.Web.Install
|
||||
steps.AddRange(new InstallSetupStep[]
|
||||
{
|
||||
new FilePermissionsStep()
|
||||
{
|
||||
Name = "Permissions",
|
||||
{
|
||||
ServerOrder = 0,
|
||||
},
|
||||
new UserStep(umbracoContext.Application)
|
||||
{
|
||||
Name = "User",
|
||||
ServerOrder = 2,
|
||||
ServerOrder = 4,
|
||||
},
|
||||
new DatabaseConfigureStep(umbracoContext.Application)
|
||||
{
|
||||
Name = "Database",
|
||||
ServerOrder = 1,
|
||||
},
|
||||
new DatabaseInstallStep(umbracoContext.Application)
|
||||
{
|
||||
ServerOrder = 2,
|
||||
},
|
||||
new DatabaseUpgradeStep(umbracoContext.Application)
|
||||
{
|
||||
ServerOrder = 3,
|
||||
},
|
||||
new StarterKitDownloadStep()
|
||||
{
|
||||
Name = "StarterKitDownload",
|
||||
ServerOrder = 3,
|
||||
ServerOrder = 5,
|
||||
},
|
||||
new StarterKitInstallStep(umbracoContext.Application, umbracoContext.HttpContext)
|
||||
{
|
||||
Name = "StarterKitInstall",
|
||||
ServerOrder = 4,
|
||||
ServerOrder = 6,
|
||||
},
|
||||
new StarterKitCleanupStep()
|
||||
{
|
||||
Name = "StarterKitCleanup",
|
||||
ServerOrder = 5,
|
||||
ServerOrder = 7,
|
||||
}
|
||||
});
|
||||
return steps;
|
||||
|
||||
@@ -1,35 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
//internal class DatabaseInstallStep : IInstallStep<object>
|
||||
//{
|
||||
// private readonly ApplicationContext _applicationContext;
|
||||
|
||||
// public DatabaseInstallStep(ApplicationContext applicationContext)
|
||||
// {
|
||||
// _applicationContext = applicationContext;
|
||||
// }
|
||||
|
||||
// public IDictionary<string, object> Setup(object model)
|
||||
// {
|
||||
// if (CheckConnection(database) == false)
|
||||
// {
|
||||
// throw new InvalidOperationException("Could not connect to the database");
|
||||
// }
|
||||
// ConfigureConnection(database);
|
||||
// return null;
|
||||
// }
|
||||
//}
|
||||
|
||||
[InstallSetupStep("DatabaseConfigure", "database")]
|
||||
internal class DatabaseConfigureStep : InstallSetupStep<DatabaseModel>
|
||||
{
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
@@ -106,7 +90,48 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
|
||||
public override string View
|
||||
{
|
||||
get { return "database"; }
|
||||
get { return ShouldDisplayView() ? base.View : ""; }
|
||||
}
|
||||
|
||||
private bool ShouldDisplayView()
|
||||
{
|
||||
//If the connection string is already present in web.config we don't need to show the settings page and we jump to installing/upgrading.
|
||||
var databaseSettings = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName];
|
||||
|
||||
var dbIsSqlCe = false;
|
||||
if (databaseSettings != null && databaseSettings.ProviderName != null)
|
||||
dbIsSqlCe = databaseSettings.ProviderName == "System.Data.SqlServerCe.4.0";
|
||||
var sqlCeDatabaseExists = false;
|
||||
if (dbIsSqlCe)
|
||||
{
|
||||
var datasource = databaseSettings.ConnectionString.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory").ToString());
|
||||
var filePath = datasource.Replace("Data Source=", string.Empty);
|
||||
sqlCeDatabaseExists = File.Exists(filePath);
|
||||
}
|
||||
|
||||
// Either the connection details are not fully specified or it's a SQL CE database that doesn't exist yet
|
||||
if (databaseSettings == null
|
||||
|| string.IsNullOrWhiteSpace(databaseSettings.ConnectionString) || string.IsNullOrWhiteSpace(databaseSettings.ProviderName)
|
||||
|| (dbIsSqlCe && sqlCeDatabaseExists == false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Since a connection string was present we verify whether this is an upgrade or an empty db
|
||||
var result = ApplicationContext.Current.DatabaseContext.ValidateDatabaseSchema();
|
||||
var determinedVersion = result.DetermineInstalledVersion();
|
||||
if (determinedVersion.Equals(new Version(0, 0, 0)))
|
||||
{
|
||||
//Fresh install
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Upgrade
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
50
src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs
Normal file
50
src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep("DatabaseInstall", "")]
|
||||
internal class DatabaseInstallStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
|
||||
public DatabaseInstallStep(ApplicationContext applicationContext)
|
||||
{
|
||||
_applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public override IDictionary<string, object> Execute(object model)
|
||||
{
|
||||
var result = _applicationContext.DatabaseContext.CreateDatabaseSchemaAndData();
|
||||
if (result.RequiresUpgrade == false)
|
||||
{
|
||||
HandleConnectionStrings();
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
{"upgrade", true}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static void HandleConnectionStrings()
|
||||
{
|
||||
// Remove legacy umbracoDbDsn configuration setting if it exists and connectionstring also exists
|
||||
if (ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName] != null)
|
||||
{
|
||||
GlobalSettings.RemoveSetting(GlobalSettings.UmbracoConnectionName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var ex = new ArgumentNullException(string.Format("ConfigurationManager.ConnectionStrings[{0}]", GlobalSettings.UmbracoConnectionName), "Install / upgrade did not complete successfully, umbracoDbDSN was not set in the connectionStrings section");
|
||||
LogHelper.Error<DatabaseInstallStep>("", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs
Normal file
44
src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep("DatabaseUpgrade", "")]
|
||||
internal class DatabaseUpgradeStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
|
||||
public DatabaseUpgradeStep(ApplicationContext applicationContext)
|
||||
{
|
||||
_applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public override IDictionary<string, object> Execute(object model)
|
||||
{
|
||||
var installSteps = InstallStatusTracker.GetStatus();
|
||||
//this step relies on the preious one completed - because it has stored some information we need
|
||||
if (installSteps.Any(x => x.Key == "DatabaseConfigure") == false)
|
||||
{
|
||||
throw new InvalidOperationException("Could not find previous step: DatabaseConfigure of the installation, package install cannot continue");
|
||||
}
|
||||
var previousStep = installSteps["DatabaseConfigure"];
|
||||
var upgrade = previousStep.AdditionalData.ContainsKey("upgrade");
|
||||
|
||||
if (upgrade)
|
||||
{
|
||||
LogHelper.Info<DatabaseUpgradeStep>("Running 'Upgrade' service");
|
||||
|
||||
var result = _applicationContext.DatabaseContext.UpgradeSchemaAndData();
|
||||
|
||||
DatabaseInstallStep.HandleConnectionStrings();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep("Permissions", "")]
|
||||
internal class FilePermissionsStep : InstallSetupStep<object>
|
||||
{
|
||||
public override IDictionary<string, object> Execute(object model)
|
||||
@@ -123,9 +124,5 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
}
|
||||
}
|
||||
|
||||
public override string View
|
||||
{
|
||||
get { return string.Empty; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
internal interface IInstallStep<in T>
|
||||
{
|
||||
IDictionary<string, object> Setup(T model);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep("StarterKitCleanup", "")]
|
||||
internal class StarterKitCleanupStep : InstallSetupStep<object>
|
||||
{
|
||||
public override IDictionary<string, object> Execute(object model)
|
||||
@@ -36,9 +37,5 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
library.RefreshContent();
|
||||
}
|
||||
|
||||
public override string View
|
||||
{
|
||||
get { return string.Empty; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep("StarterKitDownload", "starterKit")]
|
||||
internal class StarterKitDownloadStep : InstallSetupStep<Guid>
|
||||
{
|
||||
private const string RepoGuid = "65194810-1f85-11dd-bd0b-0800200c9a66";
|
||||
@@ -52,9 +53,5 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
|
||||
}
|
||||
|
||||
public override string View
|
||||
{
|
||||
get { return "starterKit"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep("StarterKitInstall", "")]
|
||||
internal class StarterKitInstallStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
@@ -46,9 +47,5 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
installer.InstallBusinessLogic(manifestId, packageFile);
|
||||
}
|
||||
|
||||
public override string View
|
||||
{
|
||||
get { return string.Empty; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
|
||||
[InstallSetupStep("User", "user")]
|
||||
internal class UserStep : InstallSetupStep<UserModel>
|
||||
{
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
@@ -65,9 +67,5 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string View
|
||||
{
|
||||
get { return "user"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,18 @@ namespace Umbraco.Web.Install.Models
|
||||
[DataContract(Name = "step", Namespace = "")]
|
||||
public abstract class InstallSetupStep<T> : InstallSetupStep
|
||||
{
|
||||
protected InstallSetupStep()
|
||||
{
|
||||
var att = GetType().GetCustomAttribute<InstallSetupStepAttribute>(false);
|
||||
if (att == null)
|
||||
{
|
||||
throw new InvalidOperationException("Each step must be attributed");
|
||||
}
|
||||
_attribute = att;
|
||||
}
|
||||
|
||||
private readonly InstallSetupStepAttribute _attribute;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the step model type on the server side so we can bind it
|
||||
/// </summary>
|
||||
@@ -27,18 +39,32 @@ namespace Umbraco.Web.Install.Models
|
||||
{
|
||||
get { return View.IsNullOrWhiteSpace() == false; }
|
||||
}
|
||||
//[IgnoreDataMember]
|
||||
//public Func<T, IDictionary<string, object>> ExecuteCallback { get; set; }
|
||||
|
||||
public override string View
|
||||
{
|
||||
get { return _attribute.View; }
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract(Name = "step", Namespace = "")]
|
||||
public abstract class InstallSetupStep
|
||||
{
|
||||
protected InstallSetupStep()
|
||||
{
|
||||
var att = GetType().GetCustomAttribute<InstallSetupStepAttribute>(false);
|
||||
if (att == null)
|
||||
{
|
||||
throw new InvalidOperationException("Each step must be attributed");
|
||||
}
|
||||
Name = att.Name;
|
||||
View = att.View;
|
||||
}
|
||||
|
||||
[DataMember(Name = "name")]
|
||||
public string Name { get; set; }
|
||||
public string Name { get; private set; }
|
||||
|
||||
[DataMember(Name = "view")]
|
||||
public abstract string View { get; }
|
||||
public virtual string View { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines what order this step needs to execute on the server side since the
|
||||
|
||||
16
src/Umbraco.Web/Install/Models/InstallSetupStepAttribute.cs
Normal file
16
src/Umbraco.Web/Install/Models/InstallSetupStepAttribute.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Web.Install.Models
|
||||
{
|
||||
public sealed class InstallSetupStepAttribute : Attribute
|
||||
{
|
||||
public InstallSetupStepAttribute(string name, string view)
|
||||
{
|
||||
Name = name;
|
||||
View = view;
|
||||
}
|
||||
|
||||
public string Name { get; private set; }
|
||||
public string View { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -305,8 +305,9 @@
|
||||
<Compile Include="Install\InstallException.cs" />
|
||||
<Compile Include="Install\InstallStatusTracker.cs" />
|
||||
<Compile Include="Install\InstallSteps\DatabaseConfigureStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\DatabaseInstallStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\DatabaseUpgradeStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\FilePermissionsStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\IInstallStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\StarterKitCleanupStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\StarterKitDownloadStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\StarterKitInstallStep.cs" />
|
||||
@@ -315,6 +316,7 @@
|
||||
<Compile Include="Install\Models\DatabaseType.cs" />
|
||||
<Compile Include="Install\Models\InstallSetup.cs" />
|
||||
<Compile Include="Install\Models\InstallSetupStep.cs" />
|
||||
<Compile Include="Install\Models\InstallSetupStepAttribute.cs" />
|
||||
<Compile Include="Install\Models\InstallTrackingItem.cs" />
|
||||
<Compile Include="Install\Models\UserModel.cs" />
|
||||
<Compile Include="Install\UmbracoInstallArea.cs" />
|
||||
|
||||
Reference in New Issue
Block a user