oqtane.framework/Oqtane.Server/Controllers/InstallationController.cs
Pavel Vesely 940cdcb349 Database Manager
done:
+ master.sql as resource
+ implemented incremental database changes also for Master
+ dbUp sql script variables implemented
+ improved database handling and creation code
+ simpified database creation
+ almost all Database and Tenant creation moved to DatabaseManager.cs (rest code marked with TODO)
+ Unattended install of master can be performed by settings in appsettings.json
+ Improved IsInstalled checking
+ Removed DBSchema field from Tenant
+ Default database and site creation moved to Program.Main
2020-03-29 14:45:02 +02:00

82 lines
2.6 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Oqtane.Models;
using Oqtane.Shared;
using Oqtane.Infrastructure;
using Oqtane.Infrastructure.Interfaces;
// ReSharper disable StringIndexOfIsCultureSpecific.1
namespace Oqtane.Controllers
{
[Route("{site}/api/[controller]")]
public class InstallationController : Controller
{
private readonly IConfigurationRoot _config;
private readonly IInstallationManager _installationManager;
private readonly DatabaseManager _databaseManager;
public InstallationController(IConfigurationRoot config, IInstallationManager installationManager, DatabaseManager databaseManager)
{
_config = config;
_installationManager = installationManager;
_databaseManager = databaseManager;
}
// POST api/<controller>
[HttpPost]
public Installation Post([FromBody] InstallConfig config)
{
//TODO Security ????
var installation = new Installation {Success = false, Message = ""};
if (ModelState.IsValid && (!_databaseManager.IsInstalled || !config.IsMaster))
{
bool master = config.IsMaster;
config.Alias = config.Alias ?? HttpContext.Request.Host.Value;
var result = DatabaseManager.InstallDatabase(config);
if (result.Success)
{
if (master)
{
_config.Reload();
}
installation.Success = true;
return installation;
}
installation.Message = result.Message;
return installation;
}
installation.Message = "Application Is Already Installed";
return installation;
}
// GET api/<controller>/installed
[HttpGet("installed")]
public Installation IsInstalled()
{
var installation = new Installation {Success = false, Message = ""};
installation.Success = _databaseManager.IsInstalled;
installation.Message = _databaseManager.Message;
return installation;
}
[HttpGet("upgrade")]
[Authorize(Roles = Constants.HostRole)]
public Installation Upgrade()
{
var installation = new Installation {Success = true, Message = ""};
_installationManager.UpgradeFramework();
return installation;
}
}
}