diff --git a/src/Orchard/DataMigration/DataMigrationCoordinator.cs b/src/Orchard/DataMigration/DataMigrationCoordinator.cs
index f34954491..a0f58ca33 100644
--- a/src/Orchard/DataMigration/DataMigrationCoordinator.cs
+++ b/src/Orchard/DataMigration/DataMigrationCoordinator.cs
@@ -35,6 +35,10 @@ namespace Orchard.DataMigration {
}
public void Uninstall(Feature feature) {
+ var featureName = feature.Descriptor.Name;
+ if ( _dataMigrationManager.IsFeatureAlreadyInstalled(featureName) ) {
+ _dataMigrationManager.Uninstall(featureName);
+ }
}
}
}
diff --git a/src/Orchard/DataMigration/DataMigrationManager.cs b/src/Orchard/DataMigration/DataMigrationManager.cs
index 32e8b6dbe..58fdf2a17 100644
--- a/src/Orchard/DataMigration/DataMigrationManager.cs
+++ b/src/Orchard/DataMigration/DataMigrationManager.cs
@@ -148,6 +148,34 @@ namespace Orchard.DataMigration {
}
}
+ public void Uninstall(string feature) {
+
+ var migrations = GetDataMigrations(feature);
+
+ // apply update methods to each migration class for the module
+ foreach (var migration in migrations) {
+ // copy the objet for the Linq query
+ var tempMigration = migration;
+
+ // get current version for this migration
+ var dataMigrationRecord = GetDataMigrationRecord(tempMigration);
+
+ var uninstallMethod = GetUninstallMethod(migration);
+ if (uninstallMethod != null) {
+ uninstallMethod.Invoke(migration, new object[0]);
+ }
+
+ if ( dataMigrationRecord == null ) {
+ continue;
+ }
+
+ _dataMigrationRepository.Delete(dataMigrationRecord);
+ _dataMigrationRepository.Flush();
+ }
+
+ }
+
+
private DataMigrationRecord GetDataMigrationRecord(IDataMigration tempMigration) {
return _dataMigrationRepository.Table
.Where(dm => dm.DataMigrationClass == tempMigration.GetType().FullName)
@@ -197,7 +225,7 @@ namespace Orchard.DataMigration {
}
///
- /// Returns the Create metho from a data migration class if it's found
+ /// Returns the Create method from a data migration class if it's found
///
private static MethodInfo GetCreateMethod(IDataMigration dataMigration) {
var methodInfo = dataMigration.GetType().GetMethod("Create", BindingFlags.Public | BindingFlags.Instance);
@@ -207,5 +235,18 @@ namespace Orchard.DataMigration {
return null;
}
+
+ ///
+ /// Returns the Uninstall method from a data migration class if it's found
+ ///
+ private static MethodInfo GetUninstallMethod(IDataMigration dataMigration) {
+ var methodInfo = dataMigration.GetType().GetMethod("Uninstall", BindingFlags.Public | BindingFlags.Instance);
+ if ( methodInfo != null && methodInfo.ReturnType == typeof(void) ) {
+ return methodInfo;
+ }
+
+ return null;
+ }
+
}
}
diff --git a/src/Orchard/DataMigration/IDataMigrationManager.cs b/src/Orchard/DataMigration/IDataMigrationManager.cs
index 7f887e728..d0eff7631 100644
--- a/src/Orchard/DataMigration/IDataMigrationManager.cs
+++ b/src/Orchard/DataMigration/IDataMigrationManager.cs
@@ -21,5 +21,11 @@ namespace Orchard.DataMigration {
/// Updates the database to the latest version for the specified features
///
void Update(IEnumerable features);
+
+ ///
+ /// Execute a script to delete any information relative to the feature
+ ///
+ ///
+ void Uninstall(string feature);
}
}
\ No newline at end of file