private IItemModelRepository GetItemModelRepository(PipelineStep pipelineStep, PipelineContext pipelineContext) { UpdateSitecoreItemSettings settings = pipelineStep.GetPlugin <UpdateSitecoreItemSettings>(); if (settings == null) { return(null); } Endpoint endpointTo = settings.EndpointFrom; if (endpointTo == null) { return(null); } ItemModelRepositorySettings repositorySettings = endpointTo.GetItemModelRepositorySettings(); if (repositorySettings == null) { return(null); } return(repositorySettings.ItemModelRepository); }
protected override object ResolveObject(object identifierValue, Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext) { if (identifierValue == null) { throw new ArgumentException("The value cannot be null.", "identifierValue"); } if (endpoint == null) { throw new ArgumentNullException("endpoint"); } if (pipelineStep == null) { throw new ArgumentNullException("pipelineStep"); } if (pipelineContext == null) { throw new ArgumentNullException("pipelineContext"); } ItemModelRepositorySettings repositorySettings = endpoint.GetItemModelRepositorySettings(); if (repositorySettings == null) { return((object)null); } IItemModelRepository itemModelRepository = repositorySettings.ItemModelRepository; if (itemModelRepository == null) { return((object)null); } ResolveSitecoreItemSettings sitecoreItemSettings = pipelineStep.GetResolveSitecoreItemSettings(); if (sitecoreItemSettings == null) { return((object)null); } ResolveObjectSettings resolveObjectSettings = pipelineStep.GetResolveObjectSettings(); if (resolveObjectSettings == null) { return((object)null); } ResolveSitecoreItemWithLanguageSettings languageSettings = pipelineStep.GetPlugin <ResolveSitecoreItemWithLanguageSettings>(); if (languageSettings == null) { return((ItemModel)null); } ItemModel sourceAsItemModel = this.GetSourceObjectAsItemModel(pipelineStep, pipelineContext); if (sourceAsItemModel == null) { return((ItemModel)null); } var language = sourceAsItemModel[languageSettings.LanguageField].ToString(); ILogger logger = pipelineContext.Logger; RepositoryObjectStatus status = RepositoryObjectStatus.DoesNotExist; ItemModel itemModel = this.DoSearch(identifierValue, sitecoreItemSettings, itemModelRepository, logger, pipelineContext); if (itemModel != null) { this.Log(new Action <string>(pipelineContext.Logger.Debug), pipelineContext, "Item was resolved.", string.Format("identifier: {0}", identifierValue), string.Format("item id: {0}", itemModel["ItemID"])); Sitecore.Diagnostics.Log.Error($"Item was resolved with identifierValue: {identifierValue} item id: {itemModel["ItemID"]}", this); status = RepositoryObjectStatus.Exists; } if (itemModel == null && !resolveObjectSettings.DoNotCreateIfObjectNotResolved) { this.Log(new Action <string>(logger.Debug), pipelineContext, "Item was not resolved. Will create it.", string.Format("identifier: {0}", identifierValue)); Sitecore.Diagnostics.Log.Error($"Item was not resolved. Will create it: {identifierValue} ", this); itemModel = this.CreateNewItem(this.GetIdentifierObject(pipelineStep, pipelineContext), itemModelRepository, sitecoreItemSettings, logger, pipelineContext, language); if (itemModel == null) { this.Log(new Action <string>(logger.Error), pipelineContext, "Unable to create new item.", string.Format("identifier: {0}", identifierValue)); Sitecore.Diagnostics.Log.Error($"Unable to create new item with identifierValue: {identifierValue} ", this); } else { this.Log(new Action <string>(logger.Debug), pipelineContext, "New item was created.", string.Format("identifier: {0}", identifierValue)); Sitecore.Diagnostics.Log.Info($"Create new item with identifierValue: {identifierValue} ", this); } } this.SetRepositoryStatusSettings(status, pipelineContext); return((object)itemModel); }