From 515ec16f215144b93fa2a17f4097406cbc7f4cc9 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Thu, 15 Dec 2011 14:10:48 -0800 Subject: [PATCH] Running migrations automatically --HG-- branch : 1.x --- .../Data/Migration/AutomaticDataMigrations.cs | 38 +++++++++++++++++++ src/Orchard/Orchard.Framework.csproj | 1 + 2 files changed, 39 insertions(+) create mode 100644 src/Orchard/Data/Migration/AutomaticDataMigrations.cs diff --git a/src/Orchard/Data/Migration/AutomaticDataMigrations.cs b/src/Orchard/Data/Migration/AutomaticDataMigrations.cs new file mode 100644 index 000000000..87d6a81ee --- /dev/null +++ b/src/Orchard/Data/Migration/AutomaticDataMigrations.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Orchard.Environment; +using Orchard.Logging; + +namespace Orchard.Data.Migration { + /// + /// Registers to OrchardShell.Activated in order to run migrations automatically + /// + public class AutomaticDataMigrations : IOrchardShellEvents { + private readonly IDataMigrationManager _dataMigrationManager; + + public AutomaticDataMigrations(IDataMigrationManager dataMigrationManager) { + _dataMigrationManager = dataMigrationManager; + + Logger = NullLogger.Instance; + } + + public ILogger Logger { get; set; } + + public void Activated() { + foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) { + try { + _dataMigrationManager.Update(feature); + } + catch (Exception e) { + Logger.Error("Could not run migrations automatically on " + feature, e); + } + } + } + + public void Terminating() { + + } + } +} diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index a54c3d8a5..efd5a1eaa 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -188,6 +188,7 @@ +