-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathCreateSolrCoreAction.cs
More file actions
36 lines (31 loc) · 1.29 KB
/
CreateSolrCoreAction.cs
File metadata and controls
36 lines (31 loc) · 1.29 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
using JetBrains.Annotations;
using SIM.Extensions;
using Sitecore.Diagnostics.Base;
using System.IO;
namespace SIM.Pipelines.InstallSearchIndexes
{
public class CreateSolrCoreAction : 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;
RequestAndGetResponseStream($"{args.SolrUrl}/admin/cores?action=CREATE&name={index.Value}&instanceDir={newCorePath}&config=solrconfig.xml&schema=schema.xml&dataDir=data");
UpdateCorePropertiesFile(index.Value, newCorePath);
}
}
private Stream RequestAndGetResponseStream(string url)
{
return WebRequestHelper.RequestAndGetResponse(url).GetResponseStream();
}
private void UpdateCorePropertiesFile(string coreName, string newCorePath)
{
string filePath = string.Format(newCorePath.EnsureEnd(@"\") + @"core.properties");
string newText = @"update.autoCreateFields=false" + "\r\n" + "name=" + coreName;
FileSystem.FileSystem.Local.File.Delete(filePath);
FileSystem.FileSystem.Local.File.WriteAllText(filePath, newText);
}
}
}