2014-02-26 16:01:31 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Configuration;
|
2014-03-07 12:09:30 +01:00
|
|
|
|
using System.IO;
|
2014-03-04 11:16:42 +11:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web;
|
2014-02-26 16:01:31 +01:00
|
|
|
|
using System.Web.Script.Serialization;
|
2013-02-03 05:06:11 +06:00
|
|
|
|
using System.Web.UI;
|
2014-03-04 11:16:42 +11:00
|
|
|
|
using Umbraco.Core;
|
2014-02-26 16:01:31 +01:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2014-03-07 12:09:30 +01:00
|
|
|
|
using Umbraco.Core.IO;
|
2014-03-04 19:20:36 +11:00
|
|
|
|
using Umbraco.Core.Persistence;
|
2014-02-26 16:01:31 +01:00
|
|
|
|
using Umbraco.Web.Install.InstallSteps;
|
|
|
|
|
|
using Umbraco.Web.Install.Models;
|
2013-02-03 05:06:11 +06:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Install
|
|
|
|
|
|
{
|
2014-03-04 11:16:42 +11:00
|
|
|
|
internal class InstallHelper
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2014-03-04 11:16:42 +11:00
|
|
|
|
private readonly UmbracoContext _umbContext;
|
2014-03-04 19:20:36 +11:00
|
|
|
|
private InstallationType? _installationType;
|
2013-02-03 05:06:11 +06:00
|
|
|
|
|
2014-03-04 11:16:42 +11:00
|
|
|
|
internal InstallHelper(UmbracoContext umbContext)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2014-03-11 18:09:54 +11:00
|
|
|
|
_umbContext = umbContext;
|
2014-03-04 11:16:42 +11:00
|
|
|
|
}
|
2014-02-26 16:49:35 +01:00
|
|
|
|
|
2014-02-27 10:16:30 +01:00
|
|
|
|
|
2014-03-04 11:16:42 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get the installer steps
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <remarks>
|
2014-03-04 19:20:36 +11:00
|
|
|
|
/// The step order returned here is how they will appear on the front-end if they have views assigned
|
2014-03-04 11:16:42 +11:00
|
|
|
|
/// </remarks>
|
2014-03-04 19:20:36 +11:00
|
|
|
|
public IEnumerable<InstallSetupStep> GetAllSteps()
|
2014-03-04 11:16:42 +11:00
|
|
|
|
{
|
|
|
|
|
|
return new List<InstallSetupStep>
|
2014-03-04 19:20:36 +11:00
|
|
|
|
{
|
2014-03-05 14:30:17 +11:00
|
|
|
|
new NewInstallStep(_umbContext.Application),
|
|
|
|
|
|
new UpgradeStep(),
|
2014-03-04 11:16:42 +11:00
|
|
|
|
new FilePermissionsStep(),
|
2014-03-04 19:20:36 +11:00
|
|
|
|
new MajorVersion7UpgradeReport(_umbContext.Application),
|
2014-03-04 11:16:42 +11:00
|
|
|
|
new DatabaseConfigureStep(_umbContext.Application),
|
|
|
|
|
|
new DatabaseInstallStep(_umbContext.Application),
|
2014-03-04 19:20:36 +11:00
|
|
|
|
new DatabaseUpgradeStep(_umbContext.Application),
|
|
|
|
|
|
new StarterKitDownloadStep(_umbContext.Application),
|
|
|
|
|
|
new StarterKitInstallStep(_umbContext.Application, _umbContext.HttpContext),
|
|
|
|
|
|
new StarterKitCleanupStep(_umbContext.Application),
|
2014-03-04 11:16:42 +11:00
|
|
|
|
new SetUmbracoVersionStep(_umbContext.Application, _umbContext.HttpContext),
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2014-02-27 10:16:30 +01:00
|
|
|
|
|
2014-03-04 19:20:36 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the steps that are used only for the current installation type
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public IEnumerable<InstallSetupStep> GetStepsForCurrentInstallType()
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetAllSteps().Where(x => x.InstallTypeTarget.HasFlag(GetInstallationType()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public InstallationType GetInstallationType()
|
|
|
|
|
|
{
|
2014-03-05 14:30:17 +11:00
|
|
|
|
return _installationType ?? (_installationType = IsBrandNewInstall ? InstallationType.NewInstall : InstallationType.Upgrade).Value;
|
2014-03-04 19:20:36 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-07 12:09:30 +01:00
|
|
|
|
internal void DeleteLegacyInstaller()
|
|
|
|
|
|
{
|
2014-03-11 18:09:54 +11:00
|
|
|
|
if (Directory.Exists(IOHelper.MapPath(SystemDirectories.Install)))
|
2014-03-07 12:09:30 +01:00
|
|
|
|
Directory.Move(IOHelper.MapPath(SystemDirectories.Install), IOHelper.MapPath("~/app_data/temp/install_backup"));
|
2014-03-11 18:09:54 +11:00
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists(IOHelper.MapPath("~/Areas/UmbracoInstall")))
|
2014-03-12 15:08:55 +11:00
|
|
|
|
{
|
|
|
|
|
|
Directory.Delete(IOHelper.MapPath("~/Areas/UmbracoInstall"), true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-07 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-04 19:20:36 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Checks if this is a brand new install meaning that there is no configured version and there is no configured database connection
|
|
|
|
|
|
/// </summary>
|
2014-03-05 14:30:17 +11:00
|
|
|
|
private bool IsBrandNewInstall
|
2014-03-04 19:20:36 +11:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var databaseSettings = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName];
|
|
|
|
|
|
if (GlobalSettings.ConfigurationStatus.IsNullOrWhiteSpace()
|
|
|
|
|
|
&& _umbContext.Application.DatabaseContext.IsConnectionStringConfigured(databaseSettings) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
//no version or conn string configured, must be a brand new install
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2014-03-11 18:09:54 +11:00
|
|
|
|
|
2014-03-05 14:30:17 +11:00
|
|
|
|
//now we have to check if this is really a new install, the db might be configured and might contain data
|
|
|
|
|
|
|
|
|
|
|
|
if (_umbContext.Application.DatabaseContext.IsConnectionStringConfigured(databaseSettings) == false
|
|
|
|
|
|
|| _umbContext.Application.DatabaseContext.IsDatabaseConfigured == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//check if we have the default user configured already
|
|
|
|
|
|
var result = _umbContext.Application.DatabaseContext.Database.ExecuteScalar<int>(
|
|
|
|
|
|
"SELECT COUNT(*) FROM umbracoUser WHERE id=0 AND userPassword='default'");
|
|
|
|
|
|
if (result == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
//the user has not been configured
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-11 18:09:54 +11:00
|
|
|
|
// //check if there are any content types configured, if there isn't then we will consider this a new install
|
|
|
|
|
|
// result = _umbContext.Application.DatabaseContext.Database.ExecuteScalar<int>(
|
|
|
|
|
|
// @"SELECT COUNT(*) FROM cmsContentType
|
|
|
|
|
|
// INNER JOIN umbracoNode ON cmsContentType.nodeId = umbracoNode.id
|
|
|
|
|
|
// WHERE umbracoNode.nodeObjectType = @contentType", new {contentType = Constants.ObjectTypes.DocumentType});
|
|
|
|
|
|
// if (result == 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// //no content types have been created
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
// }
|
2014-03-04 19:20:36 +11:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-02-03 05:06:11 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|