From 0bc4903954b955fce0c368ef7fd2a6f3761d6a93 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 17 Oct 2024 04:46:15 +0300 Subject: [PATCH] Inherit trigger from pushed command models --- .../Messaging/Commands/CommandQueueManager.cs | 7 ++++--- src/Sonarr.Api.V3/Commands/CommandController.cs | 3 +-- src/Sonarr.Api.V3/Series/SeriesController.cs | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs b/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs index 7be373e79..6f7f6d705 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs @@ -106,6 +106,8 @@ namespace NzbDrone.Core.Messaging.Commands _logger.Trace("Publishing {0}", command.Name); _logger.Trace("Checking if command is queued or started: {0}", command.Name); + command.Trigger = trigger; + lock (_commandQueue) { var existingCommands = QueuedOrStarted(command.Name); @@ -142,7 +144,6 @@ namespace NzbDrone.Core.Messaging.Commands var command = GetCommand(commandName); command.LastExecutionTime = lastExecutionTime; command.LastStartTime = lastStartTime; - command.Trigger = trigger; return Push(command, priority, trigger); } @@ -244,13 +245,13 @@ namespace NzbDrone.Core.Messaging.Commands _repo.Trim(); } - private dynamic GetCommand(string commandName) + private Command GetCommand(string commandName) { commandName = commandName.Split('.').Last(); var commands = _knownTypes.GetImplementations(typeof(Command)); var commandType = commands.Single(c => c.Name.Equals(commandName, StringComparison.InvariantCultureIgnoreCase)); - return Json.Deserialize("{}", commandType); + return Json.Deserialize("{}", commandType) as Command; } private void Update(CommandModel command, CommandStatus status, string message) diff --git a/src/Sonarr.Api.V3/Commands/CommandController.cs b/src/Sonarr.Api.V3/Commands/CommandController.cs index 980a6f875..a0203eb09 100644 --- a/src/Sonarr.Api.V3/Commands/CommandController.cs +++ b/src/Sonarr.Api.V3/Commands/CommandController.cs @@ -66,9 +66,8 @@ namespace Sonarr.Api.V3.Commands ? CommandPriority.High : CommandPriority.Normal; - dynamic command = STJson.Deserialize(body, commandType); + var command = STJson.Deserialize(body, commandType) as Command; - command.Trigger = CommandTrigger.Manual; command.SuppressMessages = !command.SendUpdatesToClient; command.SendUpdatesToClient = true; command.ClientUserAgent = Request.Headers["UserAgent"]; diff --git a/src/Sonarr.Api.V3/Series/SeriesController.cs b/src/Sonarr.Api.V3/Series/SeriesController.cs index 72bf0ee41..7122af7e9 100644 --- a/src/Sonarr.Api.V3/Series/SeriesController.cs +++ b/src/Sonarr.Api.V3/Series/SeriesController.cs @@ -190,9 +190,8 @@ namespace Sonarr.Api.V3.Series { SeriesId = series.Id, SourcePath = sourcePath, - DestinationPath = destinationPath, - Trigger = CommandTrigger.Manual - }); + DestinationPath = destinationPath + }, trigger: CommandTrigger.Manual); } var model = seriesResource.ToModel(series);