Moving in its own file

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-11-23 09:35:23 -08:00
parent bc9daa82b4
commit ec3b5aa683
3 changed files with 66 additions and 58 deletions

View File

@@ -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 <feature-name> [/Drop:true|false] \r\n\t" + "Creates the database tables for the <feature-name> 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";
}
}
}

View File

@@ -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 <feature-name> [/Drop:true|false] \r\n\t" + "Creates the database tables for the <feature-name> 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";
}
}
}

View File

@@ -46,6 +46,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\DatabaseUpdateCommands.cs" />
<Compile Include="Commands\DataMigrationCommands.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>