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;
|
||||||
using System.IO;
|
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Comments.Models;
|
using Orchard.Comments.Models;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
@@ -7,7 +6,6 @@ using Orchard.Core.Common.Models;
|
|||||||
using Orchard.Core.Navigation.Models;
|
using Orchard.Core.Navigation.Models;
|
||||||
using Orchard.Core.Settings.Models;
|
using Orchard.Core.Settings.Models;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Data.Builders;
|
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
@@ -15,7 +13,6 @@ using Orchard.Settings;
|
|||||||
using Orchard.Setup.ViewModels;
|
using Orchard.Setup.ViewModels;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using MenuItem=Orchard.Core.Navigation.Models.MenuItem;
|
|
||||||
|
|
||||||
namespace Orchard.Setup.Controllers {
|
namespace Orchard.Setup.Controllers {
|
||||||
public class SetupController : Controller {
|
public class SetupController : Controller {
|
||||||
@@ -74,7 +71,7 @@ namespace Orchard.Setup.Controllers {
|
|||||||
try {
|
try {
|
||||||
// initialize database before the transaction is created
|
// initialize database before the transaction is created
|
||||||
var sessionFactoryHolder = finiteEnvironment.Resolve<ISessionFactoryHolder>();
|
var sessionFactoryHolder = finiteEnvironment.Resolve<ISessionFactoryHolder>();
|
||||||
sessionFactoryHolder.UpdateSchema();
|
sessionFactoryHolder.CreateDatabase();
|
||||||
|
|
||||||
|
|
||||||
// create superuser
|
// create superuser
|
||||||
|
@@ -15,10 +15,10 @@ using Orchard.Environment;
|
|||||||
|
|
||||||
namespace Orchard.Data.Builders {
|
namespace Orchard.Data.Builders {
|
||||||
public abstract class AbstractBuilder {
|
public abstract class AbstractBuilder {
|
||||||
protected abstract IPersistenceConfigurer GetPersistenceConfigurer();
|
protected abstract IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase);
|
||||||
|
|
||||||
public ISessionFactory BuildSessionFactory(SessionFactoryParameters parameters) {
|
public ISessionFactory BuildSessionFactory(SessionFactoryParameters parameters) {
|
||||||
var database = GetPersistenceConfigurer();
|
var database = GetPersistenceConfigurer(parameters.CreateDatabase);
|
||||||
var persistenceModel = CreatePersistenceModel(parameters.RecordDescriptors);
|
var persistenceModel = CreatePersistenceModel(parameters.RecordDescriptors);
|
||||||
|
|
||||||
var sessionFactory = Fluently.Configure()
|
var sessionFactory = Fluently.Configure()
|
||||||
@@ -31,7 +31,11 @@ namespace Orchard.Data.Builders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void Initialization(SessionFactoryParameters parameters, Configuration configuration) {
|
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);
|
var update = new SchemaUpdate(configuration);
|
||||||
update.Execute(false/*script*/, true /*doUpdate*/);
|
update.Execute(false/*script*/, true /*doUpdate*/);
|
||||||
}
|
}
|
||||||
|
@@ -9,11 +9,13 @@ namespace Orchard.Data.Builders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class SessionFactoryParameters {
|
public class SessionFactoryParameters {
|
||||||
public IEnumerable<RecordDescriptor> RecordDescriptors { get; set; }
|
|
||||||
public bool UpdateSchema { get; set; }
|
|
||||||
|
|
||||||
public string Provider { get; set; }
|
public string Provider { get; set; }
|
||||||
public string DataFolder { get; set; }
|
public string DataFolder { get; set; }
|
||||||
public string ConnectionString { 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;
|
_connectionString = connectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IPersistenceConfigurer GetPersistenceConfigurer() {
|
protected override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase) {
|
||||||
var persistence = SQLiteConfiguration.Standard;
|
var persistence = SQLiteConfiguration.Standard;
|
||||||
if (string.IsNullOrEmpty(_connectionString)) {
|
if (string.IsNullOrEmpty(_connectionString)) {
|
||||||
|
var dataFile = Path.Combine(_dataFolder, "Orchard.db");
|
||||||
if (!Directory.Exists(_dataFolder))
|
|
||||||
Directory.CreateDirectory(_dataFolder);
|
|
||||||
|
|
||||||
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 {
|
else {
|
||||||
persistence = persistence.ConnectionString(_connectionString);
|
persistence = persistence.ConnectionString(_connectionString);
|
||||||
}
|
}
|
||||||
return persistence;
|
return persistence;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,15 +3,15 @@ using NHibernate;
|
|||||||
|
|
||||||
namespace Orchard.Data.Builders {
|
namespace Orchard.Data.Builders {
|
||||||
public class SessionFactoryBuilder : ISessionFactoryBuilder {
|
public class SessionFactoryBuilder : ISessionFactoryBuilder {
|
||||||
public ISessionFactory BuildSessionFactory(SessionFactoryParameters sessionFactoryParameters) {
|
public ISessionFactory BuildSessionFactory(SessionFactoryParameters parameters) {
|
||||||
AbstractBuilder builder;
|
AbstractBuilder builder;
|
||||||
if (string.Equals(sessionFactoryParameters.Provider, "SQLite", StringComparison.InvariantCultureIgnoreCase)) {
|
if (string.Equals(parameters.Provider, "SQLite", StringComparison.InvariantCultureIgnoreCase)) {
|
||||||
builder = new SQLiteBuilder(sessionFactoryParameters.DataFolder, sessionFactoryParameters.ConnectionString);
|
builder = new SQLiteBuilder(parameters.DataFolder, parameters.ConnectionString);
|
||||||
}
|
}
|
||||||
else {
|
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;
|
var persistence = MsSqlConfiguration.MsSql2008;
|
||||||
if (string.IsNullOrEmpty(_connectionString)) {
|
if (string.IsNullOrEmpty(_connectionString)) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System.IO;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
using Orchard.Data.Builders;
|
using Orchard.Data.Builders;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
@@ -8,6 +9,7 @@ using Orchard.Logging;
|
|||||||
namespace Orchard.Data {
|
namespace Orchard.Data {
|
||||||
public interface ISessionFactoryHolder : ISingletonDependency {
|
public interface ISessionFactoryHolder : ISingletonDependency {
|
||||||
ISessionFactory GetSessionFactory();
|
ISessionFactory GetSessionFactory();
|
||||||
|
void CreateDatabase();
|
||||||
void UpdateSchema();
|
void UpdateSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +35,17 @@ namespace Orchard.Data {
|
|||||||
|
|
||||||
public ILogger Logger { get; set; }
|
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() {
|
public void UpdateSchema() {
|
||||||
lock (this) {
|
lock (this) {
|
||||||
if (_sessionFactory != null) {
|
if (_sessionFactory != null) {
|
||||||
@@ -40,20 +53,20 @@ namespace Orchard.Data {
|
|||||||
throw new OrchardException("UpdateSchema can not be called after a session factory was created");
|
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() {
|
public ISessionFactory GetSessionFactory() {
|
||||||
lock (this) {
|
lock (this) {
|
||||||
if (_sessionFactory == null) {
|
if (_sessionFactory == null) {
|
||||||
_sessionFactory = BuildSessionFactory(false);
|
_sessionFactory = BuildSessionFactory(false /*createDatabase*/, false /*updateSchema*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _sessionFactory;
|
return _sessionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISessionFactory BuildSessionFactory(bool updateSchema) {
|
private ISessionFactory BuildSessionFactory(bool createDatabase, bool updateSchema) {
|
||||||
Logger.Debug("Building session factory");
|
Logger.Debug("Building session factory");
|
||||||
|
|
||||||
var shellPath = _appDataFolder.CreateDirectory(Path.Combine("Sites", _shellSettings.Name));
|
var shellPath = _appDataFolder.CreateDirectory(Path.Combine("Sites", _shellSettings.Name));
|
||||||
@@ -62,6 +75,7 @@ namespace Orchard.Data {
|
|||||||
Provider = _shellSettings.DataProvider,
|
Provider = _shellSettings.DataProvider,
|
||||||
DataFolder = shellPath,
|
DataFolder = shellPath,
|
||||||
ConnectionString = _shellSettings.DataConnectionString,
|
ConnectionString = _shellSettings.DataConnectionString,
|
||||||
|
CreateDatabase = createDatabase,
|
||||||
UpdateSchema = updateSchema,
|
UpdateSchema = updateSchema,
|
||||||
RecordDescriptors = _compositionStrategy.GetRecordDescriptors(),
|
RecordDescriptors = _compositionStrategy.GetRecordDescriptors(),
|
||||||
});
|
});
|
||||||
|
@@ -43,10 +43,13 @@ namespace Orchard.Environment.Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<YamlDocument> LoadFiles() {
|
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) {
|
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();
|
yield return yamlStream.Documents.Single();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user