mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Changing location of site settings file
A subfolder location is more symmetrical with location of db, and other theme and module txt files. --HG-- branch : dev
This commit is contained in:
@@ -19,6 +19,7 @@ namespace Orchard.Tests.Environment.Configuration {
|
||||
Directory.CreateDirectory(Path.Combine(_tempFolder, "alpha"));
|
||||
File.WriteAllText(Path.Combine(_tempFolder, "alpha\\beta.txt"), "beta-content");
|
||||
File.WriteAllText(Path.Combine(_tempFolder, "alpha\\gamma.txt"), "gamma-content");
|
||||
Directory.CreateDirectory(Path.Combine(_tempFolder, "alpha\\omega"));
|
||||
|
||||
_appDataFolder = new AppDataFolder();
|
||||
_appDataFolder.SetBasePath(_tempFolder);
|
||||
@@ -49,5 +50,32 @@ namespace Orchard.Tests.Environment.Configuration {
|
||||
Assert.That(physicalPath, Is.EqualTo(Path.Combine(_tempFolder, "delta\\epsilon.txt")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ListSubdirectoriesShouldContainFullSubpath() {
|
||||
var files = _appDataFolder.ListDirectories("alpha");
|
||||
Assert.That(files.Count(), Is.EqualTo(1));
|
||||
Assert.That(files, Has.Some.EqualTo("alpha\\omega"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ListSubdirectoriesShouldWorkInRoot() {
|
||||
var files = _appDataFolder.ListDirectories("");
|
||||
Assert.That(files.Count(), Is.EqualTo(1));
|
||||
Assert.That(files, Has.Some.EqualTo("alpha"));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void NonExistantFolderShouldListDirectoriesAsEmptyCollection() {
|
||||
var files = _appDataFolder.ListDirectories("delta");
|
||||
Assert.That(files.Count(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateFileWillCauseDirectoryToBeCreated() {
|
||||
Assert.That(Directory.Exists(Path.Combine(_tempFolder, "alpha\\omega\\foo")), Is.False);
|
||||
_appDataFolder.CreateFile("alpha\\omega\\foo\\bar.txt", "quux");
|
||||
Assert.That(Directory.Exists(Path.Combine(_tempFolder, "alpha\\omega\\foo")), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -62,7 +62,7 @@ namespace Orchard.Setup.Controllers {
|
||||
|
||||
try {
|
||||
var shellSettings = new ShellSettings {
|
||||
Name = "default",
|
||||
Name = "Default",
|
||||
DataProvider = model.DatabaseOptions ? "SQLite" : "SqlServer",
|
||||
DataConnectionString = model.DatabaseConnectionString
|
||||
};
|
||||
|
@@ -12,6 +12,7 @@ namespace Orchard.Environment.Configuration {
|
||||
/// </summary>
|
||||
public interface IAppDataFolder {
|
||||
IEnumerable<string> ListFiles(string path);
|
||||
IEnumerable<string> ListDirectories(string path);
|
||||
|
||||
void CreateFile(string path, string content);
|
||||
void DeleteFile(string path);
|
||||
@@ -36,7 +37,11 @@ namespace Orchard.Environment.Configuration {
|
||||
}
|
||||
|
||||
public void CreateFile(string path, string content) {
|
||||
File.WriteAllText(Path.Combine(_basePath, path), content);
|
||||
var filePath = Path.Combine(_basePath, path);
|
||||
var folderPath = Path.GetDirectoryName(filePath);
|
||||
if (!Directory.Exists(folderPath))
|
||||
Directory.CreateDirectory(folderPath);
|
||||
File.WriteAllText(filePath, content);
|
||||
}
|
||||
|
||||
public void DeleteFile(string path) {
|
||||
@@ -56,6 +61,19 @@ namespace Orchard.Environment.Configuration {
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListDirectories(string path) {
|
||||
var directoryPath = Path.Combine(_basePath, path);
|
||||
if (!Directory.Exists(directoryPath))
|
||||
return Enumerable.Empty<string>();
|
||||
|
||||
var files = Directory.GetDirectories(directoryPath);
|
||||
|
||||
return files.Select(file => {
|
||||
var fileName = Path.GetFileName(file);
|
||||
return Path.Combine(path, fileName);
|
||||
});
|
||||
}
|
||||
|
||||
public string CreateDirectory(string path) {
|
||||
var directory = Path.Combine(_basePath, path);
|
||||
if (!Directory.Exists(directory))
|
||||
|
@@ -32,9 +32,8 @@ namespace Orchard.Environment.Configuration {
|
||||
if (string.IsNullOrEmpty(settings.Name))
|
||||
throw new ArgumentException(T("Settings \"Name\" is not set.").ToString());
|
||||
|
||||
|
||||
var filePath = Path.Combine("Sites", settings.Name + ".txt");
|
||||
_appDataFolder.CreateFile(filePath, ComposeSettings(settings));
|
||||
var settingsFile = Path.Combine(Path.Combine("Sites", settings.Name), "Settings.txt");
|
||||
_appDataFolder.CreateFile(settingsFile, ComposeSettings(settings));
|
||||
}
|
||||
|
||||
IEnumerable<IShellSettings> LoadSettings() {
|
||||
@@ -44,11 +43,10 @@ namespace Orchard.Environment.Configuration {
|
||||
}
|
||||
|
||||
IEnumerable<YamlDocument> LoadFiles() {
|
||||
var filePaths = _appDataFolder.ListFiles("Sites")
|
||||
.Where(path => path.EndsWith(".txt", StringComparison.InvariantCultureIgnoreCase));
|
||||
var sitePaths = _appDataFolder.ListDirectories("Sites");
|
||||
|
||||
foreach (var filePath in filePaths) {
|
||||
var yamlStream = YamlParser.Load(_appDataFolder.MapPath(filePath));
|
||||
foreach (var sitePath in sitePaths) {
|
||||
var yamlStream = YamlParser.Load(_appDataFolder.MapPath(Path.Combine(sitePath, "Settings.txt")));
|
||||
yield return yamlStream.Documents.Single();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user