-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathUpdateManagedSchemaAction.cs
More file actions
49 lines (41 loc) · 1.42 KB
/
UpdateManagedSchemaAction.cs
File metadata and controls
49 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using JetBrains.Annotations;
using SIM.Extensions;
using Sitecore.Diagnostics.Base;
using System.Xml;
namespace SIM.Pipelines.InstallSearchIndexes
{
public class UpdateManagedSchemaAction : InstallSearchIndexesProcessor
{
protected override void Process([NotNull] InstallSearchIndexesArgs args)
{
Assert.ArgumentNotNull(args, nameof(args));
foreach (var index in args._AvailableSearchIndexesDictionary)
{
string newCorePath = args.SolrFolder.EnsureEnd(@"\") + index.Value;
UpdateManagedSchemaFile(newCorePath);
}
}
private void UpdateManagedSchemaFile(string newCorePath)
{
XmlDocument doc = new XmlDocument();
doc.Load(newCorePath.EnsureEnd(@"\") + @"conf\managed-schema");
XmlElement newField = doc.CreateElement("field");
newField.SetAttribute("name", "_uniqueid");
newField.SetAttribute("type", "string");
newField.SetAttribute("indexed", "true");
newField.SetAttribute("required", "true");
newField.SetAttribute("stored", "true");
XmlNode schemaNode = doc.SelectSingleNode("/schema");
if (schemaNode != null)
{
schemaNode.AppendChild(newField);
}
XmlNode uniqueKeyNode = doc.SelectSingleNode("/schema/uniqueKey");
if (uniqueKeyNode != null)
{
uniqueKeyNode.InnerText = "_uniqueid";
}
doc.Save(newCorePath.EnsureEnd(@"\") + @"conf\managed-schema");
}
}
}