mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 19:44:02 +08:00
Running migrations automatically
--HG-- branch : 1.x
This commit is contained in:
38
src/Orchard/Data/Migration/AutomaticDataMigrations.cs
Normal file
38
src/Orchard/Data/Migration/AutomaticDataMigrations.cs
Normal file
@@ -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 {
|
||||
/// <summary>
|
||||
/// Registers to OrchardShell.Activated in order to run migrations automatically
|
||||
/// </summary>
|
||||
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() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,6 +188,7 @@
|
||||
<Compile Include="ContentManagement\QueryHints.cs" />
|
||||
<Compile Include="ContentManagement\Utilities\ComputedField.cs" />
|
||||
<Compile Include="Data\Conventions\AggregateAttribute.cs" />
|
||||
<Compile Include="Data\Migration\AutomaticDataMigrations.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\PlacementInfo.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ResourceBindingStrategy\StylesheetBindingStrategy.cs" />
|
||||
<Compile Include="DisplayManagement\Descriptors\ShapeDescriptor.cs" />
|
||||
|
||||
Reference in New Issue
Block a user