From 092fcc869a1275fc150737f27bba58eb9f0375c9 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 25 Jun 2010 15:35:52 -0700 Subject: [PATCH 01/19] Work on automatic schema creation --HG-- branch : dev --- .../Utilities/NullInterpreter.cs | 3 ++- .../DataMigration/DataMigrationCoordinator.cs | 4 +--- .../DataMigration/DataMigrationManager.cs | 12 ++++++++--- .../DefaultDataMigrationGenerator.cs | 13 ++++++++++-- .../DataMigration/IDataMigrationCommand.cs | 4 ---- .../DataMigration/IDataMigrationGenerator.cs | 5 ++++- .../DefaultDataMigrationInterpreter.cs | 21 ++++++++++++------- .../Interpreters/IDataMigrationInterpreter.cs | 2 +- src/Orchard/Orchard.Framework.csproj | 1 - 9 files changed, 41 insertions(+), 24 deletions(-) delete mode 100644 src/Orchard/DataMigration/IDataMigrationCommand.cs diff --git a/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs b/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs index 46cadd57d..9887aa4fc 100644 --- a/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs +++ b/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs @@ -4,7 +4,8 @@ using Orchard.DataMigration.Interpreters; using Orchard.DataMigration.Schema; public class NullInterpreter : IDataMigrationInterpreter { - public void Visit(SchemaCommand command) { + + public void Visit(ISchemaBuilderCommand command) { } public void Visit(CreateTableCommand command) { diff --git a/src/Orchard/DataMigration/DataMigrationCoordinator.cs b/src/Orchard/DataMigration/DataMigrationCoordinator.cs index a0f58ca33..3107ea7f2 100644 --- a/src/Orchard/DataMigration/DataMigrationCoordinator.cs +++ b/src/Orchard/DataMigration/DataMigrationCoordinator.cs @@ -23,9 +23,7 @@ namespace Orchard.DataMigration { public void Install(Feature feature) { var featureName = feature.Descriptor.Name; - if ( !_dataMigrationManager.IsFeatureAlreadyInstalled(featureName) ) { - _dataMigrationManager.Update(featureName); - } + _dataMigrationManager.Update(featureName); } public void Enable(Feature feature) { diff --git a/src/Orchard/DataMigration/DataMigrationManager.cs b/src/Orchard/DataMigration/DataMigrationManager.cs index 58fdf2a17..943a2d8b1 100644 --- a/src/Orchard/DataMigration/DataMigrationManager.cs +++ b/src/Orchard/DataMigration/DataMigrationManager.cs @@ -9,6 +9,7 @@ using Orchard.DataMigration.Schema; using Orchard.Environment.Extensions; using Orchard.Environment.State; using Orchard.Logging; +using Orchard.Environment.ShellBuilders.Models; namespace Orchard.DataMigration { /// @@ -20,18 +21,21 @@ namespace Orchard.DataMigration { private readonly IDataMigrationGenerator _dataMigrationGenerator; private readonly IExtensionManager _extensionManager; private readonly IDataMigrationInterpreter _interpreter; + private readonly ShellBlueprint _shellBlueprint; public DataMigrationManager( IEnumerable dataMigrations, IRepository dataMigrationRepository, IDataMigrationGenerator dataMigrationGenerator, IExtensionManager extensionManager, - IDataMigrationInterpreter interpreter) { + IDataMigrationInterpreter interpreter, + ShellBlueprint shellBlueprint) { _dataMigrations = dataMigrations; _dataMigrationRepository = dataMigrationRepository; _dataMigrationGenerator = dataMigrationGenerator; _extensionManager = extensionManager; _interpreter = interpreter; + _shellBlueprint = shellBlueprint; Logger = NullLogger.Instance; } @@ -116,8 +120,10 @@ namespace Orchard.DataMigration { current = (int)createMethod.Invoke(migration, new object[0]); } else { - var commands = _dataMigrationGenerator.CreateCommands(); - /// TODO: Execute commands and define current version number + var commands = _dataMigrationGenerator.CreateCommands(_shellBlueprint.Records.Where(record => record.Feature.Descriptor.Name == feature)); + foreach(var command in commands) { + _interpreter.Visit(command); + } } } diff --git a/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs b/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs index b9591c28e..003d207a5 100644 --- a/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs +++ b/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs @@ -1,10 +1,19 @@ using System.Collections.Generic; using System.Linq; +using FluentNHibernate.Cfg; +using Orchard.Data.Builders; +using Orchard.DataMigration.Schema; +using Orchard.Environment.ShellBuilders.Models; namespace Orchard.DataMigration { public class DefaultDataMigrationGenerator : IDataMigrationGenerator { - public IEnumerable CreateCommands() { - return Enumerable.Empty(); + public IEnumerable CreateCommands(IEnumerable records) { + + // use FluentNhibernate generation for this module + var persistenceModel = AbstractBuilder.CreatePersistenceModel(records); + var configuration = Fluently.Configure().Mappings(m => m.AutoMappings.Add(persistenceModel)); + + return Enumerable.Empty(); } } } diff --git a/src/Orchard/DataMigration/IDataMigrationCommand.cs b/src/Orchard/DataMigration/IDataMigrationCommand.cs deleted file mode 100644 index cb56b9c63..000000000 --- a/src/Orchard/DataMigration/IDataMigrationCommand.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace Orchard.DataMigration { - public interface IDataMigrationCommand { - } -} diff --git a/src/Orchard/DataMigration/IDataMigrationGenerator.cs b/src/Orchard/DataMigration/IDataMigrationGenerator.cs index 72cce65b4..a2c59b6c7 100644 --- a/src/Orchard/DataMigration/IDataMigrationGenerator.cs +++ b/src/Orchard/DataMigration/IDataMigrationGenerator.cs @@ -1,8 +1,11 @@ using System.Collections.Generic; +using FluentNHibernate.Cfg; +using Orchard.DataMigration.Schema; +using Orchard.Environment.ShellBuilders.Models; namespace Orchard.DataMigration { // Builds and runs the representative migration create calls public interface IDataMigrationGenerator : IDependency { - IEnumerable CreateCommands(); + IEnumerable CreateCommands(IEnumerable records); } } diff --git a/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs b/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs index 4464a9fdd..1c19efea5 100644 --- a/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs +++ b/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs @@ -35,25 +35,30 @@ namespace Orchard.DataMigration.Interpreters { get { return _sqlStatements; } } - public void Visit(SchemaCommand command) { - switch (command.Type) { + public void Visit(ISchemaBuilderCommand command) { + var schemaCommand = command as SchemaCommand; + if (schemaCommand == null) { + return; + } + + switch ( schemaCommand.Type ) { case SchemaCommandType.CreateTable: - Visit((CreateTableCommand)command); + Visit((CreateTableCommand)schemaCommand); break; case SchemaCommandType.AlterTable: - Visit((AlterTableCommand)command); + Visit((AlterTableCommand)schemaCommand); break; case SchemaCommandType.DropTable: - Visit((DropTableCommand)command); + Visit((DropTableCommand)schemaCommand); break; case SchemaCommandType.SqlStatement: - Visit((SqlStatementCommand)command); + Visit((SqlStatementCommand)schemaCommand); break; case SchemaCommandType.CreateForeignKey: - Visit((CreateForeignKeyCommand)command); + Visit((CreateForeignKeyCommand)schemaCommand); break; case SchemaCommandType.DropForeignKey: - Visit((DropForeignKeyCommand)command); + Visit((DropForeignKeyCommand)schemaCommand); break; } } diff --git a/src/Orchard/DataMigration/Interpreters/IDataMigrationInterpreter.cs b/src/Orchard/DataMigration/Interpreters/IDataMigrationInterpreter.cs index 63fe47135..0827e3a87 100644 --- a/src/Orchard/DataMigration/Interpreters/IDataMigrationInterpreter.cs +++ b/src/Orchard/DataMigration/Interpreters/IDataMigrationInterpreter.cs @@ -2,7 +2,7 @@ namespace Orchard.DataMigration.Interpreters { public interface IDataMigrationInterpreter : IDependency{ - void Visit(SchemaCommand command); + void Visit(ISchemaBuilderCommand command); void Visit(CreateTableCommand command); void Visit(DropTableCommand command); void Visit(AlterTableCommand command); diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 418cd1813..584dab285 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -376,7 +376,6 @@ - From a09536a44a17105d335361daecd2a5163cc67e9f Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 25 Jun 2010 17:06:02 -0700 Subject: [PATCH 02/19] Updated code to reflect new DataServicesProvider changes --HG-- branch : dev --- .../Orchard.Setup/Services/SetupService.cs | 16 ++++++++++++++-- .../DefaultDataMigrationGenerator.cs | 4 ++-- src/Orchard/Orchard.Framework.csproj | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index 01d642d17..d2e078178 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -19,6 +19,8 @@ using Orchard.Security; using Orchard.Settings; using Orchard.Themes; using Orchard.UI.Notify; +using Orchard.Environment.State; +using Orchard.DataMigration; namespace Orchard.Setup.Services { public class SetupService : ISetupService { @@ -27,6 +29,8 @@ namespace Orchard.Setup.Services { private readonly IShellSettingsManager _shellSettingsManager; private readonly IShellContainerFactory _shellContainerFactory; private readonly ICompositionStrategy _compositionStrategy; + private readonly IProcessingEngine _processingEngine; + private readonly IDataMigrationManager _dataMigrationManager; public SetupService( ShellSettings shellSettings, @@ -34,12 +38,16 @@ namespace Orchard.Setup.Services { IOrchardHost orchardHost, IShellSettingsManager shellSettingsManager, IShellContainerFactory shellContainerFactory, - ICompositionStrategy compositionStrategy) { + ICompositionStrategy compositionStrategy, + IProcessingEngine processingEngine, + IDataMigrationManager dataMigrationManager) { _shellSettings = shellSettings; _orchardHost = orchardHost; _shellSettingsManager = shellSettingsManager; _shellContainerFactory = shellContainerFactory; _compositionStrategy = compositionStrategy; + _processingEngine = processingEngine; + _dataMigrationManager = dataMigrationManager; T = NullLocalizer.Instance; } @@ -97,7 +105,7 @@ namespace Orchard.Setup.Services { // initialize database explicitly, and store shell descriptor var bootstrapLifetimeScope = _shellContainerFactory.CreateContainer(shellSettings, shellToplogy); using (var environment = new StandaloneEnvironment(bootstrapLifetimeScope)) { - environment.Resolve().CreateDatabase(); + _dataMigrationManager.Update(new [] { "Orchard.Framework", "Settings" }); environment.Resolve().UpdateShellDescriptor( 0, @@ -105,6 +113,10 @@ namespace Orchard.Setup.Services { shellDescriptor.Parameters); } + // in effect "pump messages" see PostMessage circa 1980 + while ( _processingEngine.AreTasksPending() ) + _processingEngine.ExecuteNextTask(); + // creating a standalone environment. // in theory this environment can be used to resolve any normal components by interface, and those diff --git a/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs b/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs index 003d207a5..f398c7103 100644 --- a/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs +++ b/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using FluentNHibernate.Cfg; -using Orchard.Data.Builders; +using Orchard.Data.Providers; using Orchard.DataMigration.Schema; using Orchard.Environment.ShellBuilders.Models; @@ -10,7 +10,7 @@ namespace Orchard.DataMigration { public IEnumerable CreateCommands(IEnumerable records) { // use FluentNhibernate generation for this module - var persistenceModel = AbstractBuilder.CreatePersistenceModel(records); + var persistenceModel = AbstractDataServicesProvider.CreatePersistenceModel(records); var configuration = Fluently.Configure().Mappings(m => m.AutoMappings.Add(persistenceModel)); return Enumerable.Empty(); diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 2d93e7a09..0416f0c0d 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -356,6 +356,7 @@ Code + From 01f861707854bf767a55e9c60ac796d4f2366ca7 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Mon, 28 Jun 2010 17:21:19 -0700 Subject: [PATCH 03/19] Changing the Getter/Setter deletages to an IFieldStorage interface Deletages seemed inconsistent with design of rest of system Interface allows for typed accessor methods, which will be important for columnar backing --HG-- branch : dev --- .../InfosetFieldStorageProviderTests.cs | 42 +++++++++---------- .../Core/Common/Fields/TextField.cs | 5 ++- src/Orchard/ContentManagement/ContentField.cs | 4 +- .../Drivers/ContentFieldDriver.cs | 3 +- .../FieldStorage/IFieldStorage.cs | 12 +++++- .../InfosetStorage/InfosetStorageProvider.cs | 15 ++----- .../FieldStorage/SimpleFieldStorage.cs | 25 +++++++++++ src/Orchard/Orchard.Framework.csproj | 1 + 8 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 src/Orchard/ContentManagement/FieldStorage/SimpleFieldStorage.cs diff --git a/src/Orchard.Tests/ContentManagement/Drivers/FieldStorage/InfosetFieldStorageProviderTests.cs b/src/Orchard.Tests/ContentManagement/Drivers/FieldStorage/InfosetFieldStorageProviderTests.cs index 740e433cc..b64acb8dc 100644 --- a/src/Orchard.Tests/ContentManagement/Drivers/FieldStorage/InfosetFieldStorageProviderTests.cs +++ b/src/Orchard.Tests/ContentManagement/Drivers/FieldStorage/InfosetFieldStorageProviderTests.cs @@ -60,9 +60,9 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage { public void GettingUnsetNamedAndUnnamedValueIsSafeAndNull() { var part = CreateContentItemPart(); var storage = _provider.BindStorage(part, part.PartDefinition.Fields.Single()); - Assert.That(storage.Getter(null), Is.Null); - Assert.That(storage.Getter("value"), Is.Null); - Assert.That(storage.Getter("This is a test"), Is.Null); + Assert.That(storage.Get(null), Is.Null); + Assert.That(storage.Get("value"), Is.Null); + Assert.That(storage.Get("This is a test"), Is.Null); } [Test] @@ -70,10 +70,10 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage { var part = CreateContentItemPart(); var storage = _provider.BindStorage(part, part.PartDefinition.Fields.Single()); - Assert.That(storage.Getter("alpha"), Is.Null); - storage.Setter("alpha", "one"); - Assert.That(storage.Getter("alpha"), Is.Not.Null); - Assert.That(storage.Getter("alpha"), Is.EqualTo("one")); + Assert.That(storage.Get("alpha"), Is.Null); + storage.Set("alpha", "one"); + Assert.That(storage.Get("alpha"), Is.Not.Null); + Assert.That(storage.Get("alpha"), Is.EqualTo("one")); } [Test] @@ -81,14 +81,14 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage { var part = CreateContentItemPart(); var storage = _provider.BindStorage(part, part.PartDefinition.Fields.Single()); - Assert.That(storage.Getter(null), Is.Null); - Assert.That(storage.Getter(""), Is.Null); - storage.Setter(null, "one"); - Assert.That(storage.Getter(null), Is.EqualTo("one")); - Assert.That(storage.Getter(""), Is.EqualTo("one")); - storage.Setter(null, "two"); - Assert.That(storage.Getter(null), Is.EqualTo("two")); - Assert.That(storage.Getter(""), Is.EqualTo("two")); + Assert.That(storage.Get(null), Is.Null); + Assert.That(storage.Get(""), Is.Null); + storage.Set(null, "one"); + Assert.That(storage.Get(null), Is.EqualTo("one")); + Assert.That(storage.Get(""), Is.EqualTo("one")); + storage.Set(null, "two"); + Assert.That(storage.Get(null), Is.EqualTo("two")); + Assert.That(storage.Get(""), Is.EqualTo("two")); } [Test] @@ -96,8 +96,8 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage { var part = CreateContentItemPart(); var storage = _provider.BindStorage(part, part.PartDefinition.Fields.Single()); - storage.Setter(null, "one"); - storage.Setter("alpha", "two"); + storage.Set(null, "one"); + storage.Set("alpha", "two"); Assert.That(part.ContentItem.Record.Data, Is.EqualTo("one")); } @@ -107,14 +107,14 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage { var part = CreateContentItemPart(); var storage = _provider.BindStorage(part, part.PartDefinition.Fields.Single()); - storage.Setter(null, "one"); - storage.Setter("alpha", "two"); + storage.Set(null, "one"); + storage.Set("alpha", "two"); Assert.That(part.ContentItem.Record.Data, Is.EqualTo("one")); part.ContentItem.Record.Data = "three"; - storage.Setter(null, "three"); - storage.Setter("alpha", "four"); + storage.Set(null, "three"); + storage.Set("alpha", "four"); } [Test] diff --git a/src/Orchard.Web/Core/Common/Fields/TextField.cs b/src/Orchard.Web/Core/Common/Fields/TextField.cs index a7df68bd4..1a26a10da 100644 --- a/src/Orchard.Web/Core/Common/Fields/TextField.cs +++ b/src/Orchard.Web/Core/Common/Fields/TextField.cs @@ -1,10 +1,11 @@ using Orchard.ContentManagement; +using Orchard.ContentManagement.FieldStorage; namespace Orchard.Core.Common.Fields { public class TextField : ContentField { public string Value { - get { return Getter(null); } - set { Setter(null, value); } + get { return Storage.Get(); } + set { Storage.Set(value); } } } } diff --git a/src/Orchard/ContentManagement/ContentField.cs b/src/Orchard/ContentManagement/ContentField.cs index d557c121c..3d3486ac5 100644 --- a/src/Orchard/ContentManagement/ContentField.cs +++ b/src/Orchard/ContentManagement/ContentField.cs @@ -1,4 +1,5 @@ using System; +using Orchard.ContentManagement.FieldStorage; using Orchard.ContentManagement.MetaData.Models; namespace Orchard.ContentManagement { @@ -8,7 +9,6 @@ namespace Orchard.ContentManagement { public ContentPartDefinition.Field PartFieldDefinition { get; set; } public ContentFieldDefinition FieldDefinition { get { return PartFieldDefinition.FieldDefinition; } } - public Func Getter { get; set; } - public Action Setter { get; set; } + public IFieldStorage Storage { protected get; set; } } } diff --git a/src/Orchard/ContentManagement/Drivers/ContentFieldDriver.cs b/src/Orchard/ContentManagement/Drivers/ContentFieldDriver.cs index 64139d934..9e98216be 100644 --- a/src/Orchard/ContentManagement/Drivers/ContentFieldDriver.cs +++ b/src/Orchard/ContentManagement/Drivers/ContentFieldDriver.cs @@ -34,8 +34,7 @@ namespace Orchard.ContentManagement.Drivers { FieldTypeName = typeof (TField).Name, Factory = (partFieldDefinition, storage) => new TField { PartFieldDefinition = partFieldDefinition, - Getter = storage.Getter, - Setter = storage.Setter, + Storage = storage, } } }; diff --git a/src/Orchard/ContentManagement/FieldStorage/IFieldStorage.cs b/src/Orchard/ContentManagement/FieldStorage/IFieldStorage.cs index 9a5a6edf4..cc82db104 100644 --- a/src/Orchard/ContentManagement/FieldStorage/IFieldStorage.cs +++ b/src/Orchard/ContentManagement/FieldStorage/IFieldStorage.cs @@ -2,7 +2,15 @@ namespace Orchard.ContentManagement.FieldStorage { public interface IFieldStorage { - Func Getter { get; } - Action Setter { get; } + T Get(string name); + void Set(string name, T value); + } + public static class FieldStorageExtension{ + public static T Get(this IFieldStorage storage) { + return storage.Get(null); + } + public static void Set(this IFieldStorage storage, T value) { + storage.Set(null, value); + } } } \ No newline at end of file diff --git a/src/Orchard/ContentManagement/FieldStorage/InfosetStorage/InfosetStorageProvider.cs b/src/Orchard/ContentManagement/FieldStorage/InfosetStorage/InfosetStorageProvider.cs index bcff1def3..a0fb51ab9 100644 --- a/src/Orchard/ContentManagement/FieldStorage/InfosetStorage/InfosetStorageProvider.cs +++ b/src/Orchard/ContentManagement/FieldStorage/InfosetStorage/InfosetStorageProvider.cs @@ -1,5 +1,4 @@ -using System; -using System.Xml; +using System.Xml; using System.Xml.Linq; using Orchard.ContentManagement.MetaData.Models; @@ -14,10 +13,9 @@ namespace Orchard.ContentManagement.FieldStorage.InfosetStorage { var fieldName = XmlConvert.EncodeLocalName(partFieldDefinition.Name); var infosetPart = contentPart.As(); - return new Storage { - Getter = name => Get(infosetPart.Infoset.Element, partName, fieldName, name), - Setter = (name, value) => Set(infosetPart.Infoset.Element, partName, fieldName, name, value) - }; + return new SimpleFieldStorage( + name => Get(infosetPart.Infoset.Element, partName, fieldName, name), + (name, value) => Set(infosetPart.Infoset.Element, partName, fieldName, name, value)); } private static string Get(XElement element, string partName, string fieldName, string valueName) { @@ -57,10 +55,5 @@ namespace Orchard.ContentManagement.FieldStorage.InfosetStorage { fieldElement.SetAttributeValue(XmlConvert.EncodeLocalName(valueName), value); } } - - class Storage : IFieldStorage { - public Func Getter { get; set; } - public Action Setter { get; set; } - } } } \ No newline at end of file diff --git a/src/Orchard/ContentManagement/FieldStorage/SimpleFieldStorage.cs b/src/Orchard/ContentManagement/FieldStorage/SimpleFieldStorage.cs new file mode 100644 index 000000000..2897bf430 --- /dev/null +++ b/src/Orchard/ContentManagement/FieldStorage/SimpleFieldStorage.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; + +namespace Orchard.ContentManagement.FieldStorage { + public class SimpleFieldStorage : IFieldStorage { + public SimpleFieldStorage(Func getter, Action setter) { + Getter = getter; + Setter = setter; + } + + public Func Getter { get; set; } + public Action Setter { get; set; } + + public T Get(string name) { + var value = Getter(name); + return string.IsNullOrEmpty(value) + ? default(T) + : (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture); + } + + public void Set(string name, T value) { + Setter(name, Convert.ToString(value, CultureInfo.InvariantCulture)); + } + } +} \ No newline at end of file diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 194d3ea19..2edd3eaaf 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -207,6 +207,7 @@ + Code From ca0de6aa492e52cf9e95763ff118fd8eee6ba7e8 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 29 Jun 2010 11:28:21 -0700 Subject: [PATCH 04/19] Use DataMigration API to create tables by default Created DataMigration class for the Settings module --HG-- branch : dev --- .../DataMigration/DataMigrationTests.cs | 5 +- .../DataMigration/SchemaBuilderTests.cs | 2 +- src/Orchard.Web/Core/Orchard.Core.csproj | 1 + .../DataMigrations/SettingsDataMigration.cs | 89 +++++++++++++++++++ .../Orchard.Setup/Orchard.Setup.csproj | 1 + .../Orchard.Setup/Services/SetupService.cs | 19 ++-- .../Modules/Orchard.Setup/SetupMode.cs | 5 ++ .../Data/Providers/IDataServicesProvider.cs | 5 +- .../Providers/IDataServicesProviderFactory.cs | 1 + src/Orchard/Data/SessionFactoryHolder.cs | 17 ++-- .../DataMigration/DataMigrationManager.cs | 17 +--- .../DefaultDataMigrationGenerator.cs | 5 -- .../DefaultDataMigrationInterpreter.cs | 16 +++- .../Schema/CreateTableCommand.cs | 17 ++++ .../DataMigration/Schema/SchemaBuilder.cs | 6 ++ src/Orchard/Orchard.Framework.csproj | 1 - 16 files changed, 168 insertions(+), 39 deletions(-) create mode 100644 src/Orchard.Web/Core/Settings/DataMigrations/SettingsDataMigration.cs diff --git a/src/Orchard.Tests/DataMigration/DataMigrationTests.cs b/src/Orchard.Tests/DataMigration/DataMigrationTests.cs index f151226ca..f1d88760e 100644 --- a/src/Orchard.Tests/DataMigration/DataMigrationTests.cs +++ b/src/Orchard.Tests/DataMigration/DataMigrationTests.cs @@ -14,6 +14,7 @@ using Orchard.Environment.Extensions.Folders; using Orchard.Environment.Extensions.Models; using Orchard.Tests.ContentManagement; using Orchard.DataMigration; +using Orchard.Data.Providers; namespace Orchard.Tests.DataMigration { [TestFixture] @@ -50,7 +51,9 @@ namespace Orchard.Tests.DataMigration { _folders = new StubFolders(); builder.RegisterInstance(new ShellSettings { DataTablePrefix = "TEST_"}); - + + builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterInstance(_folders).As(); builder.RegisterType().As(); diff --git a/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs b/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs index 870b02421..3d734edba 100644 --- a/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs +++ b/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs @@ -65,7 +65,7 @@ namespace Orchard.Tests.DataMigration { .CreateIndex("IDX_XYZ", "NickName")) .AlterTable("User", table => table .DropIndex("IDX_XYZ")) - .DropForeignKey("Addresse", "User_Address") + .DropForeignKey("Address", "User_Address") .DropTable("Address") .ExecuteSql("drop database", statement => statement.ForProvider("SQLite")) .ExecuteSql("DROP DATABASE", statement => statement.ForProvider("SQLServer")); diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index e01c2e49b..a70ca21c0 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -159,6 +159,7 @@ + diff --git a/src/Orchard.Web/Core/Settings/DataMigrations/SettingsDataMigration.cs b/src/Orchard.Web/Core/Settings/DataMigrations/SettingsDataMigration.cs new file mode 100644 index 000000000..eba65db7c --- /dev/null +++ b/src/Orchard.Web/Core/Settings/DataMigrations/SettingsDataMigration.cs @@ -0,0 +1,89 @@ +using Orchard.DataMigration; + +namespace Orchard.Core.Settings.DataMigrations { + public class SettingsDataMigration : DataMigrationImpl { + public override string Feature { + get { return "Settings"; } + } + + public int Create() { + //CREATE TABLE Settings_ContentFieldDefinitionRecord (Id integer, Name TEXT, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ContentFieldDefinitionRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + ); + + //CREATE TABLE Settings_ContentPartDefinitionRecord (Id integer, Name TEXT, Hidden INTEGER, Settings TEXT, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ContentPartDefinitionRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + .Column("Hidden") + .Column("Settings") + ); + + //CREATE TABLE Settings_ContentPartFieldDefinitionRecord (Id integer, Name TEXT, Settings TEXT, ContentFieldDefinitionRecord_id INTEGER, INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ContentPartFieldDefinitionRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + .Column("Settings") + .Column("ContentFieldDefinitionRecord_id") + .Column("ContentPartDefinitionRecord_Id") + ); + + //CREATE TABLE Settings_ContentTypeDefinitionRecord (Id integer, Name TEXT, DisplayName TEXT, Hidden INTEGER, Settings TEXT, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ContentTypeDefinitionRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + .Column("DisplayName") + .Column("Hidden") + .Column("Settings") + ); + + //CREATE TABLE Settings_ContentTypePartDefinitionRecord (Id integer, Settings TEXT, ContentPartDefinitionRecord_id INTEGER, ContentTypeDefinitionRecord_Id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ContentTypePartDefinitionRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Settings") + .Column("ContentPartDefinitionRecord_id") + .Column("ContentTypeDefinitionRecord_Id") + ); + + //CREATE TABLE Settings_ShellDescriptorRecord (Id integer, SerialNumber INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ShellDescriptorRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("SerialNumber") + ); + + //CREATE TABLE Settings_ShellFeatureRecord (Id integer, Name TEXT, ShellDescriptorRecord_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ShellFeatureRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + .Column("ShellDescriptorRecord_id")); + + //CREATE TABLE Settings_ShellFeatureStateRecord (Id integer, Name TEXT, InstallState TEXT, EnableState TEXT, ShellStateRecord_Id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ShellFeatureStateRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + .Column("InstallState") + .Column("EnableState") + .Column("ShellStateRecord_Id") + ); + + //CREATE TABLE Settings_ShellParameterRecord (Id integer, Component TEXT, Name TEXT, Value TEXT, ShellDescriptorRecord_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ShellParameterRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Component") + .Column("Name") + .Column("Value") + .Column("ShellDescriptorRecord_id") + ); + + //CREATE TABLE Settings_ShellStateRecord (Id integer, primary key (Id)); + SchemaBuilder.CreateTable("Settings_ShellStateRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj b/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj index 47e1b5f1d..0c789a699 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj +++ b/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj @@ -43,6 +43,7 @@ False ..\..\..\..\lib\autofac\Autofac.dll + diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index d2e078178..7e833695f 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -8,6 +8,9 @@ using Orchard.Core.Common.Models; using Orchard.Core.Navigation.Models; using Orchard.Core.Settings.Models; using Orchard.Data; +using Orchard.Data.Providers; +using Orchard.DataMigration.Interpreters; +using Orchard.DataMigration.Schema; using Orchard.Environment; using Orchard.Environment.Configuration; using Orchard.Environment.ShellBuilders; @@ -30,7 +33,6 @@ namespace Orchard.Setup.Services { private readonly IShellContainerFactory _shellContainerFactory; private readonly ICompositionStrategy _compositionStrategy; private readonly IProcessingEngine _processingEngine; - private readonly IDataMigrationManager _dataMigrationManager; public SetupService( ShellSettings shellSettings, @@ -39,15 +41,13 @@ namespace Orchard.Setup.Services { IShellSettingsManager shellSettingsManager, IShellContainerFactory shellContainerFactory, ICompositionStrategy compositionStrategy, - IProcessingEngine processingEngine, - IDataMigrationManager dataMigrationManager) { + IProcessingEngine processingEngine) { _shellSettings = shellSettings; _orchardHost = orchardHost; _shellSettingsManager = shellSettingsManager; _shellContainerFactory = shellContainerFactory; _compositionStrategy = compositionStrategy; _processingEngine = processingEngine; - _dataMigrationManager = dataMigrationManager; T = NullLocalizer.Instance; } @@ -105,7 +105,16 @@ namespace Orchard.Setup.Services { // initialize database explicitly, and store shell descriptor var bootstrapLifetimeScope = _shellContainerFactory.CreateContainer(shellSettings, shellToplogy); using (var environment = new StandaloneEnvironment(bootstrapLifetimeScope)) { - _dataMigrationManager.Update(new [] { "Orchard.Framework", "Settings" }); + + var schemaBuilder = new SchemaBuilder(environment.Resolve() ); + + schemaBuilder.CreateTable("Orchard_Framework_DataMigrationRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("DataMigrationClass") + .Column("Current")); + + var dataMigrationManager = environment.Resolve(); + dataMigrationManager.Update("Settings"); environment.Resolve().UpdateShellDescriptor( 0, diff --git a/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs b/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs index 4c27ad19d..d0f4ee5aa 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs @@ -9,6 +9,8 @@ using Orchard.ContentManagement; using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.MetaData.Builders; using Orchard.Data.Providers; +using Orchard.DataMigration; +using Orchard.DataMigration.Interpreters; using Orchard.Environment.Extensions; using Orchard.Localization; using Orchard.Mvc; @@ -50,6 +52,9 @@ namespace Orchard.Setup { builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); + builder.RegisterType().As().InstancePerLifetimeScope(); + builder.RegisterType().As().InstancePerLifetimeScope(); + } diff --git a/src/Orchard/Data/Providers/IDataServicesProvider.cs b/src/Orchard/Data/Providers/IDataServicesProvider.cs index 2d66a4a87..19e5a3176 100644 --- a/src/Orchard/Data/Providers/IDataServicesProvider.cs +++ b/src/Orchard/Data/Providers/IDataServicesProvider.cs @@ -1,4 +1,7 @@ -using NHibernate; +using System; +using FluentNHibernate.Cfg; +using NHibernate; +using NHibernate.Cfg; namespace Orchard.Data.Providers { public interface IDataServicesProvider : ITransientDependency { diff --git a/src/Orchard/Data/Providers/IDataServicesProviderFactory.cs b/src/Orchard/Data/Providers/IDataServicesProviderFactory.cs index 8b47d40dd..a69c39e42 100644 --- a/src/Orchard/Data/Providers/IDataServicesProviderFactory.cs +++ b/src/Orchard/Data/Providers/IDataServicesProviderFactory.cs @@ -10,5 +10,6 @@ namespace Orchard.Data.Providers { var provider = factory.CreateProvider(sessionFactoryParameters); return provider != null ? provider.BuildSessionFactory(sessionFactoryParameters) : null; } + } } diff --git a/src/Orchard/Data/SessionFactoryHolder.cs b/src/Orchard/Data/SessionFactoryHolder.cs index aa5daeccb..2ac68ce97 100644 --- a/src/Orchard/Data/SessionFactoryHolder.cs +++ b/src/Orchard/Data/SessionFactoryHolder.cs @@ -13,6 +13,7 @@ using Orchard.Logging; namespace Orchard.Data { public interface ISessionFactoryHolder : ISingletonDependency { ISessionFactory GetSessionFactory(); + SessionFactoryParameters CreateSessionFactoryParameters(bool createDatabase, bool updateSchema); void CreateDatabase(); void UpdateSchema(); } @@ -67,7 +68,7 @@ namespace Orchard.Data { public ISessionFactory GetSessionFactory() { lock (this) { if (_sessionFactory == null) { - _sessionFactory = BuildSessionFactory(false /*createDatabase*/, true /*updateSchema*/); + _sessionFactory = BuildSessionFactory(false /*createDatabase*/, false /*updateSchema*/); } } return _sessionFactory; @@ -76,24 +77,24 @@ namespace Orchard.Data { private ISessionFactory BuildSessionFactory(bool createDatabase, bool updateSchema) { Logger.Debug("Building session factory"); + var sessionFactory = _dataServicesProviderFactory.BuildSessionFactory(CreateSessionFactoryParameters(createDatabase, updateSchema)); + return sessionFactory; + } + + public SessionFactoryParameters CreateSessionFactoryParameters(bool createDatabase, bool updateSchema) { var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name); _appDataFolder.CreateDirectory(shellPath); var shellFolder = _appDataFolder.MapPath(shellPath); - var sessionFactory = _dataServicesProviderFactory.BuildSessionFactory(new SessionFactoryParameters { + return new SessionFactoryParameters { Provider = _shellSettings.DataProvider, DataFolder = shellFolder, ConnectionString = _shellSettings.DataConnectionString, CreateDatabase = createDatabase, UpdateSchema = updateSchema, RecordDescriptors = _shellBlueprint.Records, - }); - - return sessionFactory; + }; } - } - - } diff --git a/src/Orchard/DataMigration/DataMigrationManager.cs b/src/Orchard/DataMigration/DataMigrationManager.cs index 943a2d8b1..c2666ac00 100644 --- a/src/Orchard/DataMigration/DataMigrationManager.cs +++ b/src/Orchard/DataMigration/DataMigrationManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using Orchard.Data; +using Orchard.Data.Providers; using Orchard.DataMigration.Interpreters; using Orchard.DataMigration.Schema; using Orchard.Environment.Extensions; @@ -18,24 +19,18 @@ namespace Orchard.DataMigration { public class DataMigrationManager : IDataMigrationManager { private readonly IEnumerable _dataMigrations; private readonly IRepository _dataMigrationRepository; - private readonly IDataMigrationGenerator _dataMigrationGenerator; private readonly IExtensionManager _extensionManager; private readonly IDataMigrationInterpreter _interpreter; - private readonly ShellBlueprint _shellBlueprint; public DataMigrationManager( IEnumerable dataMigrations, IRepository dataMigrationRepository, - IDataMigrationGenerator dataMigrationGenerator, IExtensionManager extensionManager, - IDataMigrationInterpreter interpreter, - ShellBlueprint shellBlueprint) { + IDataMigrationInterpreter interpreter) { _dataMigrations = dataMigrations; _dataMigrationRepository = dataMigrationRepository; - _dataMigrationGenerator = dataMigrationGenerator; _extensionManager = extensionManager; _interpreter = interpreter; - _shellBlueprint = shellBlueprint; Logger = NullLogger.Instance; } @@ -84,6 +79,8 @@ namespace Orchard.DataMigration { public void Update(string feature){ + Logger.Information("Updating {0}", feature); + // proceed with dependent features first, whatever the module it's in var dependencies = ShellStateCoordinator.OrderByDependencies(_extensionManager.AvailableExtensions() .SelectMany(ext => ext.Features)) @@ -119,12 +116,6 @@ namespace Orchard.DataMigration { if(createMethod != null) { current = (int)createMethod.Invoke(migration, new object[0]); } - else { - var commands = _dataMigrationGenerator.CreateCommands(_shellBlueprint.Records.Where(record => record.Feature.Descriptor.Name == feature)); - foreach(var command in commands) { - _interpreter.Visit(command); - } - } } var lookupTable = CreateUpgradeLookupTable(migration); diff --git a/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs b/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs index f398c7103..f33dc4d40 100644 --- a/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs +++ b/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; using System.Linq; -using FluentNHibernate.Cfg; -using Orchard.Data.Providers; using Orchard.DataMigration.Schema; using Orchard.Environment.ShellBuilders.Models; @@ -9,9 +7,6 @@ namespace Orchard.DataMigration { public class DefaultDataMigrationGenerator : IDataMigrationGenerator { public IEnumerable CreateCommands(IEnumerable records) { - // use FluentNhibernate generation for this module - var persistenceModel = AbstractDataServicesProvider.CreatePersistenceModel(records); - var configuration = Fluently.Configure().Mappings(m => m.AutoMappings.Add(persistenceModel)); return Enumerable.Empty(); } diff --git a/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs b/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs index 1c19efea5..3892917d5 100644 --- a/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs +++ b/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs @@ -86,6 +86,18 @@ namespace Orchard.DataMigration.Interpreters { Visit(builder, createColumn); } + var primaryKeys = command.TableCommands.OfType().Where(ccc => ccc.IsPrimaryKey).Select(ccc=>ccc.ColumnName); + if(primaryKeys.Any()) { + if ( appendComma ) { + builder.Append(", "); + } + + builder.Append(_dialect.PrimaryKeyString) + .Append(" ( ") + .Append(String.Join(", ", primaryKeys.ToArray())) + .Append(" )"); + } + builder.Append(" )"); _sqlStatements.Add(builder.ToString()); @@ -298,10 +310,6 @@ namespace Orchard.DataMigration.Interpreters { if ( command.IsUnique && _dialect.SupportsUnique ) { builder.Append(" unique"); } - - if ( command.IsPrimaryKey ) { - builder.Append(Space).Append(_dialect.PrimaryKeyString); - } } private void RunPendingStatements() { diff --git a/src/Orchard/DataMigration/Schema/CreateTableCommand.cs b/src/Orchard/DataMigration/Schema/CreateTableCommand.cs index f6a22ebec..8072a18ac 100644 --- a/src/Orchard/DataMigration/Schema/CreateTableCommand.cs +++ b/src/Orchard/DataMigration/Schema/CreateTableCommand.cs @@ -18,6 +18,23 @@ namespace Orchard.DataMigration.Schema { return this; } + public CreateTableCommand Column(string columnName, Action column = null) { + var dbType = System.Data.DbType.Object; + switch(System.Type.GetTypeCode(typeof(T))) { + case TypeCode.String : + dbType = DbType.String; + break; + case TypeCode.Int32 : + dbType = DbType.Int32; + break; + default: + Enum.TryParse(System.Type.GetTypeCode(typeof (T)).ToString(), true, out dbType); + break; + } + + return Column(columnName, dbType, column); + } + public CreateTableCommand ContentPartRecord() { /// TODO: Call Column() with necessary information for content part records return this; diff --git a/src/Orchard/DataMigration/Schema/SchemaBuilder.cs b/src/Orchard/DataMigration/Schema/SchemaBuilder.cs index c133e59d1..c722bee4d 100644 --- a/src/Orchard/DataMigration/Schema/SchemaBuilder.cs +++ b/src/Orchard/DataMigration/Schema/SchemaBuilder.cs @@ -1,9 +1,11 @@ using System; using Orchard.DataMigration.Interpreters; +using Orchard.Environment.ShellBuilders.Models; namespace Orchard.DataMigration.Schema { public class SchemaBuilder { private readonly IDataMigrationInterpreter _interpreter; + public SchemaBuilder(IDataMigrationInterpreter interpreter) { _interpreter = interpreter; } @@ -15,6 +17,10 @@ namespace Orchard.DataMigration.Schema { return this; } + public SchemaBuilder CreateTable(Action table) { + return CreateTable(typeof (TRecord).FullName.Replace(".", "_"), table); + } + public SchemaBuilder AlterTable(string name, Action table) { var alterTable = new AlterTableCommand(name); table(alterTable); diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 0416f0c0d..2d93e7a09 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -356,7 +356,6 @@ Code - From a7c06649846f6f5e722ef6822e7e9854bd1faaa2 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 29 Jun 2010 12:24:09 -0700 Subject: [PATCH 05/19] Prevent the search index to have two documents for the same content item --HG-- branch : dev --- .../Indexing/LuceneIndexProviderTests.cs | 40 +++++++++++++++++++ .../Services/LuceneIndexProvider.cs | 36 +++++++++-------- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/Orchard.Tests.Modules/Indexing/LuceneIndexProviderTests.cs b/src/Orchard.Tests.Modules/Indexing/LuceneIndexProviderTests.cs index 07a35fb47..250df2ff6 100644 --- a/src/Orchard.Tests.Modules/Indexing/LuceneIndexProviderTests.cs +++ b/src/Orchard.Tests.Modules/Indexing/LuceneIndexProviderTests.cs @@ -249,5 +249,45 @@ namespace Orchard.Tests.Modules.Indexing { Assert.That(doc.IsDirty, Is.True); } + + [Test] + public void DocumentsShouldBeDeleted() { + _provider.CreateIndex("default"); + _provider.Store("default", _provider.New(1).Add("field", "value1")); + _provider.Store("default", _provider.New(11).Add("field", "value11")); + _provider.Store("default", _provider.New(111).Add("field", "value111")); + + var searchBuilder = _provider.CreateSearchBuilder("default"); + + Assert.That(searchBuilder.Get(1).ContentItemId, Is.EqualTo(1)); + Assert.That(searchBuilder.Get(11).ContentItemId, Is.EqualTo(11)); + Assert.That(searchBuilder.Get(111).ContentItemId, Is.EqualTo(111)); + + _provider.Delete("default", 1); + + Assert.That(searchBuilder.Get(1), Is.Null); + Assert.That(searchBuilder.Get(11).ContentItemId, Is.EqualTo(11)); + Assert.That(searchBuilder.Get(111).ContentItemId, Is.EqualTo(111)); + + _provider.Delete("default", new int[] {1, 11, 111 }); + + Assert.That(searchBuilder.Get(1), Is.Null); + Assert.That(searchBuilder.Get(11), Is.Null); + Assert.That(searchBuilder.Get(111), Is.Null); + + } + + [Test] + public void SameContentItemShouldNotBeIndexedTwice() { + _provider.CreateIndex("default"); + + var searchBuilder = _provider.CreateSearchBuilder("default"); + + _provider.Store("default", _provider.New(1).Add("field", "value1")); + Assert.That(searchBuilder.WithField("id", "1").Count(), Is.EqualTo(1)); + + _provider.Store("default", _provider.New(1).Add("field", "value2")); + Assert.That(searchBuilder.WithField("id", "1").Count(), Is.EqualTo(1)); + } } } diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Services/LuceneIndexProvider.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Services/LuceneIndexProvider.cs index e2271a8ec..0333687fb 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Services/LuceneIndexProvider.cs +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Services/LuceneIndexProvider.cs @@ -6,6 +6,7 @@ using Lucene.Net.Analysis; using Lucene.Net.Analysis.Standard; using Lucene.Net.Documents; using Lucene.Net.Index; +using Lucene.Net.Search; using Lucene.Net.Store; using Orchard.Environment.Configuration; using Orchard.FileSystems.AppData; @@ -141,13 +142,18 @@ namespace Orchard.Indexing.Services { return; } + // Remove any previous document for these content items + Delete(indexName, indexDocuments.Select(i => i.ContentItemId)); + var writer = new IndexWriter(GetDirectory(indexName), _analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); LuceneDocumentIndex current = null; try { + foreach ( var indexDocument in indexDocuments ) { current = indexDocument; var doc = CreateDocument(indexDocument); + writer.AddDocument(doc); Logger.Debug("Document [{0}] indexed", indexDocument.ContentItemId); } @@ -166,30 +172,28 @@ namespace Orchard.Indexing.Services { } public void Delete(string indexName, IEnumerable documentIds) { - if ( documentIds.AsQueryable().Count() == 0 ) { + if (!documentIds.Any()) { return; } - - var reader = IndexReader.Open(GetDirectory(indexName), false); + + var writer = new IndexWriter(GetDirectory(indexName), _analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); try { - foreach (var id in documentIds) { - try { - var term = new Term("id", id.ToString()); - if (reader.DeleteDocuments(term) != 0) { - Logger.Error("The document [{0}] could not be removed from the index [{1}]", id, indexName); - } - else { - Logger.Debug("Document [{0}] removed from index", id); - } - } - catch (Exception ex) { - Logger.Error(ex, "An unexpected error occured while removing the document [{0}] from the index [{1}].", id, indexName); + var query = new BooleanQuery(); + + try { + foreach (var id in documentIds) { + query.Add(new BooleanClause(new TermQuery(new Term("id", id.ToString())), BooleanClause.Occur.SHOULD)); } + + writer.DeleteDocuments(query); + } + catch (Exception ex) { + Logger.Error(ex, "An unexpected error occured while removing the documents [{0}] from the index [{1}].", String.Join(", ", documentIds), indexName); } } finally { - reader.Close(); + writer.Close(); } } From d6158e316bb629fb3d98bdaba135729b82af6b48 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Tue, 29 Jun 2010 15:07:40 -0700 Subject: [PATCH 06/19] Hooking up part setting management when editing content types/parts --HG-- branch : dev --- .../Core/Common/Drivers/BodyDriver.cs | 19 +- .../Core/Common/Settings/BodySettings.cs | 67 +++++++ .../DefinitionTemplates/BodyPartSettings.ascx | 6 + .../BodyTypePartSettings.ascx | 6 + .../EditorTemplates/PlainTextEditor.ascx | 3 + src/Orchard.Web/Core/Orchard.Core.csproj | 4 + .../Controllers/AdminController.cs | 172 +++++------------- .../Services/ContentDefinitionService.cs | 18 +- .../Services/IContentDefinitionService.cs | 2 +- .../ViewModels/EditTypeViewModel.cs | 1 + .../Views/Admin/EditPart.ascx | 2 +- .../Orchard.Setup/Services/SetupService.cs | 2 + src/Orchard/ContentManagement/ContentPart.cs | 1 + .../Builders/ContentPartDefinitionBuilder.cs | 2 + .../IContentDefinitionEditorEvents.cs | 10 + 15 files changed, 175 insertions(+), 140 deletions(-) create mode 100644 src/Orchard.Web/Core/Common/Settings/BodySettings.cs create mode 100644 src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyPartSettings.ascx create mode 100644 src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyTypePartSettings.ascx create mode 100644 src/Orchard.Web/Core/Common/Views/EditorTemplates/PlainTextEditor.ascx diff --git a/src/Orchard.Web/Core/Common/Drivers/BodyDriver.cs b/src/Orchard.Web/Core/Common/Drivers/BodyDriver.cs index f7a0a0264..4d5437b42 100644 --- a/src/Orchard.Web/Core/Common/Drivers/BodyDriver.cs +++ b/src/Orchard.Web/Core/Common/Drivers/BodyDriver.cs @@ -4,6 +4,7 @@ using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Drivers; using Orchard.Core.Common.Models; +using Orchard.Core.Common.Settings; using Orchard.Core.Common.ViewModels; namespace Orchard.Core.Common.Drivers { @@ -12,6 +13,7 @@ namespace Orchard.Core.Common.Drivers { public IOrchardServices Services { get; set; } private const string TemplateName = "Parts/Common.Body"; private const string DefaultTextEditorTemplate = "TinyMceTextEditor"; + private const string PlainTextEditorTemplate = "PlainTextEditor"; public BodyDriver(IOrchardServices services) { Services = services; @@ -21,7 +23,7 @@ namespace Orchard.Core.Common.Drivers { get { return "Body"; } } - // \/\/ Haackalicious on many accounts - don't copy what has been done here for the wrapper \/\/ + // \/\/ Hackalicious on many accounts - don't copy what has been done here for the wrapper \/\/ protected override DriverResult Display(BodyAspect part, string displayType) { var model = new BodyDisplayViewModel { BodyAspect = part, Text = BbcodeReplace(part.Text) }; @@ -40,16 +42,29 @@ namespace Orchard.Core.Common.Drivers { protected override DriverResult Editor(BodyAspect part, IUpdateModel updater) { var model = BuildEditorViewModel(part); updater.TryUpdateModel(model, Prefix, null, null); + + // only set the format if it has not yet been set to preserve the initial format type - might want to change this later to support changing body formats but...later + if (string.IsNullOrWhiteSpace(model.Format)) + model.Format = GetFlavor(part); + return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "5"); } private static BodyEditorViewModel BuildEditorViewModel(BodyAspect part) { return new BodyEditorViewModel { BodyAspect = part, - TextEditorTemplate = DefaultTextEditorTemplate, + TextEditorTemplate = GetFlavor(part) == "html" ? DefaultTextEditorTemplate : PlainTextEditorTemplate, AddMediaPath= new PathBuilder(part).AddContentType().AddContainerSlug().AddSlug().ToString() }; } + + private static string GetFlavor(BodyAspect part) { + var typePartSettings = part.Settings.GetModel(); + return (typePartSettings != null && !string.IsNullOrWhiteSpace(typePartSettings.Flavor)) + ? typePartSettings.Flavor + : part.PartDefinition.Settings.GetModel().FlavorDefault; + } + class PathBuilder { private readonly IContent _content; private string _path; diff --git a/src/Orchard.Web/Core/Common/Settings/BodySettings.cs b/src/Orchard.Web/Core/Common/Settings/BodySettings.cs new file mode 100644 index 000000000..2e951ee00 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Settings/BodySettings.cs @@ -0,0 +1,67 @@ +using System.Collections.Generic; +using Orchard.ContentManagement; +using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData.Builders; +using Orchard.ContentManagement.MetaData.Models; +using Orchard.ContentManagement.ViewModels; + +namespace Orchard.Core.Common.Settings { + public class BodyPartSettings { + public const string FlavorDefaultDefault = "html"; + private string _flavorDefault; + public string FlavorDefault { + get { return !string.IsNullOrWhiteSpace(_flavorDefault) + ? _flavorDefault + : FlavorDefaultDefault; } + set { _flavorDefault = value; } + } + } + + public class BodyTypePartSettings { + public string Flavor { get; set; } + } + + public class BodySettingsHooks : ContentDefinitionEditorEventsBase { + public override IEnumerable TypePartEditor(ContentTypeDefinition.Part definition) { + if (definition.PartDefinition.Name != "BodyAspect") + yield break; + + var model = definition.Settings.GetModel(); + + if (string.IsNullOrWhiteSpace(model.Flavor)) { + var partModel = definition.PartDefinition.Settings.GetModel(); + model.Flavor = partModel.FlavorDefault; + } + + yield return DefinitionTemplate(model); + } + + public override IEnumerable PartEditor(ContentPartDefinition definition) { + if (definition.Name != "BodyAspect") + yield break; + + var model = definition.Settings.GetModel(); + yield return DefinitionTemplate(model); + } + + public override IEnumerable TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel) { + if (builder.Name != "BodyAspect") + yield break; + + var model = new BodyTypePartSettings(); + updateModel.TryUpdateModel(model, "BodyTypePartSettings", null, null); + builder.WithSetting("BodyTypePartSettings.Flavor", !string.IsNullOrWhiteSpace(model.Flavor) ? model.Flavor : null); + yield return DefinitionTemplate(model); + } + + public override IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + if (builder.Name != "BodyAspect") + yield break; + + var model = new BodyPartSettings(); + updateModel.TryUpdateModel(model, "BodyPartSettings", null, null); + builder.WithSetting("BodyPartSettings.FlavorDefault", !string.IsNullOrWhiteSpace(model.FlavorDefault) ? model.FlavorDefault : null); + yield return DefinitionTemplate(model); + } + } +} diff --git a/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyPartSettings.ascx b/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyPartSettings.ascx new file mode 100644 index 000000000..b4a75d0f0 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyPartSettings.ascx @@ -0,0 +1,6 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +
+ + <%:Html.EditorFor(m => m.FlavorDefault)%> + <%:Html.ValidationMessageFor(m => m.FlavorDefault)%> +
diff --git a/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyTypePartSettings.ascx b/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyTypePartSettings.ascx new file mode 100644 index 000000000..e1b503fa4 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Views/DefinitionTemplates/BodyTypePartSettings.ascx @@ -0,0 +1,6 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +
+ + <%:Html.EditorFor(m => m.Flavor) %> + <%:Html.ValidationMessageFor(m => m.Flavor) %> +
diff --git a/src/Orchard.Web/Core/Common/Views/EditorTemplates/PlainTextEditor.ascx b/src/Orchard.Web/Core/Common/Views/EditorTemplates/PlainTextEditor.ascx new file mode 100644 index 000000000..fa8ace6e0 --- /dev/null +++ b/src/Orchard.Web/Core/Common/Views/EditorTemplates/PlainTextEditor.ascx @@ -0,0 +1,3 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Core.Common.ViewModels"%> +<%: Html.TextArea("Text", Model.Text, 25, 80, new { @class = Model.Format }) %> \ No newline at end of file diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index 85758fffe..430850584 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -68,6 +68,7 @@ + @@ -197,9 +198,12 @@ + + + diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 9bfc9cf20..88c6810cb 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -1,50 +1,34 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Orchard.ContentManagement; using Orchard.ContentManagement.MetaData; using Orchard.ContentManagement.MetaData.Models; -using Orchard.ContentManagement.ViewModels; using Orchard.ContentTypes.Services; using Orchard.ContentTypes.ViewModels; -using Orchard.Data; using Orchard.Localization; -using Orchard.Logging; using Orchard.Mvc.Results; -using Orchard.UI.Notify; namespace Orchard.ContentTypes.Controllers { public class AdminController : Controller { - private readonly INotifier _notifier; private readonly IContentDefinitionService _contentDefinitionService; private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly IContentManager _contentManager; - private readonly ITransactionManager _transactionManager; private readonly IContentDefinitionEditorEvents _extendViewModels; public AdminController( IOrchardServices orchardServices, - INotifier notifier, IContentDefinitionService contentDefinitionService, IContentDefinitionManager contentDefinitionManager, - IContentManager contentManager, - ITransactionManager transactionManager, IContentDefinitionEditorEvents extendViewModels) { Services = orchardServices; - _notifier = notifier; _contentDefinitionService = contentDefinitionService; _contentDefinitionManager = contentDefinitionManager; - _contentManager = contentManager; - _transactionManager = transactionManager; _extendViewModels = extendViewModels; T = NullLocalizer.Instance; - Logger = NullLogger.Instance; } public IOrchardServices Services { get; private set; } public Localizer T { get; set; } - public ILogger Logger { get; set; } public ActionResult Index() { return List(); } @@ -69,32 +53,14 @@ namespace Orchard.ContentTypes.Controllers { if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content type."))) return new HttpUnauthorizedResult(); - var model = new ContentTypeDefinition(""); - TryUpdateModel(model); - - if (!ModelState.IsValid) { - Services.TransactionManager.Cancel(); + if (!ModelState.IsValid) return View(viewModel); - } - _contentDefinitionService.AddTypeDefinition(model); + _contentDefinitionService.AddTypeDefinition(viewModel.DisplayName); return RedirectToAction("Index"); } - class Updater : IUpdateModel { - public AdminController Thunk { get; set; } - public Func _prefix = x => x; - - public bool TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class { - return Thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties); - } - - public void AddModelError(string key, LocalizedString errorMessage) { - Thunk.ModelState.AddModelError(_prefix(key), errorMessage.ToString()); - } - } - public ActionResult Edit(string id) { if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type."))) return new HttpUnauthorizedResult(); @@ -106,36 +72,30 @@ namespace Orchard.ContentTypes.Controllers { var viewModel = new EditTypeViewModel(contentTypeDefinition); viewModel.Parts = viewModel.Parts.ToArray(); - viewModel.Templates = _extendViewModels.TypeEditor(contentTypeDefinition); + var entries = viewModel.Parts.Join(contentTypeDefinition.Parts, - m => m.PartDefinition.Name, - d => d.PartDefinition.Name, - (model, definition) => new { model, definition }); - foreach (var entry in entries) { + m => m.PartDefinition.Name, + d => d.PartDefinition.Name, + (model, definition) => new {model, definition}); + foreach (var entry in entries) entry.model.Templates = _extendViewModels.TypePartEditor(entry.definition); - } return View(viewModel); } [HttpPost, ActionName("Edit")] - public ActionResult EditPOST(string id) { + public ActionResult EditPOST(EditTypeViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type."))) return new HttpUnauthorizedResult(); - var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id); + var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(viewModel.Name); if (contentTypeDefinition == null) return new NotFoundResult(); - var updater = new Updater { Thunk = this }; - - var viewModel = new EditTypeViewModel(); - TryUpdateModel(viewModel); - - - _contentDefinitionManager.AlterTypeDefinition(id, typeBuilder => { + var updater = new Updater(this); + _contentDefinitionManager.AlterTypeDefinition(viewModel.Name, typeBuilder => { typeBuilder.DisplayedAs(viewModel.DisplayName); @@ -156,63 +116,14 @@ namespace Orchard.ContentTypes.Controllers { } }); - if (!ModelState.IsValid) { - _transactionManager.Cancel(); + Services.TransactionManager.Cancel(); return View(viewModel); } - //var contentTypeDefinitionParts = viewModel.Parts.Select(GenerateTypePart).ToList(); - //if (viewModel.Fields.Any()) - // contentTypeDefinitionParts.Add(GenerateTypePart(viewModel)); - - ////todo: apply the changes along the lines of but definately not resembling - //// for now this _might_ just get a little messy -> - //_contentDefinitionService.AlterTypeDefinition( - // new ContentTypeDefinition( - // viewModel.Name, - // viewModel.DisplayName, - // contentTypeDefinitionParts, - // viewModel.Settings - // ) - // ); - return RedirectToAction("Index"); } - private static ContentTypeDefinition.Part GenerateTypePart(EditTypePartViewModel viewModel) { - return new ContentTypeDefinition.Part( - new ContentPartDefinition( - viewModel.PartDefinition.Name, - viewModel.PartDefinition.Fields.Select( - f => new ContentPartDefinition.Field( - new ContentFieldDefinition(f.FieldDefinition.Name), - f.Name, - f.Settings - ) - ), - viewModel.PartDefinition.Settings - ), - viewModel.Settings - ); - } - - private static ContentTypeDefinition.Part GenerateTypePart(EditTypeViewModel viewModel) { - return new ContentTypeDefinition.Part( - new ContentPartDefinition( - viewModel.Name, - viewModel.Fields.Select( - f => new ContentPartDefinition.Field( - new ContentFieldDefinition(f.FieldDefinition.Name), - f.Name, - f.Settings - ) - ), - null - ), - null - ); - } #endregion #region Parts @@ -226,28 +137,33 @@ namespace Orchard.ContentTypes.Controllers { if (contentPartDefinition == null) return new NotFoundResult(); - return View(new EditPartViewModel(contentPartDefinition)); + var viewModel = new EditPartViewModel(contentPartDefinition) { + Templates = _extendViewModels.PartEditor(contentPartDefinition) + }; + + return View(viewModel); } [HttpPost, ActionName("EditPart")] - public ActionResult EditPartPOST(string id) { + public ActionResult EditPartPOST(EditPartViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a part."))) return new HttpUnauthorizedResult(); - var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); + var contentPartDefinition = _contentDefinitionService.GetPartDefinition(viewModel.Name); if (contentPartDefinition == null) return new NotFoundResult(); - var viewModel = new EditPartViewModel(); - TryUpdateModel(viewModel); + var updater = new Updater(this); + _contentDefinitionManager.AlterPartDefinition(viewModel.Name, partBuilder => { + // allow extensions to alter part configuration + viewModel.Templates = _extendViewModels.PartEditorUpdate(partBuilder, updater); + }); - if (!ModelState.IsValid) - return EditPart(id); - - //todo: apply the changes along the lines of but definately not resembling - // for now this _might_ just get a little messy -> - _contentDefinitionService.AlterPartDefinition(GeneratePart(viewModel)); + if (!ModelState.IsValid) { + Services.TransactionManager.Cancel(); + return View(viewModel); + } return RedirectToAction("Index"); } @@ -319,21 +235,25 @@ namespace Orchard.ContentTypes.Controllers { return RedirectToAction("EditPart", new { id }); } - private static ContentPartDefinition GeneratePart(EditPartViewModel viewModel) { - return new ContentPartDefinition( - viewModel.Name, - viewModel.Fields.Select( - f => new ContentPartDefinition.Field( - new ContentFieldDefinition(f.FieldDefinition.Name), - f.Name, - f.Settings - ) - ), - viewModel.Settings - ); - } - #endregion + class Updater : IUpdateModel { + private readonly AdminController _thunk; + + public Updater(AdminController thunk) { + _thunk = thunk; + } + + public Func _prefix = x => x; + + public bool TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class { + return _thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties); + } + + public void AddModelError(string key, LocalizedString errorMessage) { + _thunk.ModelState.AddModelError(_prefix(key), errorMessage.ToString()); + } + } + } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs index 5b1eb378f..fa33692d8 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs @@ -31,23 +31,21 @@ namespace Orchard.ContentTypes.Services { return _contentDefinitionManager.GetTypeDefinition(name); } - public void AddTypeDefinition(ContentTypeDefinition contentTypeDefinition) { - var typeName = string.IsNullOrWhiteSpace(contentTypeDefinition.Name) - ? GenerateTypeName(contentTypeDefinition.DisplayName) - : contentTypeDefinition.Name; + public void AddTypeDefinition(string displayName) { + var name = GenerateTypeName(displayName); - while (_contentDefinitionManager.GetTypeDefinition(typeName) != null) - typeName = VersionTypeName(typeName); + while (_contentDefinitionManager.GetTypeDefinition(name) != null) + name = VersionTypeName(name); //just giving the new type some default parts for now + _contentDefinitionManager.StoreTypeDefinition(new ContentTypeDefinition(name) {DisplayName = displayName}); _contentDefinitionManager.AlterTypeDefinition( - typeName, - cfg => cfg.DisplayedAs(contentTypeDefinition.DisplayName) - .WithPart("CommonAspect") + name, + cfg => cfg.WithPart("CommonAspect") //.WithPart("RoutableAspect") //need to go the new routable route .WithPart("BodyAspect")); - Services.Notifier.Information(T("Created content type: {0}", contentTypeDefinition.DisplayName)); + Services.Notifier.Information(T("Created content type: {0}", displayName)); } public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) { diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs index 575c8fd4e..4f4da54ec 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs @@ -6,7 +6,7 @@ namespace Orchard.ContentTypes.Services { public interface IContentDefinitionService : IDependency { IEnumerable GetTypeDefinitions(); ContentTypeDefinition GetTypeDefinition(string name); - void AddTypeDefinition(ContentTypeDefinition contentTypeDefinition); + void AddTypeDefinition(string displayName); void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition); void RemoveTypeDefinition(string name); diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs index 89203c4aa..f3f4d9e86 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs @@ -66,6 +66,7 @@ namespace Orchard.ContentTypes.ViewModels { } public string Name { get; set; } + public IEnumerable Templates { get; set; } public IEnumerable Fields { get; set; } public SettingsDictionary Settings { get; set; } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx index 34901350b..c79f8fc14 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/EditPart.ascx @@ -9,7 +9,7 @@ using (Html.BeginFormAntiForgeryPost()) { %> <%--// has unintended consequences (renamging the part) - changing the name creates a new part of that name--%> <%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium"}) %> - <%:Html.EditorFor(m => m.Settings, "Settings", "") %> + <% Html.RenderTemplates(Model.Templates); %>

<%:T("Fields") %>

<%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %>
<%:Html.EditorFor(m => m.Fields, "Fields", "") %> diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index 01d642d17..e95419513 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -5,6 +5,7 @@ using Orchard.Comments.Models; using Orchard.ContentManagement; using Orchard.ContentManagement.MetaData; using Orchard.Core.Common.Models; +using Orchard.Core.Common.Settings; using Orchard.Core.Navigation.Models; using Orchard.Core.Settings.Models; using Orchard.Data; @@ -150,6 +151,7 @@ namespace Orchard.Setup.Services { contentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg.DisplayedAs("Blog Post").WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); contentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.DisplayedAs("Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); contentDefinitionManager.AlterTypeDefinition("SandboxPage", cfg => cfg.DisplayedAs("Sandbox Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); + contentDefinitionManager.AlterPartDefinition("BodyAspect", cfg => cfg.WithSetting("BodyPartSettings.FlavorDefault", BodyPartSettings.FlavorDefaultDefault)); // create home page as a CMS page var page = contentManager.Create("Page", VersionOptions.Draft); diff --git a/src/Orchard/ContentManagement/ContentPart.cs b/src/Orchard/ContentManagement/ContentPart.cs index 47e3d903c..76f90f8eb 100644 --- a/src/Orchard/ContentManagement/ContentPart.cs +++ b/src/Orchard/ContentManagement/ContentPart.cs @@ -16,6 +16,7 @@ namespace Orchard.ContentManagement { public ContentTypeDefinition TypeDefinition { get { return ContentItem.TypeDefinition; } } public ContentTypeDefinition.Part TypePartDefinition { get; set; } public ContentPartDefinition PartDefinition { get { return TypePartDefinition.PartDefinition; } } + public SettingsDictionary Settings { get { return TypePartDefinition.Settings; } } public IEnumerable Fields { get { return _fields; } } diff --git a/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs b/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs index 2b7a0ad73..98f8e71cf 100644 --- a/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs +++ b/src/Orchard/ContentManagement/MetaData/Builders/ContentPartDefinitionBuilder.cs @@ -25,6 +25,8 @@ namespace Orchard.ContentManagement.MetaData.Builders { } } + public string Name { get { return _name; } } + public ContentPartDefinition Build() { return new ContentPartDefinition(_name, _fields, _settings); } diff --git a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs index fdcd05a87..7c25981d4 100644 --- a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs +++ b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs @@ -9,9 +9,11 @@ namespace Orchard.ContentManagement.MetaData { public interface IContentDefinitionEditorEvents : IEventHandler { IEnumerable TypeEditor(ContentTypeDefinition definition); IEnumerable TypePartEditor(ContentTypeDefinition.Part definition); + IEnumerable PartEditor(ContentPartDefinition definition); IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel); IEnumerable TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel); + IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel); } public abstract class ContentDefinitionEditorEventsBase : IContentDefinitionEditorEvents { @@ -23,6 +25,10 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } + public virtual IEnumerable PartEditor(ContentPartDefinition definition) { + return Enumerable.Empty(); + } + public virtual IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { return Enumerable.Empty(); } @@ -31,6 +37,10 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } + public virtual IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + return Enumerable.Empty(); + } + protected static TemplateViewModel DefinitionTemplate(TModel model) { return new TemplateViewModel(model, typeof(TModel).Name) { TemplateName = "DefinitionTemplates/" + typeof(TModel).Name From cce58c6a11153cfa9d3f337ad1fc48997118972b Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Tue, 29 Jun 2010 16:00:01 -0700 Subject: [PATCH 07/19] Getting field setting editors displayed in the content type editor (still need to hook up update...and refactor relevant actions) --HG-- branch : dev --- .../Controllers/AdminController.cs | 28 ++++++++++++++++++- .../ViewModels/EditTypeViewModel.cs | 1 + .../Views/EditorTemplates/Field.ascx | 2 +- .../Orchard.Indexing/Orchard.Indexing.csproj | 2 ++ .../Settings/IndexingSettings.cs | 26 +++++++++++++++++ .../DefinitionTemplates/IndexingSettings.ascx | 7 +++++ .../IContentDefinitionEditorEvents.cs | 10 +++++++ 7 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Indexing/Views/DefinitionTemplates/IndexingSettings.ascx diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 88c6810cb..308c2a4c9 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -78,9 +78,35 @@ namespace Orchard.ContentTypes.Controllers { m => m.PartDefinition.Name, d => d.PartDefinition.Name, (model, definition) => new {model, definition}); - foreach (var entry in entries) + foreach (var entry in entries) { entry.model.Templates = _extendViewModels.TypePartEditor(entry.definition); + var fields = entry.model.PartDefinition.Fields.Join(entry.definition.PartDefinition.Fields, + m => m.FieldDefinition.Name, + d => d.FieldDefinition.Name, + (model, definition) => new { model, definition }); + + foreach (var field in fields) { + field.model.Templates = _extendViewModels.PartFieldEditor(field.definition); + } + } + + + //Oy, this action is getting massive :( + //todo: put this action on a diet + var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id); + if (contentPartDefinition != null) { + viewModel.Fields = viewModel.Fields.ToArray(); + var fields = viewModel.Fields.Join(contentPartDefinition.Fields, + m => m.FieldDefinition.Name, + d => d.FieldDefinition.Name, + (model, definition) => new { model, definition }); + + foreach (var field in fields) { + field.model.Templates = _extendViewModels.PartFieldEditor(field.definition); + } + } + return View(viewModel); } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs index f3f4d9e86..f912eb7f1 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs @@ -82,6 +82,7 @@ namespace Orchard.ContentTypes.ViewModels { } public string Name { get; set; } + public IEnumerable Templates { get; set; } public EditFieldViewModel FieldDefinition { get; set; } public SettingsDictionary Settings { get; set; } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx index fba1ccaf2..af061a2a1 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx @@ -10,7 +10,7 @@ <% } %> --%> - <%:Html.EditorFor(m => m.Settings, "Settings", "") %> + <% Html.RenderTemplates(Model.Templates); %> <%:Html.HiddenFor(m => m.Name) %> <%:Html.HiddenFor(m => m.FieldDefinition.Name) %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj b/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj index 179e2bb84..85e922562 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj @@ -56,6 +56,7 @@ + @@ -77,6 +78,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs new file mode 100644 index 000000000..1a1146b5b --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using Orchard.ContentManagement; +using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData.Builders; +using Orchard.ContentManagement.MetaData.Models; +using Orchard.ContentManagement.ViewModels; + +namespace Orchard.Indexing.Settings { + public class IndexingSettings { + public bool IncludeInIndex { get; set; } + } + + public class IndexingSettingsHooks : ContentDefinitionEditorEventsBase { + public override IEnumerable PartFieldEditor(ContentPartDefinition.Field definition) { + var model = definition.Settings.GetModel(); + yield return DefinitionTemplate(model); + } + + public override IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + var model = new IndexingSettings(); + updateModel.TryUpdateModel(model, "IndexingSettings", null, null); + builder.WithSetting("IndexingSettings.IncludeInIndex", model.IncludeInIndex ? true.ToString() : null); + yield return DefinitionTemplate(model); + } + } +} diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Views/DefinitionTemplates/IndexingSettings.ascx b/src/Orchard.Web/Modules/Orchard.Indexing/Views/DefinitionTemplates/IndexingSettings.ascx new file mode 100644 index 000000000..b68c8f08c --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Views/DefinitionTemplates/IndexingSettings.ascx @@ -0,0 +1,7 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Mvc.Html" %> +
+ <%:Html.EditorFor(m=>m.IncludeInIndex) %> + + <%:Html.ValidationMessageFor(m => m.IncludeInIndex)%> +
diff --git a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs index 7c25981d4..f7e5cac93 100644 --- a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs +++ b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs @@ -10,10 +10,12 @@ namespace Orchard.ContentManagement.MetaData { IEnumerable TypeEditor(ContentTypeDefinition definition); IEnumerable TypePartEditor(ContentTypeDefinition.Part definition); IEnumerable PartEditor(ContentPartDefinition definition); + IEnumerable PartFieldEditor(ContentPartDefinition.Field definition); IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel); IEnumerable TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel); IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel); + IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel); } public abstract class ContentDefinitionEditorEventsBase : IContentDefinitionEditorEvents { @@ -29,6 +31,10 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } + public virtual IEnumerable PartFieldEditor(ContentPartDefinition.Field definition) { + return Enumerable.Empty(); + } + public virtual IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel) { return Enumerable.Empty(); } @@ -41,6 +47,10 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } + public virtual IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + return Enumerable.Empty(); + } + protected static TemplateViewModel DefinitionTemplate(TModel model) { return new TemplateViewModel(model, typeof(TModel).Name) { TemplateName = "DefinitionTemplates/" + typeof(TModel).Name From d91e488cb7bd4a70503113cddf1705a04c0d52f3 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 29 Jun 2010 16:17:08 -0700 Subject: [PATCH 08/19] Use DataMigration API to create database tables for each feature --HG-- branch : dev --- .../DataMigration/DataMigrationTests.cs | 54 ++++++++-------- .../DataMigration/SchemaBuilderTests.cs | 4 +- .../Utilities/NullInterpreter.cs | 6 +- .../DataMigrations/CommonDataMigration.cs | 47 ++++++++++++++ .../LocalizationDataMigration.cs | 17 +++++ .../DataMigrations/NavigationDataMigration.cs | 24 +++++++ src/Orchard.Web/Core/Orchard.Core.csproj | 4 ++ .../DataMigrations/SchedulingDataMigration.cs | 19 ++++++ .../DataMigrations/SettingsDataMigration.cs | 40 +++++++----- .../DataMigrations/WidgetsDataMigration.cs | 23 +++++++ .../Futures.Widgets/Futures.Widgets.csproj | 1 + .../DataMigrations/BlogsDataMigration.cs | 26 ++++++++ .../Orchard.Blogs/Orchard.Blogs.csproj | 1 + .../DataMigrations/CommentsDataMigration.cs | 47 ++++++++++++++ .../Orchard.Comments/Orchard.Comments.csproj | 1 + .../DataMigrations/IndexingDataMigration.cs | 19 ++++++ .../Orchard.Indexing/Orchard.Indexing.csproj | 1 + .../DataMigrations/MediaDataMigration.cs | 16 +++++ .../Orchard.Media/Orchard.Media.csproj | 1 + .../DataMigrations/RolesDataMigration.cs | 39 ++++++++++++ .../Orchard.Roles/Orchard.Roles.csproj | 1 + .../DataMigrations/SandBoxDataMigration.cs | 20 ++++++ .../Orchard.Sandbox/Orchard.Sandbox.csproj | 1 + .../DataMigrations/SearchDataMigration.cs | 17 +++++ .../Orchard.Search/Orchard.Search.csproj | 1 + .../Orchard.Setup/Services/SetupService.cs | 7 ++- .../Modules/Orchard.Setup/SetupMode.cs | 4 +- .../DataMigrations/TagsDataMigration.cs | 23 +++++++ .../Modules/Orchard.Tags/Orchard.Tags.csproj | 1 + .../DataMigrations/ThemesDataMigration.cs | 28 +++++++++ .../Orchard.Themes/Orchard.Themes.csproj | 1 + .../DataMigrations/UsersDataMigration.cs | 22 +++++++ .../Orchard.Users/Orchard.Users.csproj | 1 + .../DataMigrations/FrameworkDataMigration.cs | 41 ++++++++++++ .../Records/ContentItemVersionRecord.cs | 2 - .../Commands/DataMigrationCommands.cs | 2 +- .../Migration}/DataMigration.cs | 8 ++- .../Migration}/DataMigrationCoordinator.cs | 2 +- .../Migration}/DataMigrationManager.cs | 19 +++--- .../DefaultDataMigrationGenerator.cs | 4 +- src/Orchard/Data/Migration/IDataMigration.cs | 7 +++ .../Migration}/IDataMigrationGenerator.cs | 4 +- .../Migration}/IDataMigrationManager.cs | 2 +- .../DefaultDataMigrationInterpreter.cs | 5 +- .../Interpreters/ICommandInterpreter.cs | 4 +- .../Interpreters/IDataMigrationInterpreter.cs | 4 +- .../Interpreters/SqLiteCommandInterpreter.cs | 12 ++-- .../Migration/Records}/DataMigrationRecord.cs | 2 +- .../Migration}/Schema/AddColumnCommand.cs | 2 +- .../Migration}/Schema/AddIndexCommand.cs | 2 +- .../Migration}/Schema/AlterColumnCommand.cs | 2 +- .../Migration}/Schema/AlterTableCommand.cs | 2 +- .../Migration}/Schema/ColumnCommand.cs | 2 +- .../Migration}/Schema/CreateColumnCommand.cs | 2 +- .../Schema/CreateForeignKeyCommand.cs | 2 +- .../Migration}/Schema/CreateTableCommand.cs | 10 ++- .../Migration}/Schema/DropColumnCommand.cs | 2 +- .../Schema/DropForeignKeyCommand.cs | 2 +- .../Migration}/Schema/DropIndexCommand.cs | 2 +- .../Migration}/Schema/DropTableCommand.cs | 2 +- .../Schema/ISchemaBuilderCommand.cs | 2 +- .../Migration}/Schema/IShellSettings.cs | 0 .../Migration}/Schema/SchemaBuilder.cs | 27 ++++---- .../Migration}/Schema/SchemaCommand.cs | 2 +- .../Migration}/Schema/SqlStatementCommand.cs | 2 +- .../Migration}/Schema/TableCommand.cs | 2 +- src/Orchard/DataMigration/IDataMigration.cs | 5 -- src/Orchard/Orchard.Framework.csproj | 63 ++++++++++--------- 68 files changed, 612 insertions(+), 158 deletions(-) create mode 100644 src/Orchard.Web/Core/Common/DataMigrations/CommonDataMigration.cs create mode 100644 src/Orchard.Web/Core/Localization/DataMigrations/LocalizationDataMigration.cs create mode 100644 src/Orchard.Web/Core/Navigation/DataMigrations/NavigationDataMigration.cs create mode 100644 src/Orchard.Web/Core/Scheduling/DataMigrations/SchedulingDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Futures.Widgets/DataMigrations/WidgetsDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/DataMigrations/BlogsDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Comments/DataMigrations/CommentsDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Indexing/DataMigrations/IndexingDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Media/DataMigrations/MediaDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Roles/DataMigrations/RolesDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Sandbox/DataMigrations/SandBoxDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Search/DataMigrations/SearchDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Tags/DataMigrations/TagsDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Themes/DataMigrations/ThemesDataMigration.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Users/DataMigrations/UsersDataMigration.cs create mode 100644 src/Orchard/ContentManagement/DataMigrations/FrameworkDataMigration.cs rename src/Orchard/{DataMigration => Data/Migration}/Commands/DataMigrationCommands.cs (93%) rename src/Orchard/{DataMigration => Data/Migration}/DataMigration.cs (62%) rename src/Orchard/{DataMigration => Data/Migration}/DataMigrationCoordinator.cs (95%) rename src/Orchard/{DataMigration => Data/Migration}/DataMigrationManager.cs (92%) rename src/Orchard/{DataMigration => Data/Migration}/DefaultDataMigrationGenerator.cs (81%) create mode 100644 src/Orchard/Data/Migration/IDataMigration.cs rename src/Orchard/{DataMigration => Data/Migration}/IDataMigrationGenerator.cs (80%) rename src/Orchard/{DataMigration => Data/Migration}/IDataMigrationManager.cs (94%) rename src/Orchard/{DataMigration => Data/Migration}/Interpreters/DefaultDataMigrationInterpreter.cs (96%) rename src/Orchard/{DataMigration => Data/Migration}/Interpreters/ICommandInterpreter.cs (78%) rename src/Orchard/{DataMigration => Data/Migration}/Interpreters/IDataMigrationInterpreter.cs (80%) rename src/Orchard/{DataMigration => Data/Migration}/Interpreters/SqLiteCommandInterpreter.cs (80%) rename src/Orchard/{DataMigration => Data/Migration/Records}/DataMigrationRecord.cs (79%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/AddColumnCommand.cs (76%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/AddIndexCommand.cs (86%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/AlterColumnCommand.cs (91%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/AlterTableCommand.cs (94%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/ColumnCommand.cs (92%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/CreateColumnCommand.cs (94%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/CreateForeignKeyCommand.cs (90%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/CreateTableCommand.cs (81%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/DropColumnCommand.cs (77%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/DropForeignKeyCommand.cs (84%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/DropIndexCommand.cs (82%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/DropTableCommand.cs (76%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/ISchemaBuilderCommand.cs (51%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/IShellSettings.cs (100%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/SchemaBuilder.cs (62%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/SchemaCommand.cs (91%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/SqlStatementCommand.cs (90%) rename src/Orchard/{DataMigration => Data/Migration}/Schema/TableCommand.cs (79%) delete mode 100644 src/Orchard/DataMigration/IDataMigration.cs diff --git a/src/Orchard.Tests/DataMigration/DataMigrationTests.cs b/src/Orchard.Tests/DataMigration/DataMigrationTests.cs index f1d88760e..bc3c89cc2 100644 --- a/src/Orchard.Tests/DataMigration/DataMigrationTests.cs +++ b/src/Orchard.Tests/DataMigration/DataMigrationTests.cs @@ -7,13 +7,15 @@ using NHibernate; using NUnit.Framework; using Orchard.ContentManagement.Records; using Orchard.Data; -using Orchard.DataMigration.Interpreters; +using Orchard.Data.Migration; +using Orchard.Data.Migration.Interpreters; +using Orchard.Data.Migration.Records; using Orchard.Environment.Configuration; using Orchard.Environment.Extensions; using Orchard.Environment.Extensions.Folders; using Orchard.Environment.Extensions.Models; using Orchard.Tests.ContentManagement; -using Orchard.DataMigration; +using Orchard.Data.Migration; using Orchard.Data.Providers; namespace Orchard.Tests.DataMigration { @@ -90,20 +92,20 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationEmpty : IDataMigration { - public string Feature { - get { return "Feature1"; } + public Feature Feature { + get { return new Feature() {Descriptor = new FeatureDescriptor() {Name = "Feature1"}}; } } } public class DataMigration11 : IDataMigration { - public string Feature { - get { return "Feature1"; } + public Feature Feature { + get { return new Feature() {Descriptor = new FeatureDescriptor() {Name = "Feature1"}}; } } } public class DataMigration11Create : IDataMigration { - public string Feature { - get { return "Feature1"; } + public Feature Feature { + get { return new Feature() {Descriptor = new FeatureDescriptor() {Name = "Feature1"}}; } } public int Create() { @@ -112,8 +114,8 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationCreateCanBeFollowedByUpdates : IDataMigration { - public string Feature { - get { return "Feature1"; } + public Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature1" } }; } } public int Create() { @@ -126,8 +128,8 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationSameMigrationClassCanEvolve : IDataMigration { - public string Feature { - get { return "Feature1"; } + public Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature1" } }; } } public int Create() { @@ -144,8 +146,8 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationDependenciesModule1 : IDataMigration { - public string Feature { - get { return "Feature1"; } + public Feature Feature { + get { return new Feature() {Descriptor = new FeatureDescriptor() {Name = "Feature1"}}; } } public int Create() { @@ -154,8 +156,8 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationDependenciesModule2 : IDataMigration { - public string Feature { - get { return "Feature2"; } + public Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature2" } }; } } public int Create() { @@ -164,8 +166,8 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationWithSchemaBuilder : DataMigrationImpl { - public override string Feature { - get { return "Feature1"; } + public override Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature1" } }; } } public int Create() { @@ -175,14 +177,14 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationFeatureNeedUpdate1 : IDataMigration { - public string Feature { - get { return "Feature1"; } + public Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature1" } }; } } } public class DataMigrationFeatureNeedUpdate2 : IDataMigration { - public string Feature { - get { return "Feature2"; } + public Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature2" } }; } } public int Create() { @@ -191,8 +193,8 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationFeatureNeedUpdate3 : IDataMigration { - public string Feature { - get { return "Feature3"; } + public Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature3" } }; } } public int Create() { @@ -205,8 +207,8 @@ namespace Orchard.Tests.DataMigration { } public class DataMigrationSimpleBuilder : DataMigrationImpl { - public override string Feature { - get { return "Feature1"; } + public override Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature1" } }; } } public int Create() { diff --git a/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs b/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs index 3d734edba..2053bffc1 100644 --- a/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs +++ b/src/Orchard.Tests/DataMigration/SchemaBuilderTests.cs @@ -4,8 +4,8 @@ using Autofac; using NHibernate; using NUnit.Framework; using Orchard.Data; -using Orchard.DataMigration.Interpreters; -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Interpreters; +using Orchard.Data.Migration.Schema; using Orchard.Environment.Configuration; using Orchard.Tests.ContentManagement; using System.IO; diff --git a/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs b/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs index 9887aa4fc..6e87a8f40 100644 --- a/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs +++ b/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs @@ -1,7 +1,5 @@ - -using System; -using Orchard.DataMigration.Interpreters; -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Interpreters; +using Orchard.Data.Migration.Schema; public class NullInterpreter : IDataMigrationInterpreter { diff --git a/src/Orchard.Web/Core/Common/DataMigrations/CommonDataMigration.cs b/src/Orchard.Web/Core/Common/DataMigrations/CommonDataMigration.cs new file mode 100644 index 000000000..f1fa72627 --- /dev/null +++ b/src/Orchard.Web/Core/Common/DataMigrations/CommonDataMigration.cs @@ -0,0 +1,47 @@ +using System; +using Orchard.Data.Migration; + +namespace Orchard.Core.Common.DataMigrations { + public class CommonDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Common_BodyRecord (Id INTEGER not null, Text TEXT, Format TEXT, ContentItemRecord_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("BodyRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Text") + .Column("Format") + .Column("ContentItemRecord_id") + ); + + //CREATE TABLE Common_CommonRecord (Id INTEGER not null, OwnerId INTEGER, CreatedUtc DATETIME, PublishedUtc DATETIME, ModifiedUtc DATETIME, Container_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("CommonRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("OwnerId") + .Column("CreatedUtc") + .Column("PublishedUtc") + .Column("ModifiedUtc") + .Column("Container_id") + ); + + //CREATE TABLE Common_CommonVersionRecord (Id INTEGER not null, CreatedUtc DATETIME, PublishedUtc DATETIME, ModifiedUtc DATETIME, ContentItemRecord_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("CommonVersionRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("CreatedUtc") + .Column("PublishedUtc") + .Column("ModifiedUtc") + .Column("ContentItemRecord_id") + ); + + //CREATE TABLE Common_RoutableRecord (Id INTEGER not null, Title TEXT, Slug TEXT, Path TEXT, ContentItemRecord_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("RoutableRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Title") + .Column("Slug") + .Column("Path") + .Column("ContentItemRecord_id") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Localization/DataMigrations/LocalizationDataMigration.cs b/src/Orchard.Web/Core/Localization/DataMigrations/LocalizationDataMigration.cs new file mode 100644 index 000000000..1eed07b70 --- /dev/null +++ b/src/Orchard.Web/Core/Localization/DataMigrations/LocalizationDataMigration.cs @@ -0,0 +1,17 @@ +using Orchard.Data.Migration; + +namespace Orchard.Core.Localization.DataMigrations { + public class LocalizationDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Localization_LocalizedRecord (Id INTEGER not null, CultureId INTEGER, MasterContentItemId INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("LocalizedRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("CultureId") + .Column("MasterContentItemId") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Navigation/DataMigrations/NavigationDataMigration.cs b/src/Orchard.Web/Core/Navigation/DataMigrations/NavigationDataMigration.cs new file mode 100644 index 000000000..2910c823b --- /dev/null +++ b/src/Orchard.Web/Core/Navigation/DataMigrations/NavigationDataMigration.cs @@ -0,0 +1,24 @@ +using Orchard.Data.Migration; + +namespace Orchard.Core.Navigation.DataMigrations { + public class NavigationDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Navigation_MenuItemRecord (Id INTEGER not null, Url TEXT, primary key (Id)); + SchemaBuilder.CreateTable("MenuItemRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Url") + ); + + //CREATE TABLE Navigation_MenuPartRecord (Id INTEGER not null, MenuText TEXT, MenuPosition TEXT, OnMainMenu INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("MenuPartRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("MenuText") + .Column("MenuPosition") + .Column("OnMainMenu") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index a70ca21c0..0a234eab9 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -61,6 +61,7 @@
+ @@ -76,7 +77,9 @@ + + @@ -153,6 +156,7 @@ + diff --git a/src/Orchard.Web/Core/Scheduling/DataMigrations/SchedulingDataMigration.cs b/src/Orchard.Web/Core/Scheduling/DataMigrations/SchedulingDataMigration.cs new file mode 100644 index 000000000..2cea744d1 --- /dev/null +++ b/src/Orchard.Web/Core/Scheduling/DataMigrations/SchedulingDataMigration.cs @@ -0,0 +1,19 @@ +using System; +using Orchard.Data.Migration; + +namespace Orchard.Core.Scheduling.DataMigrations { + public class SchedulingDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Scheduling_ScheduledTaskRecord (Id integer, TaskType TEXT, ScheduledUtc DATETIME, ContentItemVersionRecord_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("ScheduledTaskRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("TaskType") + .Column("ScheduledUtc") + .Column("ContentItemVersionRecord_id") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Settings/DataMigrations/SettingsDataMigration.cs b/src/Orchard.Web/Core/Settings/DataMigrations/SettingsDataMigration.cs index eba65db7c..2116c1ca8 100644 --- a/src/Orchard.Web/Core/Settings/DataMigrations/SettingsDataMigration.cs +++ b/src/Orchard.Web/Core/Settings/DataMigrations/SettingsDataMigration.cs @@ -1,28 +1,25 @@ -using Orchard.DataMigration; +using Orchard.Data.Migration; namespace Orchard.Core.Settings.DataMigrations { public class SettingsDataMigration : DataMigrationImpl { - public override string Feature { - get { return "Settings"; } - } public int Create() { //CREATE TABLE Settings_ContentFieldDefinitionRecord (Id integer, Name TEXT, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ContentFieldDefinitionRecord", table => table + SchemaBuilder.CreateTable("ContentFieldDefinitionRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Name") ); //CREATE TABLE Settings_ContentPartDefinitionRecord (Id integer, Name TEXT, Hidden INTEGER, Settings TEXT, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ContentPartDefinitionRecord", table => table + SchemaBuilder.CreateTable("ContentPartDefinitionRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Name") - .Column("Hidden") + .Column("Hidden") .Column("Settings") ); //CREATE TABLE Settings_ContentPartFieldDefinitionRecord (Id integer, Name TEXT, Settings TEXT, ContentFieldDefinitionRecord_id INTEGER, INTEGER, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ContentPartFieldDefinitionRecord", table => table + SchemaBuilder.CreateTable("ContentPartFieldDefinitionRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Name") .Column("Settings") @@ -31,16 +28,16 @@ namespace Orchard.Core.Settings.DataMigrations { ); //CREATE TABLE Settings_ContentTypeDefinitionRecord (Id integer, Name TEXT, DisplayName TEXT, Hidden INTEGER, Settings TEXT, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ContentTypeDefinitionRecord", table => table + SchemaBuilder.CreateTable("ContentTypeDefinitionRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Name") .Column("DisplayName") - .Column("Hidden") + .Column("Hidden") .Column("Settings") ); //CREATE TABLE Settings_ContentTypePartDefinitionRecord (Id integer, Settings TEXT, ContentPartDefinitionRecord_id INTEGER, ContentTypeDefinitionRecord_Id INTEGER, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ContentTypePartDefinitionRecord", table => table + SchemaBuilder.CreateTable("ContentTypePartDefinitionRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Settings") .Column("ContentPartDefinitionRecord_id") @@ -48,19 +45,19 @@ namespace Orchard.Core.Settings.DataMigrations { ); //CREATE TABLE Settings_ShellDescriptorRecord (Id integer, SerialNumber INTEGER, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ShellDescriptorRecord", table => table + SchemaBuilder.CreateTable("ShellDescriptorRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("SerialNumber") ); //CREATE TABLE Settings_ShellFeatureRecord (Id integer, Name TEXT, ShellDescriptorRecord_id INTEGER, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ShellFeatureRecord", table => table + SchemaBuilder.CreateTable("ShellFeatureRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Name") .Column("ShellDescriptorRecord_id")); //CREATE TABLE Settings_ShellFeatureStateRecord (Id integer, Name TEXT, InstallState TEXT, EnableState TEXT, ShellStateRecord_Id INTEGER, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ShellFeatureStateRecord", table => table + SchemaBuilder.CreateTable("ShellFeatureStateRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Name") .Column("InstallState") @@ -69,7 +66,7 @@ namespace Orchard.Core.Settings.DataMigrations { ); //CREATE TABLE Settings_ShellParameterRecord (Id integer, Component TEXT, Name TEXT, Value TEXT, ShellDescriptorRecord_id INTEGER, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ShellParameterRecord", table => table + SchemaBuilder.CreateTable("ShellParameterRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Component") .Column("Name") @@ -78,11 +75,22 @@ namespace Orchard.Core.Settings.DataMigrations { ); //CREATE TABLE Settings_ShellStateRecord (Id integer, primary key (Id)); - SchemaBuilder.CreateTable("Settings_ShellStateRecord", table => table + SchemaBuilder.CreateTable("ShellStateRecord", table => table .Column("Id", column => column.PrimaryKey()) .Column("Name") ); + //CREATE TABLE Settings_SiteSettingsRecord (Id INTEGER not null, SiteSalt TEXT, SiteName TEXT, SuperUser TEXT, PageTitleSeparator TEXT, HomePage TEXT, SiteCulture TEXT, primary key (Id)); + SchemaBuilder.CreateTable("SiteSettingsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("SiteSalt") + .Column("SiteName") + .Column("SuperUser") + .Column("PageTitleSeparator") + .Column("HomePage") + .Column("SiteCulture") + ); + return 0010; } } diff --git a/src/Orchard.Web/Modules/Futures.Widgets/DataMigrations/WidgetsDataMigration.cs b/src/Orchard.Web/Modules/Futures.Widgets/DataMigrations/WidgetsDataMigration.cs new file mode 100644 index 000000000..6e06cd0ae --- /dev/null +++ b/src/Orchard.Web/Modules/Futures.Widgets/DataMigrations/WidgetsDataMigration.cs @@ -0,0 +1,23 @@ +using Orchard.Data.Migration; + +namespace Futures.Widgets.DataMigrations { + public class WidgetsDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Futures_Widgets_HasWidgetsRecord (Id INTEGER not null, primary key (Id)); + SchemaBuilder.CreateTable("HasWidgetsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + ); + + //CREATE TABLE Futures_Widgets_WidgetRecord (Id INTEGER not null, Zone TEXT, Position TEXT, Scope_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("WidgetRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Zone") + .Column("Position") + .Column("Scope_id") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Futures.Widgets/Futures.Widgets.csproj b/src/Orchard.Web/Modules/Futures.Widgets/Futures.Widgets.csproj index b4442b16c..290b659e8 100644 --- a/src/Orchard.Web/Modules/Futures.Widgets/Futures.Widgets.csproj +++ b/src/Orchard.Web/Modules/Futures.Widgets/Futures.Widgets.csproj @@ -59,6 +59,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/DataMigrations/BlogsDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Blogs/DataMigrations/BlogsDataMigration.cs new file mode 100644 index 000000000..8756eb989 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Blogs/DataMigrations/BlogsDataMigration.cs @@ -0,0 +1,26 @@ +using Orchard.Data.Migration; + +namespace Orchard.Blogs.DataMigrations { + public class BlogsDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Orchard_Blogs_BlogArchiveRecord (Id integer, Year INTEGER, Month INTEGER, PostCount INTEGER, Blog_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("BlogArchiveRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Year") + .Column("Month") + .Column("PostCount") + .Column("Blog_id") + ); + + //CREATE TABLE Orchard_Blogs_BlogRecord (Id INTEGER not null, Description TEXT, PostCount INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("BlogRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Description") + .Column("PostCount") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index a27f9f0af..5016b362b 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -68,6 +68,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Comments/DataMigrations/CommentsDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Comments/DataMigrations/CommentsDataMigration.cs new file mode 100644 index 000000000..7b7f1d689 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Comments/DataMigrations/CommentsDataMigration.cs @@ -0,0 +1,47 @@ +using System; +using Orchard.Data.Migration; + +namespace Orchard.Comments.DataMigrations { + public class CommentsDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Orchard_Comments_ClosedCommentsRecord (Id integer, ContentItemId INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("ClosedCommentsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("ContentItemId") + ); + + //CREATE TABLE Orchard_Comments_CommentRecord (Id INTEGER not null, Author TEXT, SiteName TEXT, UserName TEXT, Email TEXT, Status TEXT, CommentDateUtc DATETIME, CommentText TEXT, CommentedOn INTEGER, CommentedOnContainer INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("CommentRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Author") + .Column("SiteName") + .Column("UserName") + .Column("Email") + .Column("Status") + .Column("CommentDateUtc") + .Column("CommentText") + .Column("CommentedOn") + .Column("CommentedOnContainer") + ); + + //CREATE TABLE Orchard_Comments_CommentSettingsRecord (Id INTEGER not null, ModerateComments INTEGER, EnableSpamProtection INTEGER, AkismetKey TEXT, AkismetUrl TEXT, primary key (Id)); + SchemaBuilder.CreateTable("CommentSettingsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("ModerateComments") + .Column("EnableSpamProtection") + .Column("AkismetKey") + .Column("AkismetUrl") + ); + + //CREATE TABLE Orchard_Comments_HasCommentsRecord (Id INTEGER not null, CommentsShown INTEGER, CommentsActive INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("HasCommentsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("CommentsShown") + .Column("CommentsActive") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj b/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj index 391eb11c5..5291a071d 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj +++ b/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj @@ -72,6 +72,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/DataMigrations/IndexingDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Indexing/DataMigrations/IndexingDataMigration.cs new file mode 100644 index 000000000..c1c11bd9d --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Indexing/DataMigrations/IndexingDataMigration.cs @@ -0,0 +1,19 @@ +using System; +using Orchard.Data.Migration; + +namespace Orchard.Indexing.DataMigrations { + public class IndexingDataMigration : DataMigrationImpl { + + public int Create() { + + SchemaBuilder.CreateTable("IndexingTaskRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Action") + .Column("CreatedUtc") + .Column("ContentItemRecord_id") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj b/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj index 179e2bb84..bd3bd046c 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Orchard.Indexing.csproj @@ -62,6 +62,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Media/DataMigrations/MediaDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Media/DataMigrations/MediaDataMigration.cs new file mode 100644 index 000000000..e46870480 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Media/DataMigrations/MediaDataMigration.cs @@ -0,0 +1,16 @@ +using Orchard.Data.Migration; + +namespace Orchard.Media.DataMigrations { + public class MediaDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Orchard_Media_MediaSettingsRecord (Id INTEGER not null, RootMediaFolder TEXT, primary key (Id)); + SchemaBuilder.CreateTable("MediaSettingsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("RootMediaFolder") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Media/Orchard.Media.csproj b/src/Orchard.Web/Modules/Orchard.Media/Orchard.Media.csproj index 88f02adab..778f23a1c 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Orchard.Media.csproj +++ b/src/Orchard.Web/Modules/Orchard.Media/Orchard.Media.csproj @@ -71,6 +71,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Roles/DataMigrations/RolesDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Roles/DataMigrations/RolesDataMigration.cs new file mode 100644 index 000000000..9a676640e --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Roles/DataMigrations/RolesDataMigration.cs @@ -0,0 +1,39 @@ +using Orchard.Data.Migration; + +namespace Orchard.Roles.DataMigrations { + public class RolesDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Orchard_Roles_PermissionRecord (Id integer, Name TEXT, ModuleName TEXT, Description TEXT, primary key (Id)); + SchemaBuilder.CreateTable("PermissionRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + .Column("ModuleName") + .Column("Description") + ); + + //CREATE TABLE Orchard_Roles_RoleRecord (Id integer, Name TEXT, primary key (Id)); + SchemaBuilder.CreateTable("RoleRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + ); + + //CREATE TABLE Orchard_Roles_RolesPermissionsRecord (Id integer, Role_id INTEGER, Permission_id INTEGER, RoleRecord_Id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("RolesPermissionsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Role_id") + .Column("Permission_id") + .Column("RoleRecord_Id") + ); + + //CREATE TABLE Orchard_Roles_UserRolesRecord (Id integer, UserId INTEGER, Role_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("UserRolesRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("UserId") + .Column("Role_id") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Orchard.Roles.csproj b/src/Orchard.Web/Modules/Orchard.Roles/Orchard.Roles.csproj index 671501046..4a61ae7a5 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Orchard.Roles.csproj +++ b/src/Orchard.Web/Modules/Orchard.Roles/Orchard.Roles.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Sandbox/DataMigrations/SandBoxDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Sandbox/DataMigrations/SandBoxDataMigration.cs new file mode 100644 index 000000000..88a9aafce --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Sandbox/DataMigrations/SandBoxDataMigration.cs @@ -0,0 +1,20 @@ +using Orchard.Data.Migration; + +namespace Orchard.Sandbox.DataMigrations { + public class SandboxDataMigration : DataMigrationImpl { + + public int Create() { + SchemaBuilder.CreateTable("SandboxPageRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + ); + + SchemaBuilder.CreateTable("SandboxSettingsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("AllowAnonymousEdits") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Sandbox/Orchard.Sandbox.csproj b/src/Orchard.Web/Modules/Orchard.Sandbox/Orchard.Sandbox.csproj index 54b613b8f..9588858fa 100644 --- a/src/Orchard.Web/Modules/Orchard.Sandbox/Orchard.Sandbox.csproj +++ b/src/Orchard.Web/Modules/Orchard.Sandbox/Orchard.Sandbox.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Search/DataMigrations/SearchDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Search/DataMigrations/SearchDataMigration.cs new file mode 100644 index 000000000..7c53b4e43 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/DataMigrations/SearchDataMigration.cs @@ -0,0 +1,17 @@ +using Orchard.Data.Migration; + +namespace Orchard.Search.DataMigrations { + public class SearchDataMigration : DataMigrationImpl { + + public int Create() { + + SchemaBuilder.CreateTable("SearchSettingsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("FilterCulture") + .Column("SearchedFields") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj b/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj index 725a6ece2..c99916558 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj +++ b/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj @@ -66,6 +66,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index 7e833695f..717003504 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -8,9 +8,9 @@ using Orchard.Core.Common.Models; using Orchard.Core.Navigation.Models; using Orchard.Core.Settings.Models; using Orchard.Data; +using Orchard.Data.Migration.Interpreters; using Orchard.Data.Providers; -using Orchard.DataMigration.Interpreters; -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Schema; using Orchard.Environment; using Orchard.Environment.Configuration; using Orchard.Environment.ShellBuilders; @@ -23,7 +23,7 @@ using Orchard.Settings; using Orchard.Themes; using Orchard.UI.Notify; using Orchard.Environment.State; -using Orchard.DataMigration; +using Orchard.Data.Migration; namespace Orchard.Setup.Services { public class SetupService : ISetupService { @@ -114,6 +114,7 @@ namespace Orchard.Setup.Services { .Column("Current")); var dataMigrationManager = environment.Resolve(); + dataMigrationManager.Update("Orchard.Framework"); dataMigrationManager.Update("Settings"); environment.Resolve().UpdateShellDescriptor( diff --git a/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs b/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs index d0f4ee5aa..0c5deaf63 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs @@ -8,9 +8,9 @@ using Orchard.Commands.Builtin; using Orchard.ContentManagement; using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.MetaData.Builders; +using Orchard.Data.Migration.Interpreters; using Orchard.Data.Providers; -using Orchard.DataMigration; -using Orchard.DataMigration.Interpreters; +using Orchard.Data.Migration; using Orchard.Environment.Extensions; using Orchard.Localization; using Orchard.Mvc; diff --git a/src/Orchard.Web/Modules/Orchard.Tags/DataMigrations/TagsDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Tags/DataMigrations/TagsDataMigration.cs new file mode 100644 index 000000000..a0d1d6c6e --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Tags/DataMigrations/TagsDataMigration.cs @@ -0,0 +1,23 @@ +using Orchard.Data.Migration; + +namespace Orchard.Tags.DataMigrations { + public class TagsDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Orchard_Tags_Tag (Id integer, TagName TEXT, primary key (Id)); + SchemaBuilder.CreateTable("Tag", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("TagName") + ); + + //CREATE TABLE Orchard_Tags_TagsContentItems (Id integer, TagId INTEGER, ContentItemId INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("TagsContentItems", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("TagId") + .Column("ContentItemId") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj b/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj index 2c93a394a..a698e74a8 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj +++ b/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Themes/DataMigrations/ThemesDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Themes/DataMigrations/ThemesDataMigration.cs new file mode 100644 index 000000000..1b79ca51b --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Themes/DataMigrations/ThemesDataMigration.cs @@ -0,0 +1,28 @@ +using Orchard.Data.Migration; + +namespace Orchard.Themes.DataMigrations { + public class ThemesDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Orchard_Themes_ThemeRecord (Id INTEGER not null, ThemeName TEXT, DisplayName TEXT, Description TEXT, Version TEXT, Author TEXT, HomePage TEXT, Tags TEXT, primary key (Id)); + SchemaBuilder.CreateTable("ThemeRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("ThemeName") + .Column("DisplayName") + .Column("Description") + .Column("Version") + .Column("Author") + .Column("HomePage") + .Column("Tags") + ); + + //CREATE TABLE Orchard_Themes_ThemeSiteSettingsRecord (Id INTEGER not null, CurrentThemeName TEXT, primary key (Id)); + SchemaBuilder.CreateTable("ThemeSiteSettingsRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("CurrentThemeName") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj b/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj index 2d78f2c16..dea0eb979 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj +++ b/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Users/DataMigrations/UsersDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Users/DataMigrations/UsersDataMigration.cs new file mode 100644 index 000000000..d6a00bfeb --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Users/DataMigrations/UsersDataMigration.cs @@ -0,0 +1,22 @@ +using Orchard.Data.Migration; +using Orchard.Data.Migration; + +namespace Orchard.Users.DataMigrations { + public class UsersDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Orchard_Users_UserRecord (Id INTEGER not null, UserName TEXT, Email TEXT, NormalizedUserName TEXT, Password TEXT, PasswordFormat TEXT, PasswordSalt TEXT, primary key (Id)); + SchemaBuilder.CreateTable("UserRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("UserName") + .Column("Email") + .Column("NormalizedUserName") + .Column("Password") + .Column("PasswordFormat") + .Column("PasswordSalt") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Users/Orchard.Users.csproj b/src/Orchard.Web/Modules/Orchard.Users/Orchard.Users.csproj index 747a36978..99b6fe9bb 100644 --- a/src/Orchard.Web/Modules/Orchard.Users/Orchard.Users.csproj +++ b/src/Orchard.Web/Modules/Orchard.Users/Orchard.Users.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Orchard/ContentManagement/DataMigrations/FrameworkDataMigration.cs b/src/Orchard/ContentManagement/DataMigrations/FrameworkDataMigration.cs new file mode 100644 index 000000000..3e0ebeabc --- /dev/null +++ b/src/Orchard/ContentManagement/DataMigrations/FrameworkDataMigration.cs @@ -0,0 +1,41 @@ +using Orchard.Data.Migration; +using Orchard.Data.Migration; +using Orchard.Environment.Extensions.Models; + +namespace Orchard.ContentManagement.DataMigrations { + public class FrameworkDataMigration : DataMigrationImpl { + + public int Create() { + //CREATE TABLE Orchard_Framework_ContentItemRecord (Id integer, Data TEXT, ContentType_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("ContentItemRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Data") + .Column("ContentType_id") + ); + + //CREATE TABLE Orchard_Framework_ContentItemVersionRecord (Id integer, Number INTEGER, Published INTEGER, Latest INTEGER, Data TEXT, ContentItemRecord_id INTEGER, primary key (Id)); + SchemaBuilder.CreateTable("ContentItemVersionRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Number") + .Column("Published") + .Column("Latest") + .Column("Data") + .Column("ContentItemRecord_id") + ); + + //CREATE TABLE Orchard_Framework_ContentTypeRecord (Id integer, Name TEXT, primary key (Id)); + SchemaBuilder.CreateTable("ContentTypeRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Name") + ); + + //CREATE TABLE Orchard_Framework_CultureRecord (Id integer, Culture TEXT, primary key (Id)); + SchemaBuilder.CreateTable("CultureRecord", table => table + .Column("Id", column => column.PrimaryKey()) + .Column("Culture") + ); + + return 0010; + } + } +} \ No newline at end of file diff --git a/src/Orchard/ContentManagement/Records/ContentItemVersionRecord.cs b/src/Orchard/ContentManagement/Records/ContentItemVersionRecord.cs index 1eaa00875..9a7b4cf8a 100644 --- a/src/Orchard/ContentManagement/Records/ContentItemVersionRecord.cs +++ b/src/Orchard/ContentManagement/Records/ContentItemVersionRecord.cs @@ -1,5 +1,3 @@ -using System; -using Orchard.ContentManagement.FieldStorage; using Orchard.ContentManagement.FieldStorage.InfosetStorage; namespace Orchard.ContentManagement.Records { diff --git a/src/Orchard/DataMigration/Commands/DataMigrationCommands.cs b/src/Orchard/Data/Migration/Commands/DataMigrationCommands.cs similarity index 93% rename from src/Orchard/DataMigration/Commands/DataMigrationCommands.cs rename to src/Orchard/Data/Migration/Commands/DataMigrationCommands.cs index 2beb4a9d9..745b2fffd 100644 --- a/src/Orchard/DataMigration/Commands/DataMigrationCommands.cs +++ b/src/Orchard/Data/Migration/Commands/DataMigrationCommands.cs @@ -1,7 +1,7 @@ using System; using Orchard.Commands; -namespace Orchard.DataMigration.Commands { +namespace Orchard.Data.Migration.Commands { public class DataMigrationCommands : DefaultOrchardCommandHandler { private readonly IDataMigrationManager _dataMigrationManager; diff --git a/src/Orchard/DataMigration/DataMigration.cs b/src/Orchard/Data/Migration/DataMigration.cs similarity index 62% rename from src/Orchard/DataMigration/DataMigration.cs rename to src/Orchard/Data/Migration/DataMigration.cs index 8ae3769a7..28ddf9713 100644 --- a/src/Orchard/DataMigration/DataMigration.cs +++ b/src/Orchard/Data/Migration/DataMigration.cs @@ -1,11 +1,13 @@ -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Schema; +using Orchard.Environment.Extensions.Models; -namespace Orchard.DataMigration { +namespace Orchard.Data.Migration { /// /// Data Migration classes can inherit from this class to get a SchemaBuilder instance configured with the current tenant database prefix /// public abstract class DataMigrationImpl : IDataMigration { - public abstract string Feature { get; } public SchemaBuilder SchemaBuilder { get; set; } + public virtual Feature Feature { get; set; } + } } diff --git a/src/Orchard/DataMigration/DataMigrationCoordinator.cs b/src/Orchard/Data/Migration/DataMigrationCoordinator.cs similarity index 95% rename from src/Orchard/DataMigration/DataMigrationCoordinator.cs rename to src/Orchard/Data/Migration/DataMigrationCoordinator.cs index 3107ea7f2..bee32f62d 100644 --- a/src/Orchard/DataMigration/DataMigrationCoordinator.cs +++ b/src/Orchard/Data/Migration/DataMigrationCoordinator.cs @@ -1,7 +1,7 @@ using Orchard.Environment; using Orchard.Environment.Extensions.Models; -namespace Orchard.DataMigration { +namespace Orchard.Data.Migration { /// /// Responsible for executing data migration tasks when a feature is enabled for the first time /// 1) Initial install of a module: diff --git a/src/Orchard/DataMigration/DataMigrationManager.cs b/src/Orchard/Data/Migration/DataMigrationManager.cs similarity index 92% rename from src/Orchard/DataMigration/DataMigrationManager.cs rename to src/Orchard/Data/Migration/DataMigrationManager.cs index c2666ac00..6c258680a 100644 --- a/src/Orchard/DataMigration/DataMigrationManager.cs +++ b/src/Orchard/Data/Migration/DataMigrationManager.cs @@ -3,16 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text.RegularExpressions; -using Orchard.Data; -using Orchard.Data.Providers; -using Orchard.DataMigration.Interpreters; -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Interpreters; +using Orchard.Data.Migration.Records; +using Orchard.Data.Migration.Schema; using Orchard.Environment.Extensions; using Orchard.Environment.State; using Orchard.Logging; -using Orchard.Environment.ShellBuilders.Models; -namespace Orchard.DataMigration { +namespace Orchard.Data.Migration { /// /// Reponsible for maintaining the knowledge of data migration in a per tenant table /// @@ -56,7 +54,7 @@ namespace Orchard.DataMigration { // try to resolve a Create method if ( GetCreateMethod(dataMigration) != null ) { - features.Add(dataMigration.Feature); + features.Add(dataMigration.Feature.Descriptor.Name); continue; } } @@ -64,7 +62,7 @@ namespace Orchard.DataMigration { var lookupTable = CreateUpgradeLookupTable(dataMigration); if(lookupTable.ContainsKey(current)) { - features.Add(dataMigration.Feature); + features.Add(dataMigration.Feature.Descriptor.Name); } } @@ -172,7 +170,6 @@ namespace Orchard.DataMigration { } - private DataMigrationRecord GetDataMigrationRecord(IDataMigration tempMigration) { return _dataMigrationRepository.Table .Where(dm => dm.DataMigrationClass == tempMigration.GetType().FullName) @@ -184,11 +181,11 @@ namespace Orchard.DataMigration { /// private IEnumerable GetDataMigrations(string feature) { var migrations = _dataMigrations - .Where(dm => String.Equals(dm.Feature, feature, StringComparison.OrdinalIgnoreCase)) + .Where(dm => String.Equals(dm.Feature.Descriptor.Name, feature, StringComparison.OrdinalIgnoreCase)) .ToList(); foreach (var migration in migrations.OfType()) { - migration.SchemaBuilder = new SchemaBuilder(_interpreter); + migration.SchemaBuilder = new SchemaBuilder(_interpreter, migration.Feature.Descriptor.Name.Replace(".", "_") + "_"); } return migrations; diff --git a/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs b/src/Orchard/Data/Migration/DefaultDataMigrationGenerator.cs similarity index 81% rename from src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs rename to src/Orchard/Data/Migration/DefaultDataMigrationGenerator.cs index f33dc4d40..5aeaea29e 100644 --- a/src/Orchard/DataMigration/DefaultDataMigrationGenerator.cs +++ b/src/Orchard/Data/Migration/DefaultDataMigrationGenerator.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Schema; using Orchard.Environment.ShellBuilders.Models; -namespace Orchard.DataMigration { +namespace Orchard.Data.Migration { public class DefaultDataMigrationGenerator : IDataMigrationGenerator { public IEnumerable CreateCommands(IEnumerable records) { diff --git a/src/Orchard/Data/Migration/IDataMigration.cs b/src/Orchard/Data/Migration/IDataMigration.cs new file mode 100644 index 000000000..3cb5635ab --- /dev/null +++ b/src/Orchard/Data/Migration/IDataMigration.cs @@ -0,0 +1,7 @@ +using Orchard.Environment.Extensions.Models; + +namespace Orchard.Data.Migration { + public interface IDataMigration : IDependency { + Feature Feature { get; } + } +} diff --git a/src/Orchard/DataMigration/IDataMigrationGenerator.cs b/src/Orchard/Data/Migration/IDataMigrationGenerator.cs similarity index 80% rename from src/Orchard/DataMigration/IDataMigrationGenerator.cs rename to src/Orchard/Data/Migration/IDataMigrationGenerator.cs index a2c59b6c7..2ce898dfd 100644 --- a/src/Orchard/DataMigration/IDataMigrationGenerator.cs +++ b/src/Orchard/Data/Migration/IDataMigrationGenerator.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using FluentNHibernate.Cfg; -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Schema; using Orchard.Environment.ShellBuilders.Models; -namespace Orchard.DataMigration { +namespace Orchard.Data.Migration { // Builds and runs the representative migration create calls public interface IDataMigrationGenerator : IDependency { IEnumerable CreateCommands(IEnumerable records); diff --git a/src/Orchard/DataMigration/IDataMigrationManager.cs b/src/Orchard/Data/Migration/IDataMigrationManager.cs similarity index 94% rename from src/Orchard/DataMigration/IDataMigrationManager.cs rename to src/Orchard/Data/Migration/IDataMigrationManager.cs index d0eff7631..509d19877 100644 --- a/src/Orchard/DataMigration/IDataMigrationManager.cs +++ b/src/Orchard/Data/Migration/IDataMigrationManager.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Orchard.DataMigration { +namespace Orchard.Data.Migration { public interface IDataMigrationManager : IDependency { /// /// Whether a feature has already been installed, i.e. one of its Data Migration class has already been processed diff --git a/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs b/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs similarity index 96% rename from src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs rename to src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs index 3892917d5..fb2db6ee3 100644 --- a/src/Orchard/DataMigration/Interpreters/DefaultDataMigrationInterpreter.cs +++ b/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs @@ -6,12 +6,11 @@ using System.Text; using NHibernate; using NHibernate.Dialect; using NHibernate.SqlTypes; -using Orchard.Data; -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Schema; using Orchard.Environment.Configuration; using Orchard.Logging; -namespace Orchard.DataMigration.Interpreters { +namespace Orchard.Data.Migration.Interpreters { public class DefaultDataMigrationInterpreter : IDataMigrationInterpreter { private readonly ShellSettings _shellSettings; private readonly IEnumerable _commandInterpreters; diff --git a/src/Orchard/DataMigration/Interpreters/ICommandInterpreter.cs b/src/Orchard/Data/Migration/Interpreters/ICommandInterpreter.cs similarity index 78% rename from src/Orchard/DataMigration/Interpreters/ICommandInterpreter.cs rename to src/Orchard/Data/Migration/Interpreters/ICommandInterpreter.cs index 389f3e685..e041abad9 100644 --- a/src/Orchard/DataMigration/Interpreters/ICommandInterpreter.cs +++ b/src/Orchard/Data/Migration/Interpreters/ICommandInterpreter.cs @@ -1,6 +1,6 @@ -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Schema; -namespace Orchard.DataMigration.Interpreters { +namespace Orchard.Data.Migration.Interpreters { /// /// This interface can be implemented to provide a data migration behavior /// diff --git a/src/Orchard/DataMigration/Interpreters/IDataMigrationInterpreter.cs b/src/Orchard/Data/Migration/Interpreters/IDataMigrationInterpreter.cs similarity index 80% rename from src/Orchard/DataMigration/Interpreters/IDataMigrationInterpreter.cs rename to src/Orchard/Data/Migration/Interpreters/IDataMigrationInterpreter.cs index 0827e3a87..a2225b12f 100644 --- a/src/Orchard/DataMigration/Interpreters/IDataMigrationInterpreter.cs +++ b/src/Orchard/Data/Migration/Interpreters/IDataMigrationInterpreter.cs @@ -1,6 +1,6 @@ -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Schema; -namespace Orchard.DataMigration.Interpreters { +namespace Orchard.Data.Migration.Interpreters { public interface IDataMigrationInterpreter : IDependency{ void Visit(ISchemaBuilderCommand command); void Visit(CreateTableCommand command); diff --git a/src/Orchard/DataMigration/Interpreters/SqLiteCommandInterpreter.cs b/src/Orchard/Data/Migration/Interpreters/SqLiteCommandInterpreter.cs similarity index 80% rename from src/Orchard/DataMigration/Interpreters/SqLiteCommandInterpreter.cs rename to src/Orchard/Data/Migration/Interpreters/SqLiteCommandInterpreter.cs index 74afe885c..0a1a5563f 100644 --- a/src/Orchard/DataMigration/Interpreters/SqLiteCommandInterpreter.cs +++ b/src/Orchard/Data/Migration/Interpreters/SqLiteCommandInterpreter.cs @@ -1,14 +1,14 @@ -using Orchard.DataMigration.Schema; +using Orchard.Data.Migration.Schema; -namespace Orchard.DataMigration.Interpreters { - public class SqLiteCommandInterpreter : +namespace Orchard.Data.Migration.Interpreters { + public class SqLiteCommandInterpreter : ICommandInterpreter, - ICommandInterpreter, + ICommandInterpreter, ICommandInterpreter, ICommandInterpreter, ICommandInterpreter, ICommandInterpreter { - + public string[] CreateStatements(DropColumnCommand command) { return new string[0]; } @@ -36,5 +36,5 @@ namespace Orchard.DataMigration.Interpreters { public string DataProvider { get { return "SQLite"; } } - } + } } diff --git a/src/Orchard/DataMigration/DataMigrationRecord.cs b/src/Orchard/Data/Migration/Records/DataMigrationRecord.cs similarity index 79% rename from src/Orchard/DataMigration/DataMigrationRecord.cs rename to src/Orchard/Data/Migration/Records/DataMigrationRecord.cs index 6f84e7d9e..2635e8cd5 100644 --- a/src/Orchard/DataMigration/DataMigrationRecord.cs +++ b/src/Orchard/Data/Migration/Records/DataMigrationRecord.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration { +namespace Orchard.Data.Migration.Records { public class DataMigrationRecord { public virtual int Id { get; set; } public virtual string DataMigrationClass { get; set; } diff --git a/src/Orchard/DataMigration/Schema/AddColumnCommand.cs b/src/Orchard/Data/Migration/Schema/AddColumnCommand.cs similarity index 76% rename from src/Orchard/DataMigration/Schema/AddColumnCommand.cs rename to src/Orchard/Data/Migration/Schema/AddColumnCommand.cs index 4cfd622f8..b036d39e4 100644 --- a/src/Orchard/DataMigration/Schema/AddColumnCommand.cs +++ b/src/Orchard/Data/Migration/Schema/AddColumnCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class AddColumnCommand : CreateColumnCommand { public AddColumnCommand(string tableName, string name) : base(tableName, name) { } diff --git a/src/Orchard/DataMigration/Schema/AddIndexCommand.cs b/src/Orchard/Data/Migration/Schema/AddIndexCommand.cs similarity index 86% rename from src/Orchard/DataMigration/Schema/AddIndexCommand.cs rename to src/Orchard/Data/Migration/Schema/AddIndexCommand.cs index 0f88223c2..6caf4da40 100644 --- a/src/Orchard/DataMigration/Schema/AddIndexCommand.cs +++ b/src/Orchard/Data/Migration/Schema/AddIndexCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class AddIndexCommand : TableCommand { public string IndexName { get; set; } diff --git a/src/Orchard/DataMigration/Schema/AlterColumnCommand.cs b/src/Orchard/Data/Migration/Schema/AlterColumnCommand.cs similarity index 91% rename from src/Orchard/DataMigration/Schema/AlterColumnCommand.cs rename to src/Orchard/Data/Migration/Schema/AlterColumnCommand.cs index 937019b67..711a309a6 100644 --- a/src/Orchard/DataMigration/Schema/AlterColumnCommand.cs +++ b/src/Orchard/Data/Migration/Schema/AlterColumnCommand.cs @@ -1,6 +1,6 @@ using System.Data; -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class AlterColumnCommand : ColumnCommand { public AlterColumnCommand(string tableName, string columnName) : base(tableName, columnName) { diff --git a/src/Orchard/DataMigration/Schema/AlterTableCommand.cs b/src/Orchard/Data/Migration/Schema/AlterTableCommand.cs similarity index 94% rename from src/Orchard/DataMigration/Schema/AlterTableCommand.cs rename to src/Orchard/Data/Migration/Schema/AlterTableCommand.cs index 7c833c908..8c5576e3c 100644 --- a/src/Orchard/DataMigration/Schema/AlterTableCommand.cs +++ b/src/Orchard/Data/Migration/Schema/AlterTableCommand.cs @@ -1,7 +1,7 @@ using System; using System.Data; -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class AlterTableCommand : SchemaCommand { public AlterTableCommand(string name) : base(name, SchemaCommandType.AlterTable) { diff --git a/src/Orchard/DataMigration/Schema/ColumnCommand.cs b/src/Orchard/Data/Migration/Schema/ColumnCommand.cs similarity index 92% rename from src/Orchard/DataMigration/Schema/ColumnCommand.cs rename to src/Orchard/Data/Migration/Schema/ColumnCommand.cs index 4777805eb..a5fc59f13 100644 --- a/src/Orchard/DataMigration/Schema/ColumnCommand.cs +++ b/src/Orchard/Data/Migration/Schema/ColumnCommand.cs @@ -1,6 +1,6 @@ using System.Data; -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class ColumnCommand : TableCommand { public string ColumnName { get; set; } diff --git a/src/Orchard/DataMigration/Schema/CreateColumnCommand.cs b/src/Orchard/Data/Migration/Schema/CreateColumnCommand.cs similarity index 94% rename from src/Orchard/DataMigration/Schema/CreateColumnCommand.cs rename to src/Orchard/Data/Migration/Schema/CreateColumnCommand.cs index 6a5dc5848..3aaf0f0f8 100644 --- a/src/Orchard/DataMigration/Schema/CreateColumnCommand.cs +++ b/src/Orchard/Data/Migration/Schema/CreateColumnCommand.cs @@ -1,6 +1,6 @@ using System.Data; -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class CreateColumnCommand : ColumnCommand { public CreateColumnCommand(string tableName, string name) : base(tableName, name) { IsNotNull = false; diff --git a/src/Orchard/DataMigration/Schema/CreateForeignKeyCommand.cs b/src/Orchard/Data/Migration/Schema/CreateForeignKeyCommand.cs similarity index 90% rename from src/Orchard/DataMigration/Schema/CreateForeignKeyCommand.cs rename to src/Orchard/Data/Migration/Schema/CreateForeignKeyCommand.cs index 71a7d8087..09a01e2ed 100644 --- a/src/Orchard/DataMigration/Schema/CreateForeignKeyCommand.cs +++ b/src/Orchard/Data/Migration/Schema/CreateForeignKeyCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class CreateForeignKeyCommand : SchemaCommand { public string[] DestColumns { get; private set; } diff --git a/src/Orchard/DataMigration/Schema/CreateTableCommand.cs b/src/Orchard/Data/Migration/Schema/CreateTableCommand.cs similarity index 81% rename from src/Orchard/DataMigration/Schema/CreateTableCommand.cs rename to src/Orchard/Data/Migration/Schema/CreateTableCommand.cs index 8072a18ac..5c295e385 100644 --- a/src/Orchard/DataMigration/Schema/CreateTableCommand.cs +++ b/src/Orchard/Data/Migration/Schema/CreateTableCommand.cs @@ -1,7 +1,7 @@ using System; using System.Data; -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class CreateTableCommand : SchemaCommand { public CreateTableCommand(string name) : base(name, SchemaCommandType.CreateTable) { @@ -24,9 +24,15 @@ namespace Orchard.DataMigration.Schema { case TypeCode.String : dbType = DbType.String; break; - case TypeCode.Int32 : + case TypeCode.Int32: dbType = DbType.Int32; break; + case TypeCode.DateTime: + dbType = DbType.DateTime; + break; + case TypeCode.Boolean: + dbType = DbType.Boolean; + break; default: Enum.TryParse(System.Type.GetTypeCode(typeof (T)).ToString(), true, out dbType); break; diff --git a/src/Orchard/DataMigration/Schema/DropColumnCommand.cs b/src/Orchard/Data/Migration/Schema/DropColumnCommand.cs similarity index 77% rename from src/Orchard/DataMigration/Schema/DropColumnCommand.cs rename to src/Orchard/Data/Migration/Schema/DropColumnCommand.cs index 84739b096..e12c17d20 100644 --- a/src/Orchard/DataMigration/Schema/DropColumnCommand.cs +++ b/src/Orchard/Data/Migration/Schema/DropColumnCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class DropColumnCommand : ColumnCommand { public DropColumnCommand(string tableName, string columnName) diff --git a/src/Orchard/DataMigration/Schema/DropForeignKeyCommand.cs b/src/Orchard/Data/Migration/Schema/DropForeignKeyCommand.cs similarity index 84% rename from src/Orchard/DataMigration/Schema/DropForeignKeyCommand.cs rename to src/Orchard/Data/Migration/Schema/DropForeignKeyCommand.cs index ac7367cba..6ad76dab6 100644 --- a/src/Orchard/DataMigration/Schema/DropForeignKeyCommand.cs +++ b/src/Orchard/Data/Migration/Schema/DropForeignKeyCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class DropForeignKeyCommand : SchemaCommand { public string SrcTable { get; private set; } diff --git a/src/Orchard/DataMigration/Schema/DropIndexCommand.cs b/src/Orchard/Data/Migration/Schema/DropIndexCommand.cs similarity index 82% rename from src/Orchard/DataMigration/Schema/DropIndexCommand.cs rename to src/Orchard/Data/Migration/Schema/DropIndexCommand.cs index 57285a0fa..1730d7e66 100644 --- a/src/Orchard/DataMigration/Schema/DropIndexCommand.cs +++ b/src/Orchard/Data/Migration/Schema/DropIndexCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class DropIndexCommand : TableCommand { public string IndexName { get; set; } diff --git a/src/Orchard/DataMigration/Schema/DropTableCommand.cs b/src/Orchard/Data/Migration/Schema/DropTableCommand.cs similarity index 76% rename from src/Orchard/DataMigration/Schema/DropTableCommand.cs rename to src/Orchard/Data/Migration/Schema/DropTableCommand.cs index 4a8a67222..aeb6c70ef 100644 --- a/src/Orchard/DataMigration/Schema/DropTableCommand.cs +++ b/src/Orchard/Data/Migration/Schema/DropTableCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class DropTableCommand : SchemaCommand { public DropTableCommand(string name) : base(name, SchemaCommandType.DropTable) { diff --git a/src/Orchard/DataMigration/Schema/ISchemaBuilderCommand.cs b/src/Orchard/Data/Migration/Schema/ISchemaBuilderCommand.cs similarity index 51% rename from src/Orchard/DataMigration/Schema/ISchemaBuilderCommand.cs rename to src/Orchard/Data/Migration/Schema/ISchemaBuilderCommand.cs index da422593e..cbc613367 100644 --- a/src/Orchard/DataMigration/Schema/ISchemaBuilderCommand.cs +++ b/src/Orchard/Data/Migration/Schema/ISchemaBuilderCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public interface ISchemaBuilderCommand { } } diff --git a/src/Orchard/DataMigration/Schema/IShellSettings.cs b/src/Orchard/Data/Migration/Schema/IShellSettings.cs similarity index 100% rename from src/Orchard/DataMigration/Schema/IShellSettings.cs rename to src/Orchard/Data/Migration/Schema/IShellSettings.cs diff --git a/src/Orchard/DataMigration/Schema/SchemaBuilder.cs b/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs similarity index 62% rename from src/Orchard/DataMigration/Schema/SchemaBuilder.cs rename to src/Orchard/Data/Migration/Schema/SchemaBuilder.cs index c722bee4d..cfe318267 100644 --- a/src/Orchard/DataMigration/Schema/SchemaBuilder.cs +++ b/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs @@ -1,35 +1,32 @@ using System; -using Orchard.DataMigration.Interpreters; -using Orchard.Environment.ShellBuilders.Models; +using Orchard.Data.Migration.Interpreters; -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class SchemaBuilder { private readonly IDataMigrationInterpreter _interpreter; - - public SchemaBuilder(IDataMigrationInterpreter interpreter) { + private readonly string _featurePrefix; + + public SchemaBuilder(IDataMigrationInterpreter interpreter, string featurePrefix = null) { _interpreter = interpreter; + _featurePrefix = featurePrefix; } public SchemaBuilder CreateTable(string name, Action table) { - var createTable = new CreateTableCommand(name); + var createTable = new CreateTableCommand(String.Concat(_featurePrefix, name)); table(createTable); Run(createTable); return this; } - public SchemaBuilder CreateTable(Action table) { - return CreateTable(typeof (TRecord).FullName.Replace(".", "_"), table); - } - public SchemaBuilder AlterTable(string name, Action table) { - var alterTable = new AlterTableCommand(name); + var alterTable = new AlterTableCommand(String.Concat(_featurePrefix, name)); table(alterTable); Run(alterTable); return this; } public SchemaBuilder DropTable(string name) { - var deleteTable = new DropTableCommand(name); + var deleteTable = new DropTableCommand(String.Concat(_featurePrefix, name)); Run(deleteTable); return this; } @@ -43,18 +40,18 @@ namespace Orchard.DataMigration.Schema { return this; } - private void Run(SchemaCommand command) { + private void Run(ISchemaBuilderCommand command) { _interpreter.Visit(command); } public SchemaBuilder CreateForeignKey(string name, string srcTable, string[] srcColumns, string destTable, string[] destColumns) { - var command = new CreateForeignKeyCommand(name, srcTable, srcColumns, destTable, destColumns); + var command = new CreateForeignKeyCommand(name, String.Concat(_featurePrefix, srcTable), srcColumns, String.Concat(_featurePrefix, destTable), destColumns); Run(command); return this; } public SchemaBuilder DropForeignKey(string srcTable, string name) { - var command = new DropForeignKeyCommand(srcTable, name); + var command = new DropForeignKeyCommand(String.Concat(_featurePrefix, srcTable), name); Run(command); return this; } diff --git a/src/Orchard/DataMigration/Schema/SchemaCommand.cs b/src/Orchard/Data/Migration/Schema/SchemaCommand.cs similarity index 91% rename from src/Orchard/DataMigration/Schema/SchemaCommand.cs rename to src/Orchard/Data/Migration/Schema/SchemaCommand.cs index 64176e935..d52155768 100644 --- a/src/Orchard/DataMigration/Schema/SchemaCommand.cs +++ b/src/Orchard/Data/Migration/Schema/SchemaCommand.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using JetBrains.Annotations; -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public abstract class SchemaCommand : ISchemaBuilderCommand { protected SchemaCommand(string name, SchemaCommandType type ) { TableCommands = new List(); diff --git a/src/Orchard/DataMigration/Schema/SqlStatementCommand.cs b/src/Orchard/Data/Migration/Schema/SqlStatementCommand.cs similarity index 90% rename from src/Orchard/DataMigration/Schema/SqlStatementCommand.cs rename to src/Orchard/Data/Migration/Schema/SqlStatementCommand.cs index b730b7863..059fb56d3 100644 --- a/src/Orchard/DataMigration/Schema/SqlStatementCommand.cs +++ b/src/Orchard/Data/Migration/Schema/SqlStatementCommand.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class SqlStatementCommand : SchemaCommand { protected readonly List _providers; public SqlStatementCommand(string sql) diff --git a/src/Orchard/DataMigration/Schema/TableCommand.cs b/src/Orchard/Data/Migration/Schema/TableCommand.cs similarity index 79% rename from src/Orchard/DataMigration/Schema/TableCommand.cs rename to src/Orchard/Data/Migration/Schema/TableCommand.cs index 3d4092fec..d62e8599f 100644 --- a/src/Orchard/DataMigration/Schema/TableCommand.cs +++ b/src/Orchard/Data/Migration/Schema/TableCommand.cs @@ -1,4 +1,4 @@ -namespace Orchard.DataMigration.Schema { +namespace Orchard.Data.Migration.Schema { public class TableCommand : ISchemaBuilderCommand{ public string TableName { get; private set; } diff --git a/src/Orchard/DataMigration/IDataMigration.cs b/src/Orchard/DataMigration/IDataMigration.cs deleted file mode 100644 index 58267f100..000000000 --- a/src/Orchard/DataMigration/IDataMigration.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Orchard.DataMigration { - public interface IDataMigration : IDependency { - string Feature { get; } - } -} diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 2d93e7a09..1d99ebf36 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -356,37 +356,38 @@ Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 8c1b8ff2855942331be12d8428be3419c5997975 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 29 Jun 2010 16:27:23 -0700 Subject: [PATCH 09/19] Corrected merge change --HG-- branch : dev --- src/Orchard/Data/SessionFactoryHolder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Orchard/Data/SessionFactoryHolder.cs b/src/Orchard/Data/SessionFactoryHolder.cs index 8e1e811ae..f462050a1 100644 --- a/src/Orchard/Data/SessionFactoryHolder.cs +++ b/src/Orchard/Data/SessionFactoryHolder.cs @@ -67,7 +67,7 @@ namespace Orchard.Data { public ISessionFactory GetSessionFactory() { lock (this) { if (_sessionFactory == null) { - _sessionFactory = BuildSessionFactory(false /*createDatabase*/, true /*updateSchema*/); + _sessionFactory = BuildSessionFactory(false /*createDatabase*/, false /*updateSchema*/); } } return _sessionFactory; From 8ee4740c454644acb8e03ff6747ebe4b62042f77 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Wed, 30 Jun 2010 10:06:39 -0700 Subject: [PATCH 10/19] Getting a content type's field settings to save. Still need to expose and work with a type part's field settings. --HG-- branch : dev --- .../Controllers/AdminController.cs | 35 +++++++++++++++++++ .../Settings/IndexingSettings.cs | 2 +- .../IContentDefinitionEditorEvents.cs | 4 +-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 308c2a4c9..d7239a282 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -139,6 +139,41 @@ namespace Orchard.ContentTypes.Controllers { typeBuilder.WithPart(entry.part.PartDefinition.Name, typePartBuilder => { partViewModel.Templates = _extendViewModels.TypePartEditorUpdate(typePartBuilder, updater); }); + + if (!partViewModel.PartDefinition.Fields.Any()) + continue; + + _contentDefinitionManager.AlterPartDefinition(partViewModel.PartDefinition.Name, partBuilder => { + foreach (var fieldEntry in partViewModel.PartDefinition.Fields.Select((field, index) => new { field, index })) { + var fieldViewModel = fieldEntry.field; + + // enable updater to be aware of changing field prefix + var firstHalfFieldName = "Fields[" + fieldEntry.index + "]."; + updater._prefix = secondHalf => firstHalfFieldName + secondHalf; + + // allow extensions to alter partField configuration + partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => { + fieldViewModel.Templates = _extendViewModels.PartFieldEditorUpdate(partFieldBuilder, updater); + }); + } + }); + } + + if (viewModel.Fields.Any()) { + _contentDefinitionManager.AlterPartDefinition(viewModel.Name, partBuilder => { + foreach (var fieldEntry in viewModel.Fields.Select((field, index) => new { field, index })) { + var fieldViewModel = fieldEntry.field; + + // enable updater to be aware of changing field prefix + var firstHalfFieldName = "Fields[" + fieldEntry.index + "]."; + updater._prefix = secondHalf => firstHalfFieldName + secondHalf; + + // allow extensions to alter partField configuration + partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => { + fieldViewModel.Templates = _extendViewModels.PartFieldEditorUpdate(partFieldBuilder, updater); + }); + } + }); } }); diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs index 1a1146b5b..8b703a92e 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Settings/IndexingSettings.cs @@ -16,7 +16,7 @@ namespace Orchard.Indexing.Settings { yield return DefinitionTemplate(model); } - public override IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + public override IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder.FieldConfigurer builder, IUpdateModel updateModel) { var model = new IndexingSettings(); updateModel.TryUpdateModel(model, "IndexingSettings", null, null); builder.WithSetting("IndexingSettings.IncludeInIndex", model.IncludeInIndex ? true.ToString() : null); diff --git a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs index f7e5cac93..6fea8af3b 100644 --- a/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs +++ b/src/Orchard/ContentManagement/MetaData/IContentDefinitionEditorEvents.cs @@ -15,7 +15,7 @@ namespace Orchard.ContentManagement.MetaData { IEnumerable TypeEditorUpdate(ContentTypeDefinitionBuilder builder, IUpdateModel updateModel); IEnumerable TypePartEditorUpdate(ContentTypeDefinitionBuilder.PartConfigurer builder, IUpdateModel updateModel); IEnumerable PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel); - IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel); + IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder.FieldConfigurer builder, IUpdateModel updateModel); } public abstract class ContentDefinitionEditorEventsBase : IContentDefinitionEditorEvents { @@ -47,7 +47,7 @@ namespace Orchard.ContentManagement.MetaData { return Enumerable.Empty(); } - public virtual IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) { + public virtual IEnumerable PartFieldEditorUpdate(ContentPartDefinitionBuilder.FieldConfigurer builder, IUpdateModel updateModel) { return Enumerable.Empty(); } From 04f732701a9d103761c7619c9e54b71388429a7a Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 30 Jun 2010 11:25:50 -0700 Subject: [PATCH 11/19] Updated Azure projects --HG-- branch : dev --- .hgignore | 2 +- .../ServiceConfiguration.cscfg | 7 + .../ServiceDefinition.csdef | 9 + .../Orchard.Azure.Web.csproj | 389 ------------------ 4 files changed, 17 insertions(+), 390 deletions(-) diff --git a/.hgignore b/.hgignore index 3472a64ec..9782256f0 100644 --- a/.hgignore +++ b/.hgignore @@ -12,6 +12,6 @@ glob:src/Orchard.Web/Media/* glob:desktop.ini glob:log.xml glob:profiling -glob:src/*.suo glob:src/*.ReSharper glob:*.orig +glob:*.suo diff --git a/src/Orchard.Azure/Orchard.Azure.CloudService/ServiceConfiguration.cscfg b/src/Orchard.Azure/Orchard.Azure.CloudService/ServiceConfiguration.cscfg index 5fd08b040..16eda749c 100644 --- a/src/Orchard.Azure/Orchard.Azure.CloudService/ServiceConfiguration.cscfg +++ b/src/Orchard.Azure/Orchard.Azure.CloudService/ServiceConfiguration.cscfg @@ -1,3 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/src/Orchard.Azure/Orchard.Azure.CloudService/ServiceDefinition.csdef b/src/Orchard.Azure/Orchard.Azure.CloudService/ServiceDefinition.csdef index 8d96b8830..c1f66c33a 100644 --- a/src/Orchard.Azure/Orchard.Azure.CloudService/ServiceDefinition.csdef +++ b/src/Orchard.Azure/Orchard.Azure.CloudService/ServiceDefinition.csdef @@ -1,3 +1,12 @@  + + + + + + + + + \ No newline at end of file diff --git a/src/Orchard.Azure/Orchard.Azure.Web/Orchard.Azure.Web.csproj b/src/Orchard.Azure/Orchard.Azure.Web/Orchard.Azure.Web.csproj index 2517da264..ea271519f 100644 --- a/src/Orchard.Azure/Orchard.Azure.Web/Orchard.Azure.Web.csproj +++ b/src/Orchard.Azure/Orchard.Azure.Web/Orchard.Azure.Web.csproj @@ -92,350 +92,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -464,52 +121,6 @@ Orchard.Azure - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -