Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Psib3r 70 posts 119 karma points
    Sep 03, 2012 @ 11:25
    Psib3r
    0

    Media type ID's

    I have added media types that I am using in a macro to select an image, when I courier the images in the media section, they have differewnt ID's on the live server, so when the page with the macro is courierd the image is then missing because the ID's are different. So is this a courier issue or is it an Umbraco issue?  If umbraco can tell the difference between different page id's that have been courierd that are referenced in hyperlinks for example, how come it can't connect the media files?

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Sep 03, 2012 @ 12:46
    Jeroen Breuer
    0

    Hmm looks like Courier bug. Might be a good idea to report that here: http://umbraco.com/help-and-support/customer-area/courier-support-and-download/courier-20-bug-reports.aspx.

    Jeroen

  • Psib3r 70 posts 119 karma points
    Sep 24, 2012 @ 18:04
    Psib3r
    0

    Hi, just updated courier to the latest, when I tray to courier anything at all, all i get is this, 

     

  • Jeremy Pyne 106 posts 246 karma points MVP c-trib
    Oct 04, 2012 @ 20:20
    Jeremy Pyne
    0

    This is not acctualy a bug.  All content in Umbraco has a instance specific ID that is only unique to that instance.  When you Courier and item it will get a new id in the destination system.  (It is possible that some ID's will match but this is a result of copying the datbase and can not be coded for.)

    You CAN do you you'r trying to do but instead of using ID you have to use the Guid witch is garentied to be unique.   All of the Umbraco objects can be found byt he Guid just like they load by id.  So instead of this:

    var myImage = new Media(14);  // get image ID 14

    Do this

    var myImage = new Media(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));

    Now your asking How do I know the Guid?  While you can get it from the umbracoNode table in your database, or jsut stick a bit of code in the dev macro to print it out.

    @myImage.UniquId

     

     

    As a sufix to the conversation you may note that I am referenceing the umbraco.cms.businesslogic.media.Media class not the Razor DynamicNode here.  The problem is that DynamicNode doesnt have a method of loading by Guid nor getting the Guid.  You can add the following extension methods in App_Code and import the class to add them.

    using System;

    using umbraco.cms.businesslogic;


    namespace
    JSP

    {

        ///<summary>

        /// Extensions to the umbraco f ramework.

        ///</summary>

        publicstaticclassExtensions

        {

      ///<summary>

            /// Get a node by the unique Guid.  This is needed for sites where courier is in use.

            ///</summary>

            ///<param name="self">Current Page</param>

            ///<param name="guid">Guid to load.</param>

            ///<returns>DynamicNode</returns>

            public static DynamicNode NodeByGuid(this DynamicNode self, string guid)

            {

                return self.NodeByGuid(new Guid(guid));

            }

     

            ///<summary>

            /// Get a node by the unique Guid.  This is needed for sites where courier is in use.

            ///</summary>

            ///<param name="self">Current Page</param>

            ///<param name="guid">Guid to load.</param>

            ///<returns>DynamicNode</returns>

            public static DynamicNode NodeByGuid(this DynamicNode self, Guid guid)

            {

                return self.NodeById(new CMSNode(guid).Id);

            }

     

            ///<summary>

            /// Get the unique ID for a selected node.

            ///</summary>

            ///<param name="self">Node</param>

            ///<returns>guid</returns>

            public static string UniqueId(this DynamicNode self)

            {

                return new CMSNode(self.Id).UniqueId.ToString();

            }

        }

    }

     

    In this way you can jsut do @Model.NodeByGuid("xxx...") and @Model.UniqueId() to replicate the logic i showed above.

Please Sign in or register to post replies

Write your reply to:

Draft