/// <summary> /// Get Import items from specified start path, template id and year /// </summary> /// <returns></returns> public override IEnumerable <object> GetImportData() { var startItem = FromDB.GetItem(StartPath); var articles = Enumerable.Empty <Item>(); if (startItem != null) { var sw = new Stopwatch(); sw.Start(); if (!string.IsNullOrWhiteSpace(Year)) { articles = startItem.Axes.GetDescendants() .Where(i => i.TemplateID.ToString() == TemplateId && i.Fields[ArticleDate].Value.Contains(Year) && !PublisherSpotlights.Contains(i.Fields[ArticleCategory].Value)); } else { articles = startItem.Axes.GetDescendants() .Where(i => i.TemplateID.ToString() == TemplateId && !PublisherSpotlights.Contains(i.Fields[ArticleCategory].Value)); } sw.Stop(); Logger.Log("Performance Statistic-(Sitecore.SharedSource.DataImporter.Providers.PmbiDataMap.GetImportData)", $"Used {sw.Elapsed.TotalSeconds} to Find matches"); } return(articles); }
private Item GetLastPublishableVersion(Item oldItem, Language oldLanguage) { var oldLangItem = FromDB.GetItem(oldItem.ID, oldLanguage); string wfIdString = oldLangItem.Fields[FieldIDs.WorkflowState].Value; if (!string.IsNullOrEmpty(wfIdString)) { Item wftarget = FromDB.GetItem(wfIdString); if (wftarget?.Fields[WorkflowFieldIDs.FinalState]?.Value == "1") { return(oldLangItem); } } else { return(oldLangItem); } foreach (Item oldVersion in oldLangItem.Versions.GetOlderVersions().Reverse().Skip(1)) { string oldWfIdString = oldVersion.Fields[FieldIDs.WorkflowState].Value; if (!string.IsNullOrEmpty(oldWfIdString)) { Item wftarget = FromDB.GetItem(oldWfIdString); if (wftarget?.Fields[WorkflowFieldIDs.FinalState]?.Value == "1") { return(oldVersion); } } } return(oldLangItem); }
/// <summary> /// gets a field value from an item /// </summary> /// <param name="importRow"></param> /// <param name="fieldName"></param> /// <returns></returns> public override string GetFieldValue(object importRow, string fieldName) { //check for tokens if (fieldName.Equals("$name")) { return(((Item)importRow).Name); } Item item = importRow as Item; Item langItem = FromDB.GetItem(item.ID, ImportFromLanguage); Field f = langItem.Fields[fieldName]; return((f != null) ? langItem[fieldName] : string.Empty); }
private HashSet <string> GetAllTaxonomy(string id) { var startItem = FromDB.GetItem(new ID(id)); var result = new HashSet <string> { id }; if (startItem != null) { var descendants = startItem.Axes.GetDescendants().Select(i => i.ID.ToString()).ToList(); if (descendants.Any()) { result.UnionWith(descendants); } } return(result); }
/// <summary> /// uses the sitecore database and xpath query to retrieve data /// </summary> /// <returns></returns> public override IEnumerable <object> GetImportData() { var items = new List <object>(); foreach (var query in Query.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { if (Guid.TryParse(query, out var id)) { Logger.Log("SitecoreDataMap.GetImportData", string.Format("Adding item: {0}", id)); items.Add(FromDB.GetItem(new ID(id))); continue; } Logger.Log("SitecoreDataMap.GetImportData", string.Format("Running query: {0}", query)); items.AddRange(FromDB.SelectItems(query)); } return(items); }
public void TransferMediaLibrary() { var sourcePath = ImportItem.Fields[MediaSourcePath].Value; var destinationPath = ImportItem.Fields[MediaDestinationPath].Value; var sourceItem = FromDB.GetItem(sourcePath); var destinationItem = Database.GetDatabase("master").GetItem(destinationPath); if (sourceItem != null && destinationItem != null) { using (new ProxyDisabler()) { var defaultOptions = ItemSerializerOptions.GetDefaultOptions(); defaultOptions.AllowDefaultValues = false; defaultOptions.AllowStandardValues = false; defaultOptions.ProcessChildren = true; TransferMediaItem(sourceItem, destinationItem, defaultOptions); } } }
public MediaItem HandleMedia(IDataMap map, string itemPath, string url) { Assert.IsNotNull(map, "map"); Assert.IsNotNull(itemPath, "itemPath"); Assert.IsNotNull(url, "url"); //get file info if (!url.StartsWith("~/media/") && !url.StartsWith("/~/media/") && !url.StartsWith("~/link.aspx?_id=")) { return(null); } var id = url.Replace("/~/media/", string.Empty).Replace("~/media/", string.Empty).Replace("~/link.aspx?_id=", string.Empty).Split(new[] { '.', '&' }).FirstOrDefault(); var guid = Guid.Empty; var originalItem = FromDB.GetItem(Guid.TryParse(id, out guid) ? new ID(guid).ToString() : $"/sitecore/media library/{id.Replace("-", " ")}"); if (originalItem == null || !originalItem.Paths.IsMediaItem) { return(null); } return(MediaService.FindOrCreateMediaItem(map, originalItem)); }