From ec3b5aa683aab2abcda9aa4160bc4fdb3ff715fc Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Tue, 23 Nov 2010 09:35:23 -0800 Subject: [PATCH] Moving in its own file --HG-- branch : dev --- .../Commands/DataMigrationCommands.cs | 58 ----------------- .../Commands/DatabaseUpdateCommands.cs | 65 +++++++++++++++++++ .../Orchard.Migrations.csproj | 1 + 3 files changed, 66 insertions(+), 58 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Migrations/Commands/DatabaseUpdateCommands.cs diff --git a/src/Orchard.Web/Modules/Orchard.Migrations/Commands/DataMigrationCommands.cs b/src/Orchard.Web/Modules/Orchard.Migrations/Commands/DataMigrationCommands.cs index 92d82bea1..4ed54ead4 100644 --- a/src/Orchard.Web/Modules/Orchard.Migrations/Commands/DataMigrationCommands.cs +++ b/src/Orchard.Web/Modules/Orchard.Migrations/Commands/DataMigrationCommands.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Linq; using Orchard.Commands; using Orchard.Data.Migration; -using Orchard.Data.Migration.Generator; -using Orchard.Data.Migration.Interpreters; using Orchard.Environment.Extensions; namespace Orchard.Migrations.Commands { @@ -44,60 +42,4 @@ namespace Orchard.Migrations.Commands { return "Database upgraded"; } } - [OrchardFeature("DatabaseUpdate")] - public class DatabaseUpdateCommands : DefaultOrchardCommandHandler { - private readonly IDataMigrationInterpreter _dataMigrationInterpreter; - private readonly ISchemaCommandGenerator _schemaCommandGenerator; - - [OrchardSwitch] - public bool Drop { get; set; } - - public DatabaseUpdateCommands( - IDataMigrationInterpreter dataMigrationInterpreter, - ISchemaCommandGenerator schemaCommandGenerator - ) { - _dataMigrationInterpreter = dataMigrationInterpreter; - _schemaCommandGenerator = schemaCommandGenerator; - } - - [CommandName("update database")] - [CommandHelp("update database \r\n\t" + "Automatically updates the database schema for the enabled features")] - public string UpdateDatabase() { - try { - _schemaCommandGenerator.UpdateDatabase(); - } - catch ( Exception ex ) { - Context.Output.WriteLine(T("An error occured while updating the database: " + ex.Message)); - return "Update terminated."; - } - - return "Database updated"; - } - - [CommandName("create tables")] - [CommandHelp("create tables [/Drop:true|false] \r\n\t" + "Creates the database tables for the and optionally drops them before if specified")] - [OrchardSwitches("Drop")] - public string CreateTables(string featureName) { - var stringInterpreter = new StringCommandInterpreter(Context.Output); - try { - var commands = _schemaCommandGenerator.GetCreateFeatureCommands(featureName, Drop).ToList(); - if ( commands.Any() ) { - - foreach (var command in commands) { - stringInterpreter.Visit(command); - _dataMigrationInterpreter.Visit(command); - } - } - else { - return "There are no tables to create for this feature."; - } - } - catch ( Exception ex ) { - Context.Output.WriteLine(T("An error occured while creating the tables: " + ex.Message)); - return "Tables creation terminated."; - } - - return "Tables created"; - } - } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Migrations/Commands/DatabaseUpdateCommands.cs b/src/Orchard.Web/Modules/Orchard.Migrations/Commands/DatabaseUpdateCommands.cs new file mode 100644 index 000000000..e2ecfcc84 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Migrations/Commands/DatabaseUpdateCommands.cs @@ -0,0 +1,65 @@ +using System; +using System.Linq; +using Orchard.Commands; +using Orchard.Data.Migration.Generator; +using Orchard.Data.Migration.Interpreters; +using Orchard.Environment.Extensions; + +namespace Orchard.Migrations.Commands { + [OrchardFeature("DatabaseUpdate")] + public class DatabaseUpdateCommands : DefaultOrchardCommandHandler { + private readonly IDataMigrationInterpreter _dataMigrationInterpreter; + private readonly ISchemaCommandGenerator _schemaCommandGenerator; + + [OrchardSwitch] + public bool Drop { get; set; } + + public DatabaseUpdateCommands( + IDataMigrationInterpreter dataMigrationInterpreter, + ISchemaCommandGenerator schemaCommandGenerator + ) { + _dataMigrationInterpreter = dataMigrationInterpreter; + _schemaCommandGenerator = schemaCommandGenerator; + } + + [CommandName("update database")] + [CommandHelp("update database \r\n\t" + "Automatically updates the database schema for the enabled features")] + public string UpdateDatabase() { + try { + _schemaCommandGenerator.UpdateDatabase(); + } + catch ( Exception ex ) { + Context.Output.WriteLine(T("An error occured while updating the database: " + ex.Message)); + return "Update terminated."; + } + + return "Database updated"; + } + + [CommandName("create tables")] + [CommandHelp("create tables [/Drop:true|false] \r\n\t" + "Creates the database tables for the and optionally drops them before if specified")] + [OrchardSwitches("Drop")] + public string CreateTables(string featureName) { + var stringInterpreter = new StringCommandInterpreter(Context.Output); + try { + var commands = _schemaCommandGenerator.GetCreateFeatureCommands(featureName, Drop).ToList(); + if ( commands.Any() ) { + + foreach (var command in commands) { + stringInterpreter.Visit(command); + _dataMigrationInterpreter.Visit(command); + } + } + else { + return "There are no tables to create for this feature."; + } + } + catch ( Exception ex ) { + Context.Output.WriteLine(T("An error occured while creating the tables: " + ex.Message)); + return "Tables creation terminated."; + } + + return "Tables created"; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Migrations/Orchard.Migrations.csproj b/src/Orchard.Web/Modules/Orchard.Migrations/Orchard.Migrations.csproj index a790149ff..b3988f987 100644 --- a/src/Orchard.Web/Modules/Orchard.Migrations/Orchard.Migrations.csproj +++ b/src/Orchard.Web/Modules/Orchard.Migrations/Orchard.Migrations.csproj @@ -46,6 +46,7 @@ +