private static void DeleteNlm(INlmExportService exportService, ArticleItem articleItem) { if (!exportService.DeleteNlm(articleItem)) { // NLM Delete failed SheerResponse.Alert("The deletion XML file could not be generated."); return; } SheerResponse.Alert("The article has been successfully exported for deletion."); }
protected override void Run(PublishItemContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } try { _logger.Debug("Export to NLM started on Publish. Context.Action = [" + context.Action + "]."); var itemId = context.ItemId; var sourceItem = context.VersionToPublish ?? context.PublishOptions.SourceDatabase.GetItem(itemId); var targetItem = context.PublishOptions.TargetDatabase.GetItem(itemId); // Check if the current item is actually an Article item if (sourceItem == null || sourceItem.TemplateID != IArticleConstants.TemplateId) { _logger.Debug($"Skipping NLM export for item (not an article): '{itemId}'"); return; } switch (context.Action) { // Handle 'Delete' Publish case PublishAction.DeleteTargetItem: { var database = _serviceFactory(context.PublishOptions.TargetDatabase); var article = database.Cast <ArticleItem>(targetItem); // Export a _del.xml file _exportService.DeleteNlm(article); _logger.Info($"Exported NLM delete for article: '{itemId}'"); } break; // Handle 'New Version' Publish case PublishAction.PublishVersion: { var database = _serviceFactory(context.PublishOptions.SourceDatabase); var article = database.Cast <ArticleItem>(sourceItem); var isFirstScheduledPublishForItem = !_publishHistory.Find(sourceItem.ID.Guid).Any(); // Check if the current article is migrated content. If so, don't generate NLM if (!string.IsNullOrEmpty(article.Legacy_Article_Number)) { _logger.Info($"Skipping NLM export for article {article.Article_Number} (article is a legacy PMBI article {article.Legacy_Article_Number}): article ID - '{itemId}'"); return; } if (!string.IsNullOrEmpty(article.Escenic_ID)) { _logger.Info($"Skipping NLM export for article {article.Article_Number} (article is legacy Escenic article {article.Escenic_ID}): article ID - '{itemId}'"); return; } if (!isFirstScheduledPublishForItem) { _logger.Info($"Skipping NLM export for item (article already published via Scheduled Publishing): '{itemId}'"); return; } // Export the article as an NLM file _exportService.ExportNlm(article, ExportType.Scheduled); context.AddMessage($"NLM export of article '{itemId}' was successful."); } break; } _logger.Debug("Export to NLM ended on Publish."); } catch (Exception ex) { _logger.Error($"Unexpected error occurred while exporting Article ID {context.ItemId} on publish.", ex); } }