mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Finishing aggressive data scrubbing on setup
Existing file destroyed for lightweight databases Tables dropped and recreated for client/server databases This is "setup" only scenario. Recreating an orchard site on a new database will need some alternate "attach" mechanism - orthogonal to "setup" mechanism --HG-- branch : dev
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -7,7 +6,6 @@ using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Core.Settings.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Data.Builders;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Security;
|
||||
@@ -15,7 +13,6 @@ using Orchard.Settings;
|
||||
using Orchard.Setup.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
using MenuItem=Orchard.Core.Navigation.Models.MenuItem;
|
||||
|
||||
namespace Orchard.Setup.Controllers {
|
||||
public class SetupController : Controller {
|
||||
@@ -74,7 +71,7 @@ namespace Orchard.Setup.Controllers {
|
||||
try {
|
||||
// initialize database before the transaction is created
|
||||
var sessionFactoryHolder = finiteEnvironment.Resolve<ISessionFactoryHolder>();
|
||||
sessionFactoryHolder.UpdateSchema();
|
||||
sessionFactoryHolder.CreateDatabase();
|
||||
|
||||
|
||||
// create superuser
|
||||
|
@@ -15,10 +15,10 @@ using Orchard.Environment;
|
||||
|
||||
namespace Orchard.Data.Builders {
|
||||
public abstract class AbstractBuilder {
|
||||
protected abstract IPersistenceConfigurer GetPersistenceConfigurer();
|
||||
protected abstract IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase);
|
||||
|
||||
public ISessionFactory BuildSessionFactory(SessionFactoryParameters parameters) {
|
||||
var database = GetPersistenceConfigurer();
|
||||
var database = GetPersistenceConfigurer(parameters.CreateDatabase);
|
||||
var persistenceModel = CreatePersistenceModel(parameters.RecordDescriptors);
|
||||
|
||||
var sessionFactory = Fluently.Configure()
|
||||
@@ -31,7 +31,11 @@ namespace Orchard.Data.Builders {
|
||||
}
|
||||
|
||||
private static void Initialization(SessionFactoryParameters parameters, Configuration configuration) {
|
||||
if (parameters.UpdateSchema) {
|
||||
if (parameters.CreateDatabase) {
|
||||
var export = new SchemaExport(configuration);
|
||||
export.Execute(false/*script*/, true/*export*/, false/*justDrop*/);
|
||||
}
|
||||
else if (parameters.UpdateSchema) {
|
||||
var update = new SchemaUpdate(configuration);
|
||||
update.Execute(false/*script*/, true /*doUpdate*/);
|
||||
}
|
||||
|
@@ -9,11 +9,13 @@ namespace Orchard.Data.Builders {
|
||||
}
|
||||
|
||||
public class SessionFactoryParameters {
|
||||
public IEnumerable<RecordDescriptor> RecordDescriptors { get; set; }
|
||||
public bool UpdateSchema { get; set; }
|
||||
|
||||
public string Provider { get; set; }
|
||||
public string DataFolder { get; set; }
|
||||
public string ConnectionString { get; set; }
|
||||
|
||||
public bool CreateDatabase { get; set; }
|
||||
public bool UpdateSchema { get; set; }
|
||||
|
||||
public IEnumerable<RecordDescriptor> RecordDescriptors { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -11,20 +11,25 @@ namespace Orchard.Data.Builders {
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
protected override IPersistenceConfigurer GetPersistenceConfigurer() {
|
||||
protected override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase) {
|
||||
var persistence = SQLiteConfiguration.Standard;
|
||||
if (string.IsNullOrEmpty(_connectionString)) {
|
||||
|
||||
if (!Directory.Exists(_dataFolder))
|
||||
Directory.CreateDirectory(_dataFolder);
|
||||
var dataFile = Path.Combine(_dataFolder, "Orchard.db");
|
||||
|
||||
persistence = persistence.UsingFile(Path.Combine(_dataFolder, "Orchard.db"));
|
||||
if (!Directory.Exists(_dataFolder)) {
|
||||
Directory.CreateDirectory(_dataFolder);
|
||||
}
|
||||
|
||||
if (createDatabase && File.Exists(dataFile)) {
|
||||
File.Delete(dataFile);
|
||||
}
|
||||
|
||||
persistence = persistence.UsingFile(dataFile);
|
||||
}
|
||||
else {
|
||||
persistence = persistence.ConnectionString(_connectionString);
|
||||
}
|
||||
return persistence;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,15 +3,15 @@ using NHibernate;
|
||||
|
||||
namespace Orchard.Data.Builders {
|
||||
public class SessionFactoryBuilder : ISessionFactoryBuilder {
|
||||
public ISessionFactory BuildSessionFactory(SessionFactoryParameters sessionFactoryParameters) {
|
||||
public ISessionFactory BuildSessionFactory(SessionFactoryParameters parameters) {
|
||||
AbstractBuilder builder;
|
||||
if (string.Equals(sessionFactoryParameters.Provider, "SQLite", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
builder = new SQLiteBuilder(sessionFactoryParameters.DataFolder, sessionFactoryParameters.ConnectionString);
|
||||
if (string.Equals(parameters.Provider, "SQLite", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
builder = new SQLiteBuilder(parameters.DataFolder, parameters.ConnectionString);
|
||||
}
|
||||
else {
|
||||
builder = new SqlServerBuilder(sessionFactoryParameters.DataFolder, sessionFactoryParameters.ConnectionString);
|
||||
builder = new SqlServerBuilder(parameters.DataFolder, parameters.ConnectionString);
|
||||
}
|
||||
return builder.BuildSessionFactory(sessionFactoryParameters);
|
||||
return builder.BuildSessionFactory(parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ namespace Orchard.Data.Builders {
|
||||
}
|
||||
|
||||
|
||||
protected override IPersistenceConfigurer GetPersistenceConfigurer() {
|
||||
protected override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase) {
|
||||
var persistence = MsSqlConfiguration.MsSql2008;
|
||||
if (string.IsNullOrEmpty(_connectionString)) {
|
||||
throw new NotImplementedException();
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using NHibernate;
|
||||
using Orchard.Data.Builders;
|
||||
using Orchard.Environment;
|
||||
@@ -8,6 +9,7 @@ using Orchard.Logging;
|
||||
namespace Orchard.Data {
|
||||
public interface ISessionFactoryHolder : ISingletonDependency {
|
||||
ISessionFactory GetSessionFactory();
|
||||
void CreateDatabase();
|
||||
void UpdateSchema();
|
||||
}
|
||||
|
||||
@@ -33,6 +35,17 @@ namespace Orchard.Data {
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public void CreateDatabase() {
|
||||
lock (this) {
|
||||
if (_sessionFactory != null) {
|
||||
Logger.Error("CreateSchema can not be called after a session factory was created");
|
||||
throw new OrchardException("CreateSchema can not be called after a session factory was created");
|
||||
}
|
||||
|
||||
_sessionFactory = BuildSessionFactory(true /*createDatabase*/, false /*updateSchema*/);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateSchema() {
|
||||
lock (this) {
|
||||
if (_sessionFactory != null) {
|
||||
@@ -40,20 +53,20 @@ namespace Orchard.Data {
|
||||
throw new OrchardException("UpdateSchema can not be called after a session factory was created");
|
||||
}
|
||||
|
||||
_sessionFactory = BuildSessionFactory(true);
|
||||
_sessionFactory = BuildSessionFactory(false /*createDatabase*/, true /*updateSchema*/);
|
||||
}
|
||||
}
|
||||
|
||||
public ISessionFactory GetSessionFactory() {
|
||||
lock (this) {
|
||||
if (_sessionFactory == null) {
|
||||
_sessionFactory = BuildSessionFactory(false);
|
||||
_sessionFactory = BuildSessionFactory(false /*createDatabase*/, false /*updateSchema*/);
|
||||
}
|
||||
}
|
||||
return _sessionFactory;
|
||||
}
|
||||
|
||||
private ISessionFactory BuildSessionFactory(bool updateSchema) {
|
||||
private ISessionFactory BuildSessionFactory(bool createDatabase, bool updateSchema) {
|
||||
Logger.Debug("Building session factory");
|
||||
|
||||
var shellPath = _appDataFolder.CreateDirectory(Path.Combine("Sites", _shellSettings.Name));
|
||||
@@ -62,6 +75,7 @@ namespace Orchard.Data {
|
||||
Provider = _shellSettings.DataProvider,
|
||||
DataFolder = shellPath,
|
||||
ConnectionString = _shellSettings.DataConnectionString,
|
||||
CreateDatabase = createDatabase,
|
||||
UpdateSchema = updateSchema,
|
||||
RecordDescriptors = _compositionStrategy.GetRecordDescriptors(),
|
||||
});
|
||||
|
@@ -43,10 +43,13 @@ namespace Orchard.Environment.Configuration {
|
||||
}
|
||||
|
||||
IEnumerable<YamlDocument> LoadFiles() {
|
||||
var sitePaths = _appDataFolder.ListDirectories("Sites");
|
||||
var sitePaths = _appDataFolder
|
||||
.ListDirectories("Sites")
|
||||
.SelectMany(path => _appDataFolder.ListFiles(path))
|
||||
.Where(path => string.Equals(Path.GetFileName(path), "Settings.txt", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
foreach (var sitePath in sitePaths) {
|
||||
var yamlStream = YamlParser.Load(_appDataFolder.MapPath(Path.Combine(sitePath, "Settings.txt")));
|
||||
var yamlStream = YamlParser.Load(_appDataFolder.MapPath(sitePath));
|
||||
yield return yamlStream.Documents.Single();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user