예제 #1
0
        protected virtual Item GetBucketRoot(Item item)
        {
            var current = item;

            do
            {
                current = current.Parent;
            }while (current != null && current.Parent != null && !BucketManager.IsBucket(current));

            return(current);
        }
예제 #2
0
        public new void Execute(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var database = Factory.GetDatabase(args.Parameters["database"]);

            Assert.IsNotNull(database, args.Parameters["database"]);
            var str  = args.Parameters["id"];
            var item = database.Items[str];

            if (item.IsNull())
            {
                SheerResponse.Alert("Item not found.", new string[0]);
                args.AbortPipeline();
            }
            else
            {
                var parent = item.Parent;
                if (parent.IsNull())
                {
                    SheerResponse.Alert("Cannot duplicate the root item.", new string[0]);
                    args.AbortPipeline();
                }
                else if (parent.Access.CanCreate())
                {
                    Log.Audit(this, "Duplicate item: {0}", new[] { AuditFormatter.FormatItem(item) });

                    var parentBucketOfItem = item.GetNearestParentBucketItemOrSiteRoot();
                    if (BucketManager.IsBucket(parentBucketOfItem))
                    {
                        var duplicatedItem = Context.Workflow.DuplicateItem(item, args.Parameters["name"]);
                        var newDestination = BucketManager.CreateAndReturnDateFolderDestination(parentBucketOfItem, DateTime.Now);
                        if (!item.Template.IsBucketTemplateCheck())
                        {
                            newDestination = parentBucketOfItem;
                        }
                        Event.RaiseEvent("item:bucketing:duplicating", args, this);
                        ItemManager.MoveItem(duplicatedItem, newDestination);
                        Event.RaiseEvent("item:bucketing:duplicated", args, this);
                        Log.Info("Item " + duplicatedItem.ID + " has been duplicated to another bucket", this);
                    }
                    else
                    {
                        Context.Workflow.DuplicateItem(item, args.Parameters["name"]);
                    }
                }
                else
                {
                    SheerResponse.Alert(Translate.Text("You do not have permission to duplicate \"{0}\".", new object[] { item.DisplayName }), new string[0]);
                    args.AbortPipeline();
                }
            }

            args.AbortPipeline();
        }
        public new void Execute(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var contentDatabase = Context.ContentDatabase;

            if (BucketManager.IsBucket(contentDatabase.GetItem(args.Parameters["target"])))
            {
                var item = contentDatabase.GetItem(args.Parameters["items"]);
                Event.RaiseEvent("item:bucketing:moving", args, this);
                Shell.Applications.Dialogs.ProgressBoxes.ProgressBox.Execute("Moving Items", "Moving Items", Images.GetThemedImageSource("Business/16x16/chest_add.png"), this.StartProcess, new object[] { item, BucketManager.CreateAndReturnDateFolderDestination(contentDatabase.GetItem(args.Parameters["target"]), DateTime.Now) });
                Event.RaiseEvent("item:bucketing:moved", args, this);
                Log.Info("Item " + item.ID + " has been moved to another bucket", this);
                Context.ClientPage.SendMessage(this, "item:refreshchildren(id=" + item.Parent.ID + ")");
                args.AbortPipeline();
            }
        }
예제 #4
0
        public override void Process(HttpRequestArgs args)
        {
            try
            {
                if (Context.Item == null)
                {
                    var requestUrl = args.Url.ItemPath;

                    // remove last element from path and see if resulting pathis a bucket
                    var index = requestUrl.LastIndexOf('/');
                    if (index > 0)
                    {
                        var bucketPath = requestUrl.Substring(0, index);
                        var bucketItem = args.GetItem(bucketPath);

                        if (bucketItem != null && BucketManager.IsBucket(bucketItem))
                        {
                            string itemName = requestUrl.Substring(index + 1);
                            if (!string.IsNullOrEmpty(itemName))
                            {
                                itemName = MainUtil.DecodeName(itemName);
                            }
                            // locate item in bucket by name
                            using (var context = ContentSearchManager.GetIndex(Constants.CustomIndex).CreateSearchContext())
                            {
                                var result = context.GetQueryable <SearchResultItem>().Where(x => x.Name == itemName).FirstOrDefault();
                                if (result != null)
                                {
                                    Context.Item = args.GetItem(result.ItemId);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error(ex.Message, ex, this);
            }
        }
예제 #5
0
파일: SyncBucket.cs 프로젝트: trowpa/WeBlog
        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);
                }
            }
        }
        public new void Execute(ClientPipelineArgs args)
        {
            Event.RaiseEvent("item:bucketing:dragInto", args, this);
            Assert.ArgumentNotNull(args, "args");
            Database database = GetDatabase(args);
            Item     source   = GetSource(args, database);
            Item     target   = GetTarget(args);

            if (args.Parameters["copy"] == "1")
            {
                if (BucketManager.IsBucket(target))
                {
                    Shell.Applications.Dialogs.ProgressBoxes.ProgressBox.Execute("Copying Items", "Copying Items",
                                                                                 Images.GetThemedImageSource(
                                                                                     "Business/16x16/chest_add.png"),
                                                                                 this.StartProcess,
                                                                                 new object[]
                    {
                        source,
                        BucketManager.
                        CreateAndReturnDateFolderDestination
                            (target, DateTime.Now), true, args
                    });

                    if (source.IsNotNull())
                    {
                        Log.Info("Item " + source.ID + " has been copied to another bucket", this);
                    }
                }
            }
            else
            {
                if (BucketManager.IsBucket(target))
                {
                    Shell.Applications.Dialogs.ProgressBoxes.ProgressBox.Execute("Moving Items", "Moving Items",
                                                                                 Images.GetThemedImageSource(
                                                                                     "Business/16x16/chest_add.png"),
                                                                                 this.StartMoveProcess,
                                                                                 new object[]
                    {
                        source,
                        BucketManager.
                        CreateAndReturnDateFolderDestination
                            (target, DateTime.Now), args
                    });
                }
            }


            Event.RaiseEvent("item:bucketing:dragged", args, this);

            //Assert.ArgumentNotNull(args, "args");
            //var items = GetItems(args);
            //Item currentItem = null;
            //if (items[0].IsNotNull())
            //{
            //    currentItem = items[0];
            //}

            //Error.AssertItem(items[0], "Item");
            //var database = GetDatabase(args);
            //var topParent = database.GetItem(args.Parameters["destination"]);
            //if (BucketManager.IsBucket(topParent))
            //{
            //    Shell.Applications.Dialogs.ProgressBoxes.ProgressBox.Execute("Copying Items", "Copying Items", Images.GetThemedImageSource("Business/16x16/chest_add.png"), this.StartProcess, new object[] { currentItem, BucketManager.CreateAndReturnDateFolderDestination(topParent, DateTime.Now), true });

            //    if (currentItem.IsNotNull())
            //    {
            //        Log.Info("Item " + currentItem.ID + " has been copied to another bucket", this);
            //    }

            //    Event.RaiseEvent("item:bucketing:copied", args, this);
            //    args.AbortPipeline();
            //}
        }
        protected void Add(ClientPipelineArgs args)
        {
            if (!SheerResponse.CheckModified())
            {
                return;
            }

            Item masterItem = Context.ContentDatabase.GetItem(args.Parameters["Master"]);

            if (masterItem == null)
            {
                SheerResponse.Alert(Translate.Text("Branch \"{0}\" not found.", (object)args.Parameters["Master"]));
            }

            else if (masterItem.TemplateID == TemplateIDs.CommandMaster)
            {
                string message = masterItem["Command"];
                if (string.IsNullOrEmpty(message))
                {
                    return;
                }

                Context.ClientPage.SendMessage((object)this, message);
            }
            else if (args.IsPostBack)
            {
                if (!args.HasResult)
                {
                    return;
                }

                Item parent = Context.ContentDatabase.Items[StringUtil.GetString(args.Parameters["ItemID"]), Language.Parse(StringUtil.GetString(args.Parameters["Language"]))];

                if (parent == null)
                {
                    SheerResponse.Alert("Parent item not found.");
                }

                else if (!parent.Access.CanCreate())
                {
                    Context.ClientPage.ClientResponse.Alert("You do not have permission to create items here");
                }
                else
                {
                    try
                    {
                        if (masterItem.TemplateID == TemplateIDs.BranchTemplate)
                        {
                            BranchItem branch = (BranchItem)masterItem;
                            Context.Workflow.AddItem(args.Result, branch, parent);
                        }
                        else
                        {
                            TemplateItem template = (TemplateItem)masterItem;
                            Context.Workflow.AddItem(args.Result, template, parent);
                        }
                    } catch (WorkflowException ex)
                    {
                        Log.Error("Workflow error: could not add item from master", (Exception)ex, (object)this);
                        SheerResponse.Alert(ex.Message);
                    }
                }
            }
            else
            {
                if (BucketManager.IsBucket(masterItem))
                {
                    var url = new UrlString(UIUtil.GetUri("control:AddMasterDialog"));

                    url["id"]      = args.Parameters["ItemID"];
                    url["lang"]    = args.Parameters["Language"];
                    url["master"]  = args.Parameters["Master"];
                    url["version"] = args.Parameters["Version"];

                    SheerResponse.ShowModalDialog(url.ToString());
                }
                else
                {
                    SheerResponse.Input("Enter a name for the new item***:", masterItem.DisplayName, Settings.ItemNameValidation, "'$Input' is not a valid name.", Settings.MaxItemNameLength);
                }

                args.WaitForPostBack();
            }
        }
예제 #8
0
        private List <SitemapItem> GetSitemapItems(string rootPath)
        {
            string disTpls = _config.EnabledTemplates;

            Database database = Factory.GetDatabase(SitemapManagerConfiguration.WorkingDatabase);

            Item contentRoot = database.Items[rootPath];

            IEnumerable <Item> descendants;

            Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(Constants.SitemapParserUser, true);
            using (new Sitecore.Security.Accounts.UserSwitcher(user))
            {
                descendants = contentRoot.Axes.GetDescendants()
                              .Where(i => i[Settings.GetSetting("Sitemap.Fields.ExcludeItemFromSitemap", "Exclude From Sitemap")] != "1");
            }

            // getting shared content
            var sharedModels      = new List <SitemapItem>();
            var sharedDefinitions = Db.SelectItems(string.Format("fast:{0}/*", _config.SitemapConfigurationItemPath));
            var site             = Factory.GetSite(_config.SiteName);
            var enabledTemplates = BuildListFromString(disTpls, '|');

            foreach (var sharedDefinition in sharedDefinitions)
            {
                if (string.IsNullOrWhiteSpace(sharedDefinition[Constants.SharedContent.ContentLocationFieldName]) ||
                    string.IsNullOrWhiteSpace(sharedDefinition[Constants.SharedContent.ParentItemFieldName]))
                {
                    continue;
                }
                var contentLocation = ((DatasourceField)sharedDefinition.Fields[Constants.SharedContent.ContentLocationFieldName]).TargetItem;
                var parentItem      = ((DatasourceField)sharedDefinition.Fields[Constants.SharedContent.ParentItemFieldName]).TargetItem;
                var sharedItems     = new List <Item>();
                if (BucketManager.IsBucket(contentLocation))
                {
                    var index = ContentSearchManager.GetIndex(new SitecoreIndexableItem(contentLocation));
                    using (var searchContext = index.CreateSearchContext())
                    {
                        var searchResultItem =
                            searchContext.GetQueryable <SearchResultItem>()
                            .Where(item => item.Paths.Contains(contentLocation.ID) && item.ItemId != contentLocation.ID)
                            .ToList();
                        sharedItems.AddRange(searchResultItem.Select(i => i.GetItem()));
                    }
                }
                else
                {
                    sharedItems.AddRange(contentLocation.Axes.GetDescendants());
                }

                var cleanedSharedItems = from itm in sharedItems
                                         where itm.Template != null && enabledTemplates.Select(t => t.ToLower()).Contains(itm.Template.ID.ToString().ToLower())
                                         select itm;
                var sharedSitemapItems = cleanedSharedItems.Select(i => new SitemapItem(i, site, parentItem));
                sharedModels.AddRange(sharedSitemapItems);
            }

            var sitemapItems = descendants.ToList();

            sitemapItems.Insert(0, contentRoot);

            var selected = from itm in sitemapItems
                           where itm.Template != null && enabledTemplates.Contains(itm.Template.ID.ToString())
                           select itm;

            var selectedModels = selected.Select(i => new SitemapItem(i, site, null)).ToList();

            selectedModels.AddRange(sharedModels);
            selectedModels = selectedModels.OrderBy(u => u.Priority).Take(int.Parse(Settings.GetSetting("Sitemap.UrlLimit", "1000"))).ToList();
            return(selectedModels);
        }
 /// <summary>
 /// This checks if the item being added is of a template type that will be bucketed and
 /// if the creation destination is a bucket item itself
 /// </summary>
 /// <returns>True if it can be added. False if it cannot.</returns>
 private bool CanAddToBucket()
 {
     return(BucketManager.IsTemplateBucketable(this.TemplateId, this.Database) && BucketManager.IsBucket(this.Destination));
 }
예제 #10
0
        private List <SitemapItem> GetSitemapItems(string rootPath)
        {
            var disTpls           = _config.EnabledTemplates;
            var excludeItemsField = _config.ExcludedItems;

            var database = Factory.GetDatabase(SitemapManagerConfiguration.WorkingDatabase);

            //Get the content root item
            var contentRoot = database.Items[rootPath];

            //Get the descendents of the content root
            IEnumerable <Item> descendants;
            var user = Sitecore.Security.Accounts.User.FromName(Constants.SitemapParserUser, true);

            using (new Sitecore.Security.Accounts.UserSwitcher(user))
            {
                descendants = contentRoot.Axes.GetDescendants()
                              .Where(i => i[Constants.XmlSettings.ExcludeItemFromSitemap] != "1");
            }

            // getting shared content
            //TODO: Unverified and un-tested. Might need some modifications before it can be used.
            var sharedModels      = new List <List <SitemapItem> >();
            var sharedDefinitions = Db.SelectItems(string.Format("fast:{0}/*", _config.SitemapConfigurationItemPath).Replace("-", "#-#"));
            var site             = Factory.GetSite(_config.SiteName);
            var enabledTemplates = BuildListFromString(disTpls, '|');
            var excludeItems     = BuildListFromString(excludeItemsField, '|');

            foreach (var sharedDefinition in sharedDefinitions)
            {
                if (string.IsNullOrWhiteSpace(sharedDefinition[Constants.SharedContent.ContentLocationFieldName]) ||
                    string.IsNullOrWhiteSpace(sharedDefinition[Constants.SharedContent.ParentItemFieldName]))
                {
                    continue;
                }
                var contentLocation = ((DatasourceField)sharedDefinition.Fields[Constants.SharedContent.ContentLocationFieldName]).TargetItem;
                var parentItem      = ((DatasourceField)sharedDefinition.Fields[Constants.SharedContent.ParentItemFieldName]).TargetItem;
                var sharedItems     = new List <Item>();
                if (BucketManager.IsBucket(contentLocation))
                {
                    var index = ContentSearchManager.GetIndex(new SitecoreIndexableItem(contentLocation));
                    using (var searchContext = index.CreateSearchContext())
                    {
                        var searchResultItem =
                            searchContext.GetQueryable <SearchResultItem>()
                            .Where(item => item.Paths.Contains(contentLocation.ID) && item.ItemId != contentLocation.ID)
                            .ToList();
                        sharedItems.AddRange(searchResultItem.Select(i => i.GetItem()));
                    }
                }
                else
                {
                    sharedItems.AddRange(contentLocation.Axes.GetDescendants());
                }

                var cleanedSharedItems = from itm in sharedItems
                                         where itm.Template != null && enabledTemplates.Select(t => t.ToLower()).Contains(itm.Template.ID.ToString().ToLower()) &&
                                         !excludeItems.Contains(itm.ID.ToString())
                                         select itm;
                var sharedSitemapItems = cleanedSharedItems.Select(i => SitemapItem.GetLanguageSitemapItems(i, site, parentItem, _config));
                sharedModels.AddRange(sharedSitemapItems);
            }

            //All content items
            var contentItems = descendants.ToList();

            contentItems.Insert(0, contentRoot);

            //Filter out the content items that belongs to Sitemap Configuration Manager
            //Should belong to enabled templates
            //Should not be an excluded item
            var selected = from itm in contentItems
                           where itm.Template != null && enabledTemplates.Contains(itm.Template.ID.ToString()) &&
                           !excludeItems.Contains(itm.ID.ToString())
                           select itm;

            //Get sitemap items in Language blocks per item
            var languageSitemapItems = selected.Select(i => SitemapItem.GetLanguageSitemapItems(i, site, null, _config)).ToList();

            //Final list of sitamap items
            var sitemapItems = new List <SitemapItem>();

            //Adding shared items to the sitemap items list
            foreach (var sharedModel in sharedModels)
            {
                sitemapItems.AddRange(sharedModel);
            }

            //Adding language specific sitemap items to the sitemap items list
            foreach (var laguageSitemapItem in languageSitemapItems)
            {
                sitemapItems.AddRange(laguageSitemapItem);
            }

            //Order the items based on priority in descending order with a cap of max items
            sitemapItems = sitemapItems.OrderByDescending(u => u.Priority).Take(int.Parse(Constants.XmlSettings.UrlLimit)).ToList();

            return(sitemapItems);
        }
예제 #11
0
        public Item Duplicate(ClientPipelineArgs args)
        {
            Item result = null;

            Assert.ArgumentNotNull(args, "args");

            var database = Factory.GetDatabase(args.Parameters["database"]);

            Assert.IsNotNull(database, args.Parameters["database"]);

            var itemId     = args.Parameters["id"];
            var sourceItem = database.Items[itemId];

            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 = ItemExtensions.GetParentBucketItemOrSiteRoot(sourceItem);
                    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);
        }