Tweaking a few aspects of the moment of setup

Sites subdirectory may need to be created
Shouldn't write out the site-exists file until the setup transaction has committed
Host reinitialize should be called outside of the lifetime of the temporary shell to avoid a xact deadlock

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-02-09 00:41:23 -08:00
parent fd79fd9774
commit ee119699a0
3 changed files with 20 additions and 11 deletions

View File

@@ -33,6 +33,8 @@ namespace Orchard.Core.Settings.Services {
item.Record.SiteName = "My Orchard Project Application";
item.Record.PageTitleSeparator = " - ";
});
// ensure subsequent calls will locate this object
_contentManager.Flush();
return site;
}
return _contentManager.Get<ISite>(record.Id);

View File

@@ -8,6 +8,7 @@ using Orchard.Data.Migrations;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Security;
using Orchard.Settings;
using Orchard.Setup.ViewModels;
using Orchard.Localization;
using Orchard.UI.Notify;
@@ -55,24 +56,21 @@ namespace Orchard.Setup.Controllers {
// components will exist entirely in isolation - no crossover between the safemode container currently in effect
var shellSettings = new ShellSettings { Name = "temp" };
if (!_shellSettingsLoader.SaveSettings(shellSettings)) {
_notifier.Error(T("Site settings could not be saved. (Name = \"{0}\")", shellSettings.Name));
return Index(model);
}
using (var finiteEnvironment = _orchardHost.CreateStandaloneEnvironment(shellSettings)) {
var contentManager = finiteEnvironment.Resolve<IContentManager>();
// create superuser
var membershipService = finiteEnvironment.Resolve<IMembershipService>();
var user = membershipService.CreateUser(new CreateUserParams(model.AdminUsername, model.AdminPassword, String.Empty, String.Empty, String.Empty, true));
// set site name and settings
contentManager.Create<SiteSettings>("site", item => {
item.Record.SiteSalt = Guid.NewGuid().ToString("N");
item.Record.SiteName = model.SiteName;
item.Record.SuperUser = model.AdminUsername;
item.Record.PageTitleSeparator = " - ";
});
var siteService = finiteEnvironment.Resolve<ISiteService>();
var siteSettings = siteService.GetSiteSettings().As<SiteSettings>();
siteSettings.Record.SiteSalt = Guid.NewGuid().ToString("N");
siteSettings.Record.SiteName = model.SiteName;
siteSettings.Record.SuperUser = model.AdminUsername;
siteSettings.Record.PageTitleSeparator = " - ";
// create home page as a CMS page
var page = contentManager.Create("page");
@@ -86,9 +84,15 @@ namespace Orchard.Setup.Controllers {
var authenticationService = finiteEnvironment.Resolve<IAuthenticationService>();
authenticationService.SignIn(user, true);
//_orchardHost.Reinitialize();
}
if (!_shellSettingsLoader.SaveSettings(shellSettings)) {
_notifier.Error(T("Site settings could not be saved. (Name = \"{0}\")", shellSettings.Name));
return Index(model);
}
_orchardHost.Reinitialize();
_notifier.Information(T("Setup succeeded"));
// redirect to the welcome page.

View File

@@ -20,6 +20,9 @@ namespace Orchard.Environment.Configuration {
if (settings != null && !string.IsNullOrEmpty(settings.Name)) {
var sitesPath = HostingEnvironment.MapPath("~/App_Data/Sites");
if (sitesPath != null) {
if (!Directory.Exists(sitesPath))
Directory.CreateDirectory(sitesPath);
var filePath = Path.Combine(sitesPath, string.Format("{0}.txt", settings.Name));
File.WriteAllText(filePath, ComposeSettings(settings));
return true;