mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
Getting setup to save real info for site settings and changing the default settings name to "default"
--HG-- branch : dev
This commit is contained in:
@@ -58,9 +58,8 @@ namespace Orchard.Tests.Environment {
|
|||||||
return _shellSettings.AsEnumerable();
|
return _shellSettings.AsEnumerable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SaveSettings(IShellSettings settings) {
|
public void SaveSettings(IShellSettings settings) {
|
||||||
_shellSettings.Add(settings);
|
_shellSettings.Add(settings);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,18 +45,22 @@ namespace Orchard.Setup.Controllers {
|
|||||||
return Index(model);
|
return Index(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var shellSettings = new ShellSettings {
|
||||||
|
Name = "default",
|
||||||
|
DataProvider = model.DatabaseOptions ? "SQLite" : "SqlServer",
|
||||||
|
DataFolder = Server.MapPath("~/App_Data"),
|
||||||
|
DataConnectionString = model.DatabaseConnectionString
|
||||||
|
};
|
||||||
|
|
||||||
// initialize the database:
|
// initialize the database:
|
||||||
// provider: SqlServer or SQLite
|
// provider: SqlServer or SQLite
|
||||||
// dataFolder: physical path (map before calling). Builtin database will be created in this location
|
// dataFolder: physical path (map before calling). Builtin database will be created in this location
|
||||||
// connectionString: optional - if provided the dataFolder is essentially ignored, but should still be passed in
|
// connectionString: optional - if provided the dataFolder is essentially ignored, but should still be passed in
|
||||||
_databaseMigrationManager.CreateCoordinator(model.DatabaseOptions ? "SQLite" : "SqlServer", Server.MapPath("~/App_Data"), model.DatabaseConnectionString);
|
_databaseMigrationManager.CreateCoordinator(shellSettings.DataProvider, shellSettings.DataFolder, shellSettings.DataConnectionString);
|
||||||
|
|
||||||
// creating a standalone environment.
|
// creating a standalone environment.
|
||||||
// in theory this environment can be used to resolve any normal components by interface, and those
|
// 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
|
// components will exist entirely in isolation - no crossover between the safemode container currently in effect
|
||||||
var shellSettings = new ShellSettings { Name = "temp" };
|
|
||||||
|
|
||||||
|
|
||||||
using (var finiteEnvironment = _orchardHost.CreateStandaloneEnvironment(shellSettings)) {
|
using (var finiteEnvironment = _orchardHost.CreateStandaloneEnvironment(shellSettings)) {
|
||||||
var contentManager = finiteEnvironment.Resolve<IContentManager>();
|
var contentManager = finiteEnvironment.Resolve<IContentManager>();
|
||||||
|
|
||||||
@@ -83,13 +87,9 @@ namespace Orchard.Setup.Controllers {
|
|||||||
|
|
||||||
var authenticationService = finiteEnvironment.Resolve<IAuthenticationService>();
|
var authenticationService = finiteEnvironment.Resolve<IAuthenticationService>();
|
||||||
authenticationService.SignIn(user, true);
|
authenticationService.SignIn(user, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_shellSettingsLoader.SaveSettings(shellSettings)) {
|
_shellSettingsLoader.SaveSettings(shellSettings);
|
||||||
_notifier.Error(T("Site settings could not be saved. (Name = \"{0}\")", shellSettings.Name));
|
|
||||||
return Index(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
_orchardHost.Reinitialize();
|
_orchardHost.Reinitialize();
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<%=Html.LabelFor(svm => svm.AdminPassword) %>
|
<%=Html.LabelFor(svm => svm.AdminPassword) %>
|
||||||
<%=Html.EditorFor(svm => svm.AdminPassword) %>
|
<%=Html.PasswordFor(svm => svm.AdminPassword) %>
|
||||||
<%=Html.ValidationMessage("AdminPassword", "*") %>
|
<%=Html.ValidationMessage("AdminPassword", "*") %>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@@ -1,9 +1,15 @@
|
|||||||
namespace Orchard.Environment.Configuration {
|
namespace Orchard.Environment.Configuration {
|
||||||
public interface IShellSettings {
|
public interface IShellSettings {
|
||||||
string Name { get; set; }
|
string Name { get; set; }
|
||||||
|
string DataProvider { get; set; }
|
||||||
|
string DataFolder { get; set; }
|
||||||
|
string DataConnectionString { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ShellSettings : IShellSettings {
|
public class ShellSettings : IShellSettings {
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
public string DataProvider { get; set; }
|
||||||
|
public string DataFolder { get; set; }
|
||||||
|
public string DataConnectionString { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,35 +1,45 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
|
using Orchard.Localization;
|
||||||
using Yaml.Grammar;
|
using Yaml.Grammar;
|
||||||
|
|
||||||
namespace Orchard.Environment.Configuration {
|
namespace Orchard.Environment.Configuration {
|
||||||
public interface IShellSettingsLoader {
|
public interface IShellSettingsLoader {
|
||||||
IEnumerable<IShellSettings> LoadSettings();
|
IEnumerable<IShellSettings> LoadSettings();
|
||||||
bool SaveSettings(IShellSettings settings);
|
void SaveSettings(IShellSettings settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ShellSettingsLoader : IShellSettingsLoader {
|
public class ShellSettingsLoader : IShellSettingsLoader {
|
||||||
|
Localizer T { get; set; }
|
||||||
|
|
||||||
|
public ShellSettingsLoader() {
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
IEnumerable<IShellSettings> IShellSettingsLoader.LoadSettings() {
|
IEnumerable<IShellSettings> IShellSettingsLoader.LoadSettings() {
|
||||||
return LoadSettings().ToArray();
|
return LoadSettings().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SaveSettings(IShellSettings settings) {
|
public void SaveSettings(IShellSettings settings) {
|
||||||
if (settings != null && !string.IsNullOrEmpty(settings.Name)) {
|
if (settings == null)
|
||||||
var sitesPath = HostingEnvironment.MapPath("~/App_Data/Sites");
|
throw new ArgumentException(T("There are no settings to save.").ToString());
|
||||||
if (sitesPath != null) {
|
if (string.IsNullOrEmpty(settings.Name))
|
||||||
if (!Directory.Exists(sitesPath))
|
throw new ArgumentException(T("Settings \"Name\" is not set.").ToString());
|
||||||
Directory.CreateDirectory(sitesPath);
|
|
||||||
|
|
||||||
var filePath = Path.Combine(sitesPath, string.Format("{0}.txt", settings.Name));
|
var sitesPath = HostingEnvironment.MapPath("~/App_Data/Sites");
|
||||||
File.WriteAllText(filePath, ComposeSettings(settings));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
if (string.IsNullOrEmpty(sitesPath))
|
||||||
|
throw new ArgumentException(T("Can't determine the path on the server to save settings. Looking for something like \"~/App_Data/Sites\".").ToString());
|
||||||
|
|
||||||
|
if (!Directory.Exists(sitesPath))
|
||||||
|
Directory.CreateDirectory(sitesPath);
|
||||||
|
|
||||||
|
var filePath = Path.Combine(sitesPath, string.Format("{0}.txt", settings.Name));
|
||||||
|
File.WriteAllText(filePath, ComposeSettings(settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<IShellSettings> LoadSettings() {
|
static IEnumerable<IShellSettings> LoadSettings() {
|
||||||
@@ -54,7 +64,12 @@ namespace Orchard.Environment.Configuration {
|
|||||||
.Where(x => x.Key is Scalar)
|
.Where(x => x.Key is Scalar)
|
||||||
.ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value);
|
.ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value);
|
||||||
|
|
||||||
return new ShellSettings { Name = GetValue(fields, "Name") };
|
return new ShellSettings {
|
||||||
|
Name = GetValue(fields, "Name"),
|
||||||
|
DataProvider = GetValue(fields, "DataProvider"),
|
||||||
|
DataFolder = GetValue(fields, "DataFolder"),
|
||||||
|
DataConnectionString = GetValue(fields, "DataConnectionString")
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetValue(
|
static string GetValue(
|
||||||
@@ -66,7 +81,17 @@ namespace Orchard.Environment.Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static string ComposeSettings(IShellSettings shellSettings) {
|
static string ComposeSettings(IShellSettings shellSettings) {
|
||||||
return shellSettings == null ? "" : string.Format("Name: {0}", shellSettings.Name);
|
if (shellSettings == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
var settingsBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
settingsBuilder.AppendLine(string.Format("Name: {0}", shellSettings.Name));
|
||||||
|
settingsBuilder.AppendLine(string.Format("DataProvider: {0}", shellSettings.DataProvider));
|
||||||
|
settingsBuilder.AppendLine(string.Format("DataFolder: {0}", shellSettings.DataFolder));
|
||||||
|
settingsBuilder.AppendLine(string.Format("DataConnectionString: {0}", shellSettings.DataConnectionString));
|
||||||
|
|
||||||
|
return settingsBuilder.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user