From 81e385f7beb122857d866fef57bbaa18ee297a0c Mon Sep 17 00:00:00 2001 From: Dmitry Dzygin Date: Thu, 1 Mar 2018 11:58:42 +0100 Subject: [PATCH] Fix #542 Exception in the log files when C1 tries to unpublish a data item that has been previously deleted --- .../Scheduling/DataPublishSchedulerWorkflow.cs | 14 ++++++++++---- .../Scheduling/DataUnpublishSchedulerWorkflow.cs | 16 +++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Composite.Workflows/C1Console/Scheduling/DataPublishSchedulerWorkflow.cs b/Composite.Workflows/C1Console/Scheduling/DataPublishSchedulerWorkflow.cs index c5fa9e2081..d8506b1756 100644 --- a/Composite.Workflows/C1Console/Scheduling/DataPublishSchedulerWorkflow.cs +++ b/Composite.Workflows/C1Console/Scheduling/DataPublishSchedulerWorkflow.cs @@ -36,8 +36,14 @@ protected override void Execute() var publishSchedule = PublishScheduleHelper.GetPublishSchedule(type, DataId, LocaleName); DataFacade.Delete(publishSchedule); - var data = (IPublishControlled)DataFacade.GetDataByUniqueKey(type, DataId); - Verify.IsNotNull(data, "The data with the id '{0}' does not exist", DataId); + var data = (IPublishControlled)DataFacade.TryGetDataByUniqueKey(type, DataId); + if (data == null) + { + Log.LogWarning(LogTitle, $"Failed to find data of type '{type}' by id '{DataId}'."); + + transaction.Complete(); + return; + } dataEntityToken = data.GetDataEntityToken(); @@ -49,11 +55,11 @@ protected override void Execute() DataFacade.Update(data); - Log.LogVerbose(LogTitle, "Scheduled publishing of data with label '{0}' is complete", data.GetLabel()); + Log.LogVerbose(LogTitle, $"Scheduled publishing of data with label '{data.GetLabel()}' is complete"); } else { - Log.LogWarning(LogTitle, "Scheduled publishing of data with label '{0}' could not be done because the data is not in a publisheble state", data.GetLabel()); + Log.LogWarning(LogTitle, $"Scheduled publishing of data with label '{data.GetLabel()}' could not be done because the data is not in a publisheble state"); } transaction.Complete(); diff --git a/Composite.Workflows/C1Console/Scheduling/DataUnpublishSchedulerWorkflow.cs b/Composite.Workflows/C1Console/Scheduling/DataUnpublishSchedulerWorkflow.cs index d9be03a759..1dedbee6e5 100644 --- a/Composite.Workflows/C1Console/Scheduling/DataUnpublishSchedulerWorkflow.cs +++ b/Composite.Workflows/C1Console/Scheduling/DataUnpublishSchedulerWorkflow.cs @@ -37,10 +37,16 @@ protected override void Execute() DataFacade.Delete(unpublishSchedule); - var deletePublished = false; + var data = (IPublishControlled)DataFacade.TryGetDataByUniqueKey(type, DataId); + if (data == null) + { + Log.LogWarning(LogTitle, $"Failed to find data of type '{type}' by id '{DataId}'."); - var data = (IPublishControlled)DataFacade.GetDataByUniqueKey(type, DataId); - Verify.IsNotNull(data, "The data with the id {0} does not exist", DataId); + transaction.Complete(); + return; + } + + var deletePublished = false; dataEntityToken = data.GetDataEntityToken(); @@ -56,7 +62,7 @@ protected override void Execute() } else { - Log.LogWarning(LogTitle, "Scheduled unpublishing of data with label '{0}' could not be done because the data is not in a unpublisheble state", data.GetLabel()); + Log.LogWarning(LogTitle, $"Scheduled unpublishing of data with label '{data.GetLabel()}' could not be done because the data is not in a unpublisheble state"); } @@ -69,7 +75,7 @@ protected override void Execute() { DataFacade.Delete(deletedData, CascadeDeleteType.Disable); - Log.LogVerbose(LogTitle, "Scheduled unpublishing of data with label '{0}' is complete", deletedData.GetLabel()); + Log.LogVerbose(LogTitle, $"Scheduled unpublishing of data with label '{deletedData.GetLabel()}' is complete"); } } }