Shifting TypePadSettings

This commit is contained in:
Sebastien Ros
2013-10-29 18:25:06 -07:00
parent 4e218a5362
commit ddca4f762f
8 changed files with 25 additions and 28 deletions

View File

@@ -1,7 +1,6 @@
using JetBrains.Annotations;
using Orchard.AntiSpam.Models;
using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
using Orchard.Environment.Extensions;
using Orchard.Localization;
@@ -10,11 +9,10 @@ namespace Orchard.AntiSpam.Handlers {
[UsedImplicitly]
[OrchardFeature("TypePad.Filter")]
public class TypePadSettingsPartHandler : ContentHandler {
public TypePadSettingsPartHandler(IRepository<TypePadSettingsPartRecord> repository) {
public TypePadSettingsPartHandler() {
T = NullLocalizer.Instance;
Filters.Add(new ActivatingFilter<TypePadSettingsPart>("Site"));
Filters.Add(StorageFilter.For(repository));
Filters.Add(new TemplateFilterForRecord<TypePadSettingsPartRecord>("TypePadSettings", "Parts/AntiSpam.TypePadSettings", "spam"));
Filters.Add(new TemplateFilterForPart<TypePadSettingsPart>("TypePadSettings", "Parts/AntiSpam.TypePadSettings", "spam"));
}
public Localizer T { get; set; }

View File

@@ -85,13 +85,6 @@ namespace Orchard.AntiSpam {
public class TypePadMigrations : DataMigrationImpl {
public int Create() {
SchemaBuilder.CreateTable("TypePadSettingsPartRecord",
table => table.ContentPartVersionRecord()
.Column<bool>("TrustAuthenticatedUsers")
.Column<string>("ApiKey")
);
return 1;
}
}

View File

@@ -1,6 +1,15 @@
using Orchard.ContentManagement;
namespace Orchard.AntiSpam.Models {
public class TypePadSettingsPart : ContentPart<TypePadSettingsPartRecord> {
public class TypePadSettingsPart : ContentPart {
public bool TrustAuthenticatedUsers {
get { return this.Retrieve(x => x.TrustAuthenticatedUsers); }
set { this.Store(x => x.TrustAuthenticatedUsers, value); }
}
public string ApiKey {
get { return this.Retrieve(x => x.ApiKey); }
set { this.Store(x => x.ApiKey, value); }
}
}
}

View File

@@ -1,11 +0,0 @@
using Orchard.ContentManagement.Records;
namespace Orchard.AntiSpam.Models {
public class TypePadSettingsPartRecord : ContentPartRecord {
public virtual bool TrustAuthenticatedUsers { get; set; }
// API key for TypePad AntiSpam (http://antispam.typepad.com/info/get-api-key.html).
public virtual string ApiKey { get; set; }
}
}

View File

@@ -110,10 +110,9 @@
<Compile Include="Models\CommentCheckContext.cs" />
<Compile Include="Models\ReCaptchaSettingsPart.cs" />
<Compile Include="Models\TypePadSettingsPart.cs" />
<Compile Include="Models\TypePadSettingsPartRecord.cs" />
<Compile Include="Models\_SpamFilterPart.cs" />
<Compile Include="Models\ReCaptchaPart.cs" />
<Compile Include="Models\SpamFilterPartRecord.cs" />
<Compile Include="Models\ReCaptchaPart.cs" />
<Compile Include="Models\SpamFilterPart.cs" />
<Compile Include="Models\SpamStatus.cs" />
<Compile Include="Models\SubmissionLimitPart.cs" />
<Compile Include="Permissions.cs" />

View File

@@ -19,7 +19,7 @@ namespace Orchard.AntiSpam.Services {
public IEnumerable<ISpamFilter> GetSpamFilters() {
var settings = _orchardServices.WorkContext.CurrentSite.As<TypePadSettingsPart>().Record;
var settings = _orchardServices.WorkContext.CurrentSite.As<TypePadSettingsPart>();
if(string.IsNullOrWhiteSpace(settings.ApiKey)) {
yield break;

View File

@@ -1,4 +1,4 @@
@model Orchard.AntiSpam.Models.TypePadSettingsPartRecord
@model Orchard.AntiSpam.Models.TypePadSettingsPart
@using Orchard.Utility.Extensions;
<fieldset>

View File

@@ -95,6 +95,15 @@ namespace Upgrade.Controllers {
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_ReCaptchaSettingsPartRecord"), null);
// TypePadSettingsPartRecord
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_TypePadSettingsPartRecord"),
(reader, connection) => {
site.As<InfosetPart>().Set("TypePadSettingsPart", "ApiKey", reader["ApiKey"].ToString());
site.As<InfosetPart>().Set("ReCaptchaSettingsPart", "TrustAuthenticatedUsers", reader["TrustAuthenticatedUsers"].ToString());
});
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_TypePadSettingsPartRecord"), null);
_orchardServices.Notifier.Information(T("Site Settings migrated successfully"));