mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Some more work on setup
- shell settings config saved to ~/App_Data/Sites/<ShellSettings Name>.txt - initial page owner set - orchardHost reinitialized (<- left commented out) --HG-- branch : dev
This commit is contained in:
@@ -51,12 +51,16 @@ namespace Orchard.Tests.Environment {
|
||||
}
|
||||
|
||||
public class StubShellSettingsLoader : IShellSettingsLoader {
|
||||
private readonly List<IShellSettings> _shellSettings = new List<IShellSettings>
|
||||
{new ShellSettings {Name = "testing"}};
|
||||
|
||||
public IEnumerable<IShellSettings> LoadSettings() {
|
||||
return new[] { new ShellSettings { Name = "testing" } };
|
||||
return _shellSettings.AsEnumerable();
|
||||
}
|
||||
|
||||
public void SaveSettings(IShellSettings settings) {
|
||||
|
||||
public bool SaveSettings(IShellSettings settings) {
|
||||
_shellSettings.Add(settings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -73,7 +73,7 @@ foreach (var pageEntry in Model.PageEntries)
|
||||
<td><%=Html.Encode(pageEntry.Page.Title ?? T("(no title)").ToString())%></td>
|
||||
<td><% if (pageEntry.Page.HasPublished)
|
||||
{ %>
|
||||
<%=Html.ActionLink(pageEntry.Page.Slug ?? T("(no slug)").ToString(), "Item", new { controller = "Page", slug = pageEntry.Page.PublishedSlug })%>
|
||||
<%=Html.ActionLink(!string.IsNullOrEmpty(pageEntry.Page.Slug) ? pageEntry.Page.Slug : T("(no slug)").ToString(), "Item", new { controller = "Page", slug = pageEntry.Page.PublishedSlug })%>
|
||||
<% }
|
||||
else
|
||||
{%>
|
||||
|
@@ -17,14 +17,17 @@ namespace Orchard.Setup.Controllers {
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IDatabaseMigrationManager _databaseMigrationManager;
|
||||
private readonly IOrchardHost _orchardHost;
|
||||
private readonly IShellSettingsLoader _shellSettingsLoader;
|
||||
|
||||
public SetupController(
|
||||
INotifier notifier,
|
||||
IDatabaseMigrationManager databaseMigrationManager,
|
||||
IOrchardHost orchardHost) {
|
||||
IOrchardHost orchardHost,
|
||||
IShellSettingsLoader shellSettingsLoader) {
|
||||
_notifier = notifier;
|
||||
_databaseMigrationManager = databaseMigrationManager;
|
||||
_orchardHost = orchardHost;
|
||||
_shellSettingsLoader = shellSettingsLoader;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
@@ -51,6 +54,12 @@ namespace Orchard.Setup.Controllers {
|
||||
// in theory this environment can be used to resolve any normal components by interface, and those
|
||||
// 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
|
||||
@@ -71,10 +80,13 @@ namespace Orchard.Setup.Controllers {
|
||||
page.As<RoutableAspect>().Slug = "";
|
||||
page.As<RoutableAspect>().Title = model.SiteName;
|
||||
page.As<HasComments>().CommentsShown = false;
|
||||
page.As<CommonAspect>().Owner = user;
|
||||
contentManager.Publish(page);
|
||||
|
||||
var authenticationService = finiteEnvironment.Resolve<IAuthenticationService>();
|
||||
authenticationService.SignIn(user, true);
|
||||
|
||||
//_orchardHost.Reinitialize();
|
||||
}
|
||||
|
||||
_notifier.Information(T("Setup succeeded"));
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Hosting;
|
||||
@@ -8,7 +7,7 @@ using Yaml.Grammar;
|
||||
namespace Orchard.Environment.Configuration {
|
||||
public interface IShellSettingsLoader {
|
||||
IEnumerable<IShellSettings> LoadSettings();
|
||||
void SaveSettings(IShellSettings settings);
|
||||
bool SaveSettings(IShellSettings settings);
|
||||
}
|
||||
|
||||
public class ShellSettingsLoader : IShellSettingsLoader {
|
||||
@@ -17,8 +16,17 @@ namespace Orchard.Environment.Configuration {
|
||||
return LoadSettings().ToArray();
|
||||
}
|
||||
|
||||
public void SaveSettings(IShellSettings settings) {
|
||||
public bool SaveSettings(IShellSettings settings) {
|
||||
if (settings != null && !string.IsNullOrEmpty(settings.Name)) {
|
||||
var sitesPath = HostingEnvironment.MapPath("~/App_Data/Sites");
|
||||
if (sitesPath != null) {
|
||||
var filePath = Path.Combine(sitesPath, string.Format("{0}.txt", settings.Name));
|
||||
File.WriteAllText(filePath, ComposeSettings(settings));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static IEnumerable<IShellSettings> LoadSettings() {
|
||||
@@ -53,5 +61,9 @@ namespace Orchard.Environment.Configuration {
|
||||
DataItem value;
|
||||
return fields.TryGetValue(key, out value) ? value.ToString() : null;
|
||||
}
|
||||
|
||||
static string ComposeSettings(IShellSettings shellSettings) {
|
||||
return shellSettings == null ? "" : string.Format("Name: {0}", shellSettings.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user