public virtual void Process(CreateItemPipelineArgs args) { if (args.Source == null || args.Parent != null) { return; } var source = args.Source; // Determing the template id to use in the target var parentId = (Overrides.ContainsKey(source.ParentId)) ? Overrides[source.ParentId] : source.ParentId; var parent = Sitecore.Context.Database.GetItem(new ID(parentId)); if (parent == null) { Sitecore.Diagnostics.Log.Warn( string.Format("[FieldMigrator] Could not find the parent with id {0} for {1} ({2})", source.ParentId.ToString().ToUpper(), source.Name, source.Id), this); return; } args.Parent = parent; }
public CreateItemPipelineArgs Run(ItemModel source, ID itemId) { var args = new CreateItemPipelineArgs { Source = source, ItemId = itemId }; try { var stopWatch = new Stopwatch(); stopWatch.Start(); CorePipeline.Run("createItem", args, "OneNorth.Migrator"); stopWatch.Stop(); if (args.Item == null) { Sitecore.Diagnostics.Log.Warn(string.Format("[FieldMigrator] (CreateItemPipeline) Did not create: {0} {1} in {2}", source.Id, source.FullPath(x => x.Parent, x => x.Name), stopWatch.Elapsed), this); } else { Sitecore.Diagnostics.Log.Info(string.Format("[FieldMigrator] (CreateItemPipeline) Created: {0} {1} in {2}", args.Item.ID, args.Item.Paths.FullPath, stopWatch.Elapsed), this); } } catch (Exception ex) { Sitecore.Diagnostics.Log.Error(string.Format("[FieldMigrator] (CreateItemPipeline) {0} {1}", source.Id, source.FullPath(x => x.Parent, x => x.Name)), ex, this); } return(args); }
public virtual void Process(CreateItemPipelineArgs args) { if (args.Item != null || ID.IsNullOrEmpty(args.ItemId) || args.Source == null || args.Parent == null || args.Template == null) { return; } args.Item = ItemManager.CreateItem(args.Source.Name, args.Parent, args.Template.ID, args.ItemId, SecurityCheck.Disable); }
public virtual void Process(CreateItemPipelineArgs args) { if (args.Source == null || args.Template != null) { return; } var source = args.Source; // Determing the template id to use in the target TemplateItem template; if (MediaManagerDecidesMediaItemTemplates && source.IsMediaItem) { // Grab extension var extensionField = source.Versions.SelectMany(x => x.Fields) .FirstOrDefault(x => string.Equals(x.Name, "Extension", StringComparison.OrdinalIgnoreCase)); if (extensionField == null) { return; } var extension = extensionField.Value; var versioned = Sitecore.Configuration.Settings.Media.UploadAsVersionableByDefault; var templateFullName = MediaManager.Config.GetTemplate(extension, versioned); template = Context.Database.GetTemplate(templateFullName); } else { var templateId = Overrides.ContainsKey(source.TemplateId) ? Overrides[source.TemplateId] : source.TemplateId; template = Context.Database.GetTemplate(new ID(templateId)); } if (template == null) { Sitecore.Diagnostics.Log.Warn( string.Format("[FieldMigrator] Could not find the template for {0} ({1})", source.FullPath(x => x.Parent, x => x.Name), source.Id), this); return; } args.Template = template; }
public virtual void Process(CreateItemPipelineArgs args) { if (args.Source == null || args.Parent != null || args.Template == null) { return; } var source = args.Source; // Determine if the parent already exists. If it does, there is nothing to do. args.Parent = Sitecore.Context.Database.GetItem(new ID(source.ParentId)); if (args.Parent != null) { return; } Item parent = null; // Work backwards ensuring folders exist, skipping the current item var firstVersion = source.Versions.First(); var path = _hardRockWebServiceProxy.GetFullPath(source.Id, firstVersion.Language, firstVersion.Version); // Get folder type based on location var folderTemplateId = (path.Any(f => f.Id == ItemIDs.MediaLibraryRoot.Guid)) ? TemplateIDs.MediaFolder : TemplateIDs.Folder; // Find first ancestor that exists var count = path.Count; var index = 2; //Skip the first 2 (self and parent) while (index < count) { parent = Sitecore.Context.Database.GetItem(new ID(path[index].Id)); if (parent != null) { break; } index++; } // Move to the first missing parent index--; // Create the parents, furthest to closest while (index > 0) { var folder = path[index]; // Create the folder. This becomes the parent for the next item parent = ItemManager.CreateItem(folder.Name, parent, folderTemplateId, new ID(folder.Id), SecurityCheck.Disable); // Add at least 1 version if (!string.IsNullOrEmpty(DefaultLanguage)) { var language = LanguageManager.GetLanguage(DefaultLanguage); parent = (parent.Language == language) ? parent : parent.Database.GetItem(parent.ID, language); // Create version if it does not exist if (parent.Versions.Count == 0) { var disableFiltering = Sitecore.Context.Site.DisableFiltering; try { Sitecore.Context.Site.DisableFiltering = true; parent = parent.Versions.AddVersion(); } finally { Sitecore.Context.Site.DisableFiltering = disableFiltering; } } } Sitecore.Diagnostics.Log.Debug(string.Format("[FieldMigrator] Created: {0}", parent.Paths.FullPath), this); index--; } args.Parent = parent; }