public Item Duplicate(ClientPipelineArgs args, Item sourceItem) { Item result = null; if (sourceItem == null) { SheerResponse.Alert(Translate.Text("Item not found.")); } else { Item parent = sourceItem.Parent; if (parent == null) { SheerResponse.Alert(Translate.Text("Cannot duplicate the root item.")); } else if (parent.Access.CanCreate()) { Log.Audit(this, "Duplicate item: {0}", new string[1] { AuditFormatter.FormatItem(sourceItem) }); var bucketItemOrSiteRoot = sourceItem.GetParentBucketItemOrSiteRoot(); if (BucketManager.IsBucket(bucketItemOrSiteRoot) && BucketManager.IsBucketable(sourceItem)) { if (!EventDisabler.IsActive) { EventResult eventResult = Event.RaiseEvent("item:bucketing:duplicating", args, this); if (eventResult != null && eventResult.Cancel) { Log.Info(string.Format("Event {0} was cancelled", "item:bucketing:duplicating"), this); args.AbortPipeline(); return(null); } } result = Context.Workflow.DuplicateItem(sourceItem, args.Parameters["name"]); Item destination = CreateAndReturnBucketFolderDestination(bucketItemOrSiteRoot, DateUtil.ToUniversalTime(DateTime.Now), sourceItem); if (!IsBucketTemplateCheck(sourceItem)) { destination = bucketItemOrSiteRoot; } ItemManager.MoveItem(result, destination); if (!EventDisabler.IsActive) { Event.RaiseEvent("item:bucketing:duplicated", args, this); } } else { result = Context.Workflow.DuplicateItem(sourceItem, args.Parameters["name"]); } } else { SheerResponse.Alert(Translate.Text("You do not have permission to duplicate \"{0}\".", sourceItem.DisplayName)); } } args.AbortPipeline(); return(result); }
public void OnItemSaved(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); Item item = Event.ExtractParameter(args, 0) as Item; if (item == null || !BucketManager.IsBucketable(item) || IsPublish()) { return; } Item bucketRoot = GetBucketRoot(item); if (bucketRoot != null && BucketManager.IsBucket(bucketRoot)) { if (!IsAlreadyOnItsPlace(item, bucketRoot)) { BucketManager.MoveItemIntoBucket(item, bucketRoot); } } }