diff --git a/NzbDrone.Core/Datastore/Migrations/Migration.cs b/NzbDrone.Core/Datastore/Migrations/Migration.cs index b9a527c9b..4fbbe431b 100644 --- a/NzbDrone.Core/Datastore/Migrations/Migration.cs +++ b/NzbDrone.Core/Datastore/Migrations/Migration.cs @@ -108,6 +108,14 @@ namespace NzbDrone.Core.Datastore.Migrations new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey), new Column("Path", DbType.String, ColumnProperty.NotNull), }); + + Database.AddTable("ExternalNotificationSettings", "SQLite", new[] + { + new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey), + new Column("Enabled", DbType.Boolean, ColumnProperty.NotNull), + new Column("NotifierName", DbType.String, ColumnProperty.NotNull), + new Column("Name", DbType.String, ColumnProperty.NotNull) + }); } public override void Down() diff --git a/NzbDrone.Core/Providers/ExternalNotificationProvider.cs b/NzbDrone.Core/Providers/ExternalNotificationProvider.cs index d6f16f5f1..8e86e4cba 100644 --- a/NzbDrone.Core/Providers/ExternalNotificationProvider.cs +++ b/NzbDrone.Core/Providers/ExternalNotificationProvider.cs @@ -8,6 +8,7 @@ using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.ExternalNotification; using NzbDrone.Core.Repository; +using PetaPoco; using SubSonic.Repository; namespace NzbDrone.Core.Providers @@ -15,12 +16,12 @@ namespace NzbDrone.Core.Providers public class ExternalNotificationProvider { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly IRepository _repository; + private readonly IDatabase _database; [Inject] - public ExternalNotificationProvider(IRepository repository) + public ExternalNotificationProvider(IDatabase database) { - _repository = repository; + _database = database; } public ExternalNotificationProvider() @@ -30,7 +31,7 @@ namespace NzbDrone.Core.Providers public virtual List All() { - return _repository.All().ToList(); + return _database.Fetch(); } public virtual void SaveSettings(ExternalNotificationSetting settings) @@ -38,23 +39,24 @@ namespace NzbDrone.Core.Providers if (settings.Id == 0) { Logger.Debug("Adding External Notification settings for {0}", settings.Name); - _repository.Add(settings); + _database.Insert(settings); } + else { Logger.Debug("Updating External Notification settings for {0}", settings.Name); - _repository.Update(settings); + _database.Update(settings); } } public virtual ExternalNotificationSetting GetSettings(Type type) { - return _repository.Single(s => s.NotifierName == type.ToString()); + return _database.SingleOrDefault("WHERE NotifierName = @0", type.ToString()); } public virtual ExternalNotificationSetting GetSettings(int id) { - return _repository.Single(s => s.Id == id); + return _database.SingleOrDefault(id); } public virtual void InitializeNotifiers(IList notifiers) diff --git a/NzbDrone.Core/Repository/ExternalNotificationSetting.cs b/NzbDrone.Core/Repository/ExternalNotificationSetting.cs index 737ebe413..abb30bcd7 100644 --- a/NzbDrone.Core/Repository/ExternalNotificationSetting.cs +++ b/NzbDrone.Core/Repository/ExternalNotificationSetting.cs @@ -2,17 +2,20 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using SubSonic.SqlGeneration.Schema; +using PetaPoco; namespace NzbDrone.Core.Repository { + [TableName("ExternalNotificationSettings")] + [PrimaryKey("Id", autoIncrement = true)] public class ExternalNotificationSetting { - [SubSonicPrimaryKey(true)] public int Id { get; set; } public bool Enabled { get; set; } + public string NotifierName { get; set; } + public string Name { get; set; } } }