mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Implementation of MySQL dtabase provider
--HG-- branch : 1.x extra : transplant_source : O%ECb%09%81%94%1B%0D%FF%7EQ%23B%AE%C8%C0%E8%F8%B6%DA
This commit is contained in:
@@ -36,7 +36,7 @@ namespace Orchard.Setup.Commands {
|
||||
[OrchardSwitch]
|
||||
public string Recipe { get; set; }
|
||||
|
||||
[CommandHelp("setup /SiteName:<siteName> /AdminUsername:<username> /AdminPassword:<password> /DatabaseProvider:<SqlCe|SQLServer> " +
|
||||
[CommandHelp("setup /SiteName:<siteName> /AdminUsername:<username> /AdminPassword:<password> /DatabaseProvider:<SqlCe|SQLServer|MySql> " +
|
||||
"/DatabaseConnectionString:<connection_string> /DatabaseTablePrefix:<table_prefix> /EnabledFeatures:<feature1,feature2,...> " +
|
||||
"/Recipe:<recipe>" +
|
||||
"\r\n\tRun first time setup for the site or for a given tenant")]
|
||||
|
||||
@@ -111,11 +111,32 @@ namespace Orchard.Setup.Controllers {
|
||||
}
|
||||
|
||||
try {
|
||||
string providerName = null;
|
||||
|
||||
if (model.DatabaseOptions)
|
||||
providerName = "SqlCe";
|
||||
else
|
||||
{
|
||||
switch (model.DatabaseType)
|
||||
{
|
||||
case SetupDatabaseType.SqlServer:
|
||||
providerName = "SqlServer";
|
||||
break;
|
||||
|
||||
case SetupDatabaseType.MySql:
|
||||
providerName = "MySql";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ApplicationException("Unknown database type: " + model.DatabaseType);
|
||||
}
|
||||
}
|
||||
|
||||
var setupContext = new SetupContext {
|
||||
SiteName = model.SiteName,
|
||||
AdminUsername = model.AdminUsername,
|
||||
AdminPassword = model.AdminPassword,
|
||||
DatabaseProvider = model.DatabaseOptions ? "SqlCe" : "SqlServer",
|
||||
DatabaseProvider = providerName,
|
||||
DatabaseConnectionString = model.DatabaseConnectionString,
|
||||
DatabaseTablePrefix = model.DatabaseTablePrefix,
|
||||
EnabledFeatures = null, // default list
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Setup.Controllers
|
||||
{
|
||||
public enum SetupDatabaseType
|
||||
{
|
||||
SqlServer,
|
||||
MySql
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@
|
||||
<Compile Include="Annotations\StringLengthMin.cs" />
|
||||
<Compile Include="Commands\SetupCommand.cs" />
|
||||
<Compile Include="Controllers\SetupController.cs" />
|
||||
<Compile Include="Controllers\SetupDatabaseType.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Routes.cs" />
|
||||
<Compile Include="Services\ISetupService.cs" />
|
||||
|
||||
@@ -13,6 +13,17 @@
|
||||
}
|
||||
})();
|
||||
|
||||
(function () {
|
||||
$('#databaseType').change(function () {
|
||||
$('.databaseTypeHint').hide();
|
||||
$('#databaseType' + $(this).val()).show();
|
||||
});
|
||||
|
||||
// This is to get right info after postback
|
||||
$('.databaseTypeHint').hide();
|
||||
$('#databaseType' + $(this).val()).show();
|
||||
})();
|
||||
|
||||
(function ($) {
|
||||
$("select.recipe").change(function () { // class="recipe" on the select element
|
||||
var description = $(this).find(":selected").attr("recipedescription"); // reads the html attribute of the selected option
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Setup.Annotations;
|
||||
using Orchard.Setup.Controllers;
|
||||
|
||||
namespace Orchard.Setup.ViewModels {
|
||||
public class SetupViewModel {
|
||||
@@ -17,10 +18,13 @@ namespace Orchard.Setup.ViewModels {
|
||||
[PasswordConfirmationRequired]
|
||||
public string ConfirmPassword { get; set; }
|
||||
public bool DatabaseOptions { get; set; }
|
||||
[SqlDatabaseConnectionString]
|
||||
|
||||
// TODO: Do a better validation of connection string that works with MySQL database connection string also
|
||||
// [SqlDatabaseConnectionString]
|
||||
public string DatabaseConnectionString { get; set; }
|
||||
public string DatabaseTablePrefix { get; set; }
|
||||
public bool DatabaseIsPreconfigured { get; set; }
|
||||
public SetupDatabaseType DatabaseType { get; set; }
|
||||
|
||||
public IEnumerable<Recipe> Recipes { get; set; }
|
||||
public string Recipe { get; set; }
|
||||
|
||||
@@ -36,12 +36,19 @@ if (!Model.DatabaseIsPreconfigured) {
|
||||
</div>
|
||||
<div>
|
||||
@Html.RadioButtonFor(svm => svm.DatabaseOptions, false, new { id = "sql" })
|
||||
<label for="sql" class="forcheckbox">@T("Use an existing SQL Server (or SQL Express) database")</label>
|
||||
<label for="sql" class="forcheckbox">@T("Use an existing SQL Server, SQL Express or MySql database")</label>
|
||||
<div data-controllerid="sql">
|
||||
<label for="DatabaseProviderName">@T("Database server type")</label>
|
||||
@Html.DropDownListFor(svm => svm.DatabaseType, Enum.GetValues(typeof(Orchard.Setup.Controllers.SetupDatabaseType)).Cast<Orchard.Setup.Controllers.SetupDatabaseType>().Select(x => new SelectListItem { Text = x.ToString(), Value = ((int)x).ToString() }), new { id = "databaseType" })
|
||||
</div>
|
||||
<div data-controllerid="sql">
|
||||
<label for="DatabaseConnectionString">@T("Connection string")</label>
|
||||
@Html.EditorFor(svm => svm.DatabaseConnectionString)
|
||||
<span class="hint">
|
||||
@T("Example:")<br />@T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password")
|
||||
<span id="databaseType0" class="hint databaseTypeHint">
|
||||
@T("SQL Server Example:")<br />@T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password")
|
||||
</span>
|
||||
<span id="databaseType1" class="hint databaseTypeHint" style="display: none">
|
||||
@T("MySQL Example:")<br />@T("Server=MySqlServerName;Port=3306;User Id=UserName;Password=Password;Persist Security Info=True;Database=DatabaseName;Pooling=True;")
|
||||
</span>
|
||||
</div>
|
||||
<div data-controllerid="sql">
|
||||
|
||||
@@ -60,6 +60,11 @@
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\..\lib\newtonsoft.json\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\mysql\MySql.Data.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NuGet.Core, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\lib\nuget\NuGet.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using FluentNHibernate.Cfg.Db;
|
||||
|
||||
namespace Orchard.Data.Providers
|
||||
{
|
||||
public class MySqklDataServicesProvider : AbstractDataServicesProvider
|
||||
{
|
||||
private readonly string _dataFolder;
|
||||
private readonly string _connectionString;
|
||||
|
||||
public MySqklDataServicesProvider(string dataFolder, string connectionString)
|
||||
{
|
||||
_dataFolder = dataFolder;
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
public static string ProviderName
|
||||
{
|
||||
get { return "MySql"; }
|
||||
}
|
||||
|
||||
public override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase)
|
||||
{
|
||||
var persistence = MySQLConfiguration.Standard;
|
||||
if (string.IsNullOrEmpty(_connectionString))
|
||||
{
|
||||
throw new ArgumentException("The connection string is empty");
|
||||
}
|
||||
persistence = persistence.ConnectionString(_connectionString);
|
||||
return persistence;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,6 +738,7 @@
|
||||
<Compile Include="Data\Providers\DataServicesProviderFactory.cs" />
|
||||
<Compile Include="Data\Providers\IDataServicesProviderFactory.cs" />
|
||||
<Compile Include="Data\Providers\SqlServerDataServicesProvider.cs" />
|
||||
<Compile Include="Data\Providers\MySqlDataServicesProvider.cs" />
|
||||
<Compile Include="Data\Conventions\StringLengthConvention.cs" />
|
||||
<Compile Include="Data\SessionFactoryHolder.cs" />
|
||||
<Compile Include="Environment\AutofacUtil\LifetimeScopeContainer.cs" />
|
||||
|
||||
Reference in New Issue
Block a user