mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding migration steps for Orchard.Indexing and Orchard.Search
--HG-- branch : 1.x
This commit is contained in:
@@ -1,11 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
|
|
||||||
namespace Orchard.Indexing {
|
namespace Orchard.Indexing {
|
||||||
public class Migrations : DataMigrationImpl {
|
public class Migrations : DataMigrationImpl {
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
|
||||||
|
public Migrations(IContentDefinitionManager contentDefinitionManager) {
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
|
}
|
||||||
|
|
||||||
public int Create() {
|
public int Create() {
|
||||||
SchemaBuilder.CreateTable("IndexingTaskRecord",
|
SchemaBuilder.CreateTable("IndexingTaskRecord",
|
||||||
table => table
|
table => table
|
||||||
.Column<int>("Id", column => column.PrimaryKey().Identity())
|
.Column<int>("Id", column => column.PrimaryKey().Identity())
|
||||||
.Column<int>("Action")
|
.Column<int>("Action")
|
||||||
@@ -13,10 +20,20 @@ namespace Orchard.Indexing {
|
|||||||
.Column<int>("ContentItemRecord_id")
|
.Column<int>("ContentItemRecord_id")
|
||||||
);
|
);
|
||||||
|
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: When upgrading from 1, change TypeIndexing.Included to TypeIndexing.Indexes = "Search"
|
public int UpdateFrom1() {
|
||||||
// todo: When upgrading from 1, define SearchSettingsPart.SelectedIndex to "Search"
|
|
||||||
|
foreach (var typeDefinition in _contentDefinitionManager.ListTypeDefinitions()) {
|
||||||
|
if (typeDefinition.Settings.ContainsKey("TypeIndexing.Included") && Convert.ToBoolean(typeDefinition.Settings["TypeIndexing.Included"], CultureInfo.InvariantCulture)) {
|
||||||
|
typeDefinition.Settings.Remove("TypeIndexing.Included");
|
||||||
|
typeDefinition.Settings["TypeIndexing.Indexes"] = "Search";
|
||||||
|
_contentDefinitionManager.StoreTypeDefinition(typeDefinition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,8 +1,16 @@
|
|||||||
using Orchard.ContentManagement.MetaData;
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.Data;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
|
using Orchard.Search.Models;
|
||||||
|
|
||||||
namespace Orchard.Search {
|
namespace Orchard.Search {
|
||||||
public class SearchDataMigration : DataMigrationImpl {
|
public class SearchDataMigration : DataMigrationImpl {
|
||||||
|
private readonly IRepository<SearchSettingsPartRecord> _searchSettingsPartRecordRepository;
|
||||||
|
|
||||||
|
public SearchDataMigration(IRepository<SearchSettingsPartRecord> searchSettingsPartRecordRepository) {
|
||||||
|
_searchSettingsPartRecordRepository = searchSettingsPartRecordRepository;
|
||||||
|
}
|
||||||
|
|
||||||
public int Create() {
|
public int Create() {
|
||||||
|
|
||||||
@@ -29,6 +37,11 @@ namespace Orchard.Search {
|
|||||||
.AddColumn<string>("SearchIndex")
|
.AddColumn<string>("SearchIndex")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var settings = _searchSettingsPartRecordRepository.Table.FirstOrDefault();
|
||||||
|
if (settings != null) {
|
||||||
|
settings.SearchIndex = "Search";
|
||||||
|
}
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user