mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +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"));
|
Directory.CreateDirectory(Path.Combine(_tempFolder, "alpha"));
|
||||||
File.WriteAllText(Path.Combine(_tempFolder, "alpha\\beta.txt"), "beta-content");
|
File.WriteAllText(Path.Combine(_tempFolder, "alpha\\beta.txt"), "beta-content");
|
||||||
File.WriteAllText(Path.Combine(_tempFolder, "alpha\\gamma.txt"), "gamma-content");
|
File.WriteAllText(Path.Combine(_tempFolder, "alpha\\gamma.txt"), "gamma-content");
|
||||||
|
Directory.CreateDirectory(Path.Combine(_tempFolder, "alpha\\omega"));
|
||||||
|
|
||||||
_appDataFolder = new AppDataFolder();
|
_appDataFolder = new AppDataFolder();
|
||||||
_appDataFolder.SetBasePath(_tempFolder);
|
_appDataFolder.SetBasePath(_tempFolder);
|
||||||
@@ -49,5 +50,32 @@ namespace Orchard.Tests.Environment.Configuration {
|
|||||||
Assert.That(physicalPath, Is.EqualTo(Path.Combine(_tempFolder, "delta\\epsilon.txt")));
|
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 {
|
try {
|
||||||
var shellSettings = new ShellSettings {
|
var shellSettings = new ShellSettings {
|
||||||
Name = "default",
|
Name = "Default",
|
||||||
DataProvider = model.DatabaseOptions ? "SQLite" : "SqlServer",
|
DataProvider = model.DatabaseOptions ? "SQLite" : "SqlServer",
|
||||||
DataConnectionString = model.DatabaseConnectionString
|
DataConnectionString = model.DatabaseConnectionString
|
||||||
};
|
};
|
||||||
|
@@ -12,6 +12,7 @@ namespace Orchard.Environment.Configuration {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IAppDataFolder {
|
public interface IAppDataFolder {
|
||||||
IEnumerable<string> ListFiles(string path);
|
IEnumerable<string> ListFiles(string path);
|
||||||
|
IEnumerable<string> ListDirectories(string path);
|
||||||
|
|
||||||
void CreateFile(string path, string content);
|
void CreateFile(string path, string content);
|
||||||
void DeleteFile(string path);
|
void DeleteFile(string path);
|
||||||
@@ -36,7 +37,11 @@ namespace Orchard.Environment.Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void CreateFile(string path, string content) {
|
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) {
|
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) {
|
public string CreateDirectory(string path) {
|
||||||
var directory = Path.Combine(_basePath, path);
|
var directory = Path.Combine(_basePath, path);
|
||||||
if (!Directory.Exists(directory))
|
if (!Directory.Exists(directory))
|
||||||
|
@@ -32,9 +32,8 @@ namespace Orchard.Environment.Configuration {
|
|||||||
if (string.IsNullOrEmpty(settings.Name))
|
if (string.IsNullOrEmpty(settings.Name))
|
||||||
throw new ArgumentException(T("Settings \"Name\" is not set.").ToString());
|
throw new ArgumentException(T("Settings \"Name\" is not set.").ToString());
|
||||||
|
|
||||||
|
var settingsFile = Path.Combine(Path.Combine("Sites", settings.Name), "Settings.txt");
|
||||||
var filePath = Path.Combine("Sites", settings.Name + ".txt");
|
_appDataFolder.CreateFile(settingsFile, ComposeSettings(settings));
|
||||||
_appDataFolder.CreateFile(filePath, ComposeSettings(settings));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<IShellSettings> LoadSettings() {
|
IEnumerable<IShellSettings> LoadSettings() {
|
||||||
@@ -44,11 +43,10 @@ namespace Orchard.Environment.Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<YamlDocument> LoadFiles() {
|
IEnumerable<YamlDocument> LoadFiles() {
|
||||||
var filePaths = _appDataFolder.ListFiles("Sites")
|
var sitePaths = _appDataFolder.ListDirectories("Sites");
|
||||||
.Where(path => path.EndsWith(".txt", StringComparison.InvariantCultureIgnoreCase));
|
|
||||||
|
|
||||||
foreach (var filePath in filePaths) {
|
foreach (var sitePath in sitePaths) {
|
||||||
var yamlStream = YamlParser.Load(_appDataFolder.MapPath(filePath));
|
var yamlStream = YamlParser.Load(_appDataFolder.MapPath(Path.Combine(sitePath, "Settings.txt")));
|
||||||
yield return yamlStream.Documents.Single();
|
yield return yamlStream.Documents.Single();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user