コード例 #1
0
ファイル: LayoutField.cs プロジェクト: Praveencls/cxm
 public override void RemoveLink(Sitecore.Links.ItemLink itemLink)
 {
     Sitecore.Diagnostics.Assert.ArgumentNotNull(itemLink, "itemLink");
     Replace(
         itemLink.TargetPath,
         itemLink.TargetItemID.ToString(),
         String.Empty,
         String.Empty);
 }
コード例 #2
0
ファイル: LayoutField.cs プロジェクト: Praveencls/cxm
 public override void Relink(Sitecore.Links.ItemLink link, Sitecore.Data.Items.Item updated)
 {
     Sitecore.Diagnostics.Assert.ArgumentNotNull(link, "link");
     Sitecore.Diagnostics.Assert.ArgumentNotNull(updated, "updated");
     Replace(
         link.TargetPath,
         link.TargetItemID.ToString(),
         updated.Paths.FullPath,
         updated.ID.ToString());
 }
コード例 #3
0
        public override void Relink(
            SC.Links.ItemLink itemLink,
            SC.Data.Items.Item newLink)
        {
            SC.Diagnostics.Assert.ArgumentNotNull(itemLink, "itemLink");
            SC.Diagnostics.Assert.ArgumentNotNull(newLink, "newLink");
            base.Relink(itemLink, newLink);
            string xml = this.Value;

            if (String.IsNullOrEmpty(xml))
            {
                return;
            }

            SC.Layouts.LayoutDefinition layoutDetails =
                SC.Layouts.LayoutDefinition.Parse(xml);
            ArrayList devices = layoutDetails.Devices;

            if (devices == null)
            {
                return;
            }

            foreach (SC.Layouts.DeviceDefinition device in devices)
            {
                if (device == null || device.Renderings == null)
                {
                    continue;
                }

                foreach (SC.Layouts.RenderingDefinition rendering in device.Renderings)
                {
                    if (!String.IsNullOrEmpty(rendering.Datasource) &&
                        (rendering.Datasource.Equals(itemLink.TargetPath, StringComparison.InvariantCultureIgnoreCase) ||
                         rendering.Datasource.Equals(itemLink.TargetItemID.ToString(), StringComparison.InvariantCultureIgnoreCase)))
                    {
                        rendering.Datasource = newLink.ID.ToString();
                    }
                }
            }

            this.Value = layoutDetails.ToXml();
        }
コード例 #4
0
        /// <summary>
        /// Handle links database references to items that do not exist by logging an error
        /// or throwing an exception.
        /// </summary>
        /// <param name="item">The item that contains the reference.</param>
        /// <param name="referenced">The referenced item, which may be Null.</param>
        /// <param name="link">The link record from the links database.</param>
        /// <returns>True if the referenced item is Null, false otherwise.</returns>
        /// <exception cref="PublishingException"><c>PublishingException</c> - Any type of
        /// error.</exception>
        protected bool HandleNullReference(
            Sitecore.Data.Items.Item item,
            Sitecore.Data.Items.Item referenced,
            Sitecore.Links.ItemLink link)
        {
            if (referenced != null)
            {
                return(false);
            }

            Sitecore.Data.Fields.Field field = item.Fields[link.SourceFieldID];

            if (field == null)
            {
                return(true);
            }

            if (field.Value.Contains(link.TargetItemID.ToString()))
            {
                string message = this.Logger.Info(
                    "{0} of {1} contains broken link to {2} : {3}",
                    field.Name,
                    item,
                    link.TargetItemID,
                    link.TargetPath);

                if (this.ThrowExceptions)
                {
                    throw new PublishingException(message);
                }

                return(true);
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Returns True if the link exists in the specified version of the item.
        /// </summary>
        /// <param name="me">The item to check.</param>
        /// <param name="link">The link record.</param>
        /// <returns>True if the link exists in the specified version of the item, False
        /// otherwise.</returns>
        public static bool IsValidLink(
            this Sitecore.Data.Items.Item me,
            Sitecore.Links.ItemLink link)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(me, "item");
            Sitecore.Diagnostics.Assert.IsNotNull(link, "link");

            // If the link is in a different database
            if (String.Compare(
                    link.SourceDatabaseName,
                    me.Database.Name,
                    StringComparison.OrdinalIgnoreCase) != 0)
            {
                return(false);
            }

            // If the source field is unknown.
            if (link.SourceFieldID == Sitecore.Data.ID.Null)
            {
                me.Fields.ReadAll();

                foreach (Sitecore.Data.Fields.Field checkField in me.Fields)
                {
                    if (!checkField.Value.Contains(link.TargetItemID.ToString()))
                    {
                        continue;
                    }

                    string message = String.Format(
                        "{0} : Link to {1} in {2} of {3}, but field has Null ID in links database",
                        me,
                        link.TargetItemID,
                        checkField.Name,
                        me.Paths.FullPath);
                    Sitecore.Diagnostics.Log.Warn(message, me);
                    return(false);
                }

                string error = String.Format(
                    "{0} : link database record from {1} to {2}, but field has Null ID in links database and no field value contains reference",
                    me,
                    me.Paths.FullPath,
                    link.TargetItemID);
                Sitecore.Diagnostics.Log.Warn(error, me);
                return(false);
            }

            // The field containing the link.
            Sitecore.Data.Fields.Field field = me.Fields[link.SourceFieldID];

            // The field does not exist.
            if (field == null)
            {
                return(false);
            }

            // The link must be in a previous version of the item.
            if (field.Value.Contains(link.TargetItemID.ToString()) ||
                field.Value.Contains(link.TargetItemID.ToShortID().ToString()))
            {
                return(true);
            }

            return(false);
        }