Beispiel #1
0
        public void Process(object sender, EventArgs args)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");

            Item savedItem = Event.ExtractParameter(args, 0) as Item;

            Assert.IsNotNull(savedItem, "saved item can not be null");
            if (savedItem == null)
            {
                Log.Error("XBlog error creating item", this);
                return;
            }
            if (!savedItem.Database.Name.Equals("master", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }
            if (!BucketManager.IsItemContainedWithinBucket(savedItem))
            {
                Log.Debug("Item {0}  is not contained in a bucket", savedItem);
                return;
            }
            Item bucketItem = savedItem.GetParentBucketItemOrParent();

            if (!BucketManager.IsBucket(bucketItem))
            {
                return;
            }

            BucketManager.MoveItemIntoBucket(savedItem, bucketItem);
        }
Beispiel #2
0
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            // call the base implementation for non-bucketed items
            if (!BucketManager.IsItemContainedWithinBucket(item))
            {
                return(base.GetItemUrl(item, options));
            }

            var bucketItem = item.GetParentBucketItemOrParent();

            // is this item a bucket?
            if (bucketItem == null || !bucketItem.IsABucket())
            {
                return(base.GetItemUrl(item, options));
            }

            var bucketUrl = base.GetItemUrl(bucketItem, options);

            if (options.AddAspxExtension)
            {
                bucketUrl = bucketUrl.Replace(".aspx", string.Empty);
            }

            var name = item.Name;

            if (options.EncodeNames)
            {
                name = MainUtil.EncodePath(item.Name, '/');
            }

            bucketUrl = FileUtil.MakePath(bucketUrl, name);

            // reutrn url as bucket-name/item-name
            return(bucketUrl + (options.AddAspxExtension ? ".aspx" : string.Empty));
        }
Beispiel #3
0
 protected void OnItemSaved(object sender, System.EventArgs args)
 {
     if ((args != null))
     {
         Item item = Event.ExtractParameter(args, 0) as Item;
         Assert.IsNotNull(item, "No item in parameters");
         ID parentID = item.ParentID;
         if (BucketManager.IsItemContainedWithinBucket(item))
         {
             parentID = item.GetParentBucketItemOrParent().ParentID;
         }
         IHasExternalId i = item.GlassCast <IHasExternalId>();
         if (i != null && !string.IsNullOrEmpty(i.ExternalId))
         {
             string prefix = i.TemplateId.GetMatchingPrefix();
             if (IDTable.GetID(prefix, i.ExternalId) == null)
             {
                 IDTable.Add(prefix, i.ExternalId, item.ID, parentID);
             }
         }
         else if (parentID.Equals(RebootConstants.ImageRootID))
         {
             string prefix = RebootConstants.ImageItemPrefix;
             if (IDTable.GetID(prefix, item.Name) == null)
             {
                 IDTable.Add(prefix, item.Name, item.ID, parentID);
             }
         }
     }
 }
Beispiel #4
0
        public static Item GetDestinationItem(this Item sourceItem, Item destinationSite)
        {
            var parentSourceItem   = sourceItem.Parent;
            var saveParentItemPath = BucketManager.IsItemContainedWithinBucket(sourceItem)
                ? parentSourceItem.GetParentBucketItemOrParent().Paths.Path
                : parentSourceItem.Paths.Path;
            var destinationPath = saveParentItemPath.Replace(sourceItem.GetSitePath(), destinationSite.GetSitePath());

            return(destinationSite.Database.GetItem(destinationPath));
        }
Beispiel #5
0
        public override string GetItemUrl(Data.Items.Item item, UrlOptions options)
        {
            if (item != null)
            {
                return(BucketManager.IsItemContainedWithinBucket(item, Context.Database)
                           ? item.ShortUrl()
                           : base.GetItemUrl(item, options));
            }

            return(string.Empty);
        }
        private void OnItemCreated(object sender, ItemCreatedEventArgs args)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull((object)args, "args");
            Item obj = args.Item;

            if (obj == null || !BucketManager.IsItemContainedWithinBucket(obj))
            {
                return;
            }
            Context.ClientPage.ClientResponse.Eval("request.currentCommand = Number.MAX_VALUE;scForm.invoke(\"item:load(id=" + (object)obj.ID + ")\")");
        }
        public override string Build(Sitecore.Data.Items.Item item,
                                     ItemUrlBuilderOptions options)
        {
            if (BucketManager.IsItemContainedWithinBucket(item))
            {
                var bucketItem = item.GetParentBucketItemOrParent();
                if (bucketItem != null && bucketItem.IsABucket())
                {
                    var bucketUrl = base.Build(bucketItem, options);

                    return(FileUtil.MakePath(bucketUrl, item.Name.Replace(" ", "-")));
                }
            }

            return(base.Build(item, options));
        }
        private void CloneItem(Item sourceItem, Item destinatonSite, NameValueCollection targets)
        {
            var destination = sourceItem.GetDestinationItem(destinatonSite);

            if (destination == null)
            {
                throw new ClientAlertException("Parent Item on Mall Site is not exists.");
            }
            var newItem = BucketManager.IsItemContainedWithinBucket(sourceItem)
                ? BucketManager.CloneItem(sourceItem, destination, true)
                : sourceItem.CloneTo(destination);

            targets.Add(newItem.GetSiteItem().ID.ToShortID().ToString(), newItem.ID.Guid.ToString().ToUpper());
            newItem.Editing.BeginEdit();
            newItem.Fields[HiddenFields.Templates.HiddenField.Fields.SourceId].SetValue(sourceItem.ID.ToString(), true);
            newItem.Fields[Templates.MainSiteSetting.Fields.MallSites].SetValue(string.Empty, true);
            newItem.Editing.EndEdit();
        }
Beispiel #9
0
        private void CopyItem(Item sourceItem, Item destination, ID newState)
        {
            var resultItem = BucketManager.IsItemContainedWithinBucket(sourceItem)
                ? BucketManager.CopyItem(destination, sourceItem, true)
                : sourceItem.CopyTo(destination, sourceItem.Name);

            //Update info sourceItem
            sourceItem.Editing.BeginEdit();
            ((NameValueListField)sourceItem.Fields[HiddenFields.Templates.HiddenField.Fields.TargetIds]).NameValues
                = new NameValueCollection {
                { resultItem.GetSiteItem().ID.ToShortID().ToString(), resultItem.ID.Guid.ToString().ToUpper() }
                };
            ((CheckboxField)sourceItem.Fields[Multisite.Templates.MainSite.Fields.IsDisplayOnMainSite]).Checked = true;
            sourceItem.Editing.EndEdit();
            //Update info copiedItem
            resultItem.Editing.BeginEdit();
            resultItem.Fields[HiddenFields.Templates.HiddenField.Fields.SourceId].SetValue(sourceItem.ID.ToString(), true);
            ((MultilistField)resultItem.Fields[Templates.MallSite.Fields.SiteDisplaySettings]).Add(sourceItem.GetSiteItem().ID.ToString());
            resultItem.Fields[FieldIDs.State].Value = newState.ToString();
            resultItem.Editing.EndEdit();
        }
Beispiel #10
0
 public override string GetItemUrl(Sitecore.Data.Items.Item item, UrlOptions options)
 {
     try
     {
         if (BucketManager.IsItemContainedWithinBucket(item))
         {
             var bucketItem = item.GetParentBucketItemOrParent();
             if (bucketItem != null && bucketItem.IsABucket())
             {
                 var    bucketUrl = base.GetItemUrl(bucketItem, options);
                 string itemName  = MainUtil.EncodeName(item.Name);
                 return(FileUtil.MakePath(bucketUrl, itemName));
             }
         }
     }
     catch (Exception ex)
     {
         Sitecore.Diagnostics.Log.Error(ex.Message, ex, this);
     }
     return(base.GetItemUrl(item, options));
 }
Beispiel #11
0
 protected void OnItemDeleted(object sender, System.EventArgs args)
 {
     if (args != null)
     {
         Item item = Event.ExtractParameter(args, 0) as Item;
         Assert.IsNotNull(item, "No item in parameters");
         ID parentID = item.ParentID;
         if (BucketManager.IsItemContainedWithinBucket(item))
         {
             parentID = item.GetParentBucketItemOrParent().ParentID;
         }
         //IHasExternalId i = item.GlassCast<IHasExternalId>();
         string extId = item[IHasExternalIdConstants.ExternalIdFieldId];
         if (!string.IsNullOrEmpty(extId))
         {
             string prefix = item.TemplateID.Guid.GetMatchingPrefix();
             IDTable.RemoveID(prefix, item.ID);
         }
         else if (parentID.Equals(RebootConstants.ImageRootID))
         {
             IDTable.RemoveID(RebootConstants.ImageItemPrefix, item.ID);
         }
     }
 }
Beispiel #12
0
 protected void OnItemSaved(object sender, System.EventArgs args)
 {
     if ((args != null))
     {
         Item item = Event.ExtractParameter(args, 0) as Item;
         Assert.IsNotNull(item, "No item in parameters");
         if (!item.TemplateID.Equals(RebootConstants.ModelTemplateId))
         {
             return;
         }
         ID parentID = item.ParentID;
         if (BucketManager.IsItemContainedWithinBucket(item))
         {
             parentID = item.GetParentBucketItemOrParent().ParentID;
         }
         string       prefix       = item.TemplateID.ToString();
         string       key          = item.Name;
         IDTableEntry idTableEntry = IDTable.GetID(prefix, key);
         if (idTableEntry == null)
         {
             IDTable.Add(prefix, key, item.ID, parentID);
         }
     }
 }