refactoring the code.
This commit is contained in:
@ -11,6 +11,8 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
public class SearchIndexJob : HostedServiceBase
|
||||
{
|
||||
private const string SearchIndexStartTimeSettingName = "SearchIndex_StartTime";
|
||||
|
||||
public SearchIndexJob(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory)
|
||||
{
|
||||
Name = "Search Index Job";
|
||||
@ -54,7 +56,7 @@ namespace Oqtane.Infrastructure
|
||||
|
||||
private DateTime? GetSearchStartTime(int siteId, ISettingRepository settingRepository)
|
||||
{
|
||||
var setting = settingRepository.GetSetting(EntityNames.Site, siteId, Constants.SearchIndexStartTimeSettingName);
|
||||
var setting = settingRepository.GetSetting(EntityNames.Site, siteId, SearchIndexStartTimeSettingName);
|
||||
if(setting == null)
|
||||
{
|
||||
return null;
|
||||
@ -65,14 +67,14 @@ namespace Oqtane.Infrastructure
|
||||
|
||||
private void UpdateSearchStartTime(int siteId, DateTime startTime, ISettingRepository settingRepository)
|
||||
{
|
||||
var setting = settingRepository.GetSetting(EntityNames.Site, siteId, Constants.SearchIndexStartTimeSettingName);
|
||||
var setting = settingRepository.GetSetting(EntityNames.Site, siteId, SearchIndexStartTimeSettingName);
|
||||
if (setting == null)
|
||||
{
|
||||
setting = new Setting
|
||||
{
|
||||
EntityName = EntityNames.Site,
|
||||
EntityId = siteId,
|
||||
SettingName = Constants.SearchIndexStartTimeSettingName,
|
||||
SettingName = SearchIndexStartTimeSettingName,
|
||||
SettingValue = Convert.ToString(startTime),
|
||||
};
|
||||
|
||||
|
@ -138,7 +138,7 @@ namespace Oqtane.SiteTemplates
|
||||
Name = "Search Results",
|
||||
Parent = "",
|
||||
Order = 7,
|
||||
Path = "search-results",
|
||||
Path = "search",
|
||||
Icon = "oi oi-magnifying-glass",
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
@ -148,7 +148,7 @@ namespace Oqtane.SiteTemplates
|
||||
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||
},
|
||||
PageTemplateModules = new List<PageTemplateModule> {
|
||||
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.SearchResults, Oqtane.Client", Title = "Search Results", Pane = PaneNames.Default,
|
||||
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.SearchResults, Oqtane.Client", Title = "Search Results", Pane = PaneNames.Default,
|
||||
PermissionList = new List<Permission> {
|
||||
new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
||||
new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||
|
@ -66,6 +66,9 @@ namespace Oqtane.Infrastructure
|
||||
case "5.1.0":
|
||||
Upgrade_5_1_0(tenant, scope);
|
||||
break;
|
||||
case "5.2.0":
|
||||
Upgrade_5_2_0(tenant, scope);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -385,5 +388,48 @@ namespace Oqtane.Infrastructure
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Upgrade_5_2_0(Tenant tenant, IServiceScope scope)
|
||||
{
|
||||
CreateSearchResultsPages(tenant, scope);
|
||||
}
|
||||
|
||||
private void CreateSearchResultsPages(Tenant tenant, IServiceScope scope)
|
||||
{
|
||||
var pageTemplates = new List<PageTemplate>();
|
||||
pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "Search Results",
|
||||
Parent = "",
|
||||
Path = "search",
|
||||
Icon = "oi oi-magnifying-glass",
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
PermissionList = new List<Permission> {
|
||||
new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
||||
new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||
},
|
||||
PageTemplateModules = new List<PageTemplateModule> {
|
||||
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.Admin.SearchResults, Oqtane.Client", Title = "Search Results", Pane = PaneNames.Default,
|
||||
PermissionList = new List<Permission> {
|
||||
new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
||||
new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var pages = scope.ServiceProvider.GetRequiredService<IPageRepository>();
|
||||
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||
foreach (var site in sites.GetSites().ToList())
|
||||
{
|
||||
if (!pages.GetPages(site.SiteId).ToList().Where(item => item.Path == "search").Any())
|
||||
{
|
||||
sites.CreatePages(site, pageTemplates, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user