set SiteState in HostedServiceBase for scheduled jobs
This commit is contained in:
@ -91,7 +91,15 @@ namespace Oqtane.Infrastructure
|
|||||||
// execute the job
|
// execute the job
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
log.Notes = ExecuteJob(scope.ServiceProvider);
|
var notes = "";
|
||||||
|
var tenants = scope.ServiceProvider.GetRequiredService<ITenantRepository>();
|
||||||
|
var siteState = scope.ServiceProvider.GetRequiredService<SiteState>();
|
||||||
|
foreach (var tenant in tenants.GetTenants())
|
||||||
|
{
|
||||||
|
siteState.Alias = new Alias { TenantId = tenant.TenantId };
|
||||||
|
notes += ExecuteJob(scope.ServiceProvider);
|
||||||
|
}
|
||||||
|
log.Notes = notes;
|
||||||
log.Succeeded = true;
|
log.Succeeded = true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -26,20 +26,7 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
string log = "";
|
string log = "";
|
||||||
|
|
||||||
// iterate through tenants in this installation
|
// get services
|
||||||
List<int> tenants = new List<int>();
|
|
||||||
var aliasRepository = provider.GetRequiredService<IAliasRepository>();
|
|
||||||
List<Alias> aliases = aliasRepository.GetAliases().ToList();
|
|
||||||
foreach (Alias alias in aliases)
|
|
||||||
{
|
|
||||||
if (tenants.Contains(alias.TenantId)) continue;
|
|
||||||
tenants.Add(alias.TenantId);
|
|
||||||
|
|
||||||
// use the SiteState to set the Alias explicitly so the tenant can be resolved
|
|
||||||
var siteState = provider.GetRequiredService<SiteState>();
|
|
||||||
siteState.Alias = alias;
|
|
||||||
|
|
||||||
// get services which require tenant resolution
|
|
||||||
var siteRepository = provider.GetRequiredService<ISiteRepository>();
|
var siteRepository = provider.GetRequiredService<ISiteRepository>();
|
||||||
var settingRepository = provider.GetRequiredService<ISettingRepository>();
|
var settingRepository = provider.GetRequiredService<ISettingRepository>();
|
||||||
var notificationRepository = provider.GetRequiredService<INotificationRepository>();
|
var notificationRepository = provider.GetRequiredService<INotificationRepository>();
|
||||||
@ -124,7 +111,6 @@ namespace Oqtane.Infrastructure
|
|||||||
log += "SMTP Not Configured Properly In Site Settings - Host, Port, SSL, And Sender Are All Required" + "<br />";
|
log += "SMTP Not Configured Properly In Site Settings - Host, Port, SSL, And Sender Are All Required" + "<br />";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user