Copied to clipboard

Flag this post as spam?

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


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

    Experimenting with base media types

    Hello,

    I've been using base media types for a while now. It's pretty easy to do:

    1. Just create a new media type
    2. Go to the cmsContentType table in the database
    3. Find the media type you just created
    4. Set the masterContentType field with the nodeId of the parent media type (usually 1032 or 1033)
    5. Open your media type in the backoffice and it will now look like this:
    Your media type will now support base media types. The tree doesn't support it, but it does work.
    The only problem I'm having now is that after you've done this you can't add properties to the base media type anymore. It will give this error:

    Parameter name: Property trackLabel (205) on Content Type ImageContent could not be retrieved for Document 1298 on Tab Page Image. To fix this problem, delete the property and recreate it.

    I've seen this error a couple times before on the forum, but didn't find a good solution. Anyone know what I need to do to fix this? What should I do after I've added a property on a base media type and try to open an media item which inherits from this?
    Jeroen

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 18, 2012 @ 17:42
    Tom Fulton
    0

    Hi Jeroen,

    I've also seen this error, and usually resetting the app pool fixes it.  I think I also had to muck around in the DB once but unfortunately I don't recall the details - this usually fixes itself.  Does resetting fix for you?

    Sorry I don't have more info :(

    -Tom

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 20, 2012 @ 01:39
    Tom Fulton
    0

    Also, not sure if this helps, but I got this error again today when changing the inheritance of a document type via uSiteBuilder.  To fix I re-published the offending page by right-clicking and selecting Publish (since I wasn't able to access the edit UI).  This seems like a similar situation to what you are doing.  Just wanted to mention in case it helps

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Sep 20, 2012 @ 07:28
    Richard Soeteman
    0

    Hi Jeroen and Tom,

    This is indeed because the property is missing from existing media types. When you use the UI it updates the existing items automatically, I've had this once with normal content and wrote a blogpost about that. Maybe it will help you to, but you need to code.

    http://www.richardsoeteman.net/2009/10/27/FixObjectReferenceNotSetErrorAfterAddingOrDeletingADocumentProperty.aspx

    Cheers,

    Richard

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Sep 20, 2012 @ 11:55
    Jeroen Breuer
    0

    Thanks for the feedback Tom and Richard :-). I haven't found a solution yet, but the problem only happens with media items which already exists. So if I add a new property to the base media type all existing media items give the above error, but if I create a new media item that does work. Somehow need to update all existing media so the new property from the base media type is added there too.

    Jeroen

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 20, 2012 @ 16:55
    Tom Fulton
    0

    Since re-publishing fixes for me, I wonder if you can initiate a republish of all the media, sort of what you have to do when upgrading around 4.5 ?  If I recall there is some page you can goto like /dialogs/publish.aspx?xml=true (winging it...)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Sep 20, 2012 @ 17:05
    Jeroen Breuer
    1

    I discovered what the problem was :-). It seems that if you add a property to a media type that all media items are updated in the cmsPropertyData table, but if you add a property to a base media type this doesn't happen and that's what is causing the error from my first post. I'm working on a new package which needs to add a new property to some media types. Here at Digibiz we are working with base media types so I needed to find a way to only add this new property to the base media type without breaking all existing media items which have a media type that inherit from another base media type. Here is part of my code to fix this:

    //Get the media type which needs to be updated.
    MediaType mediaType = new MediaType(Convert.ToInt32(listItem.Value));
    
    //Check if the property already exists.
    if (mediaType.getPropertyType("trackLabel") == null)
    {
        //Add the new property to the media type.
        PropertyType trackLabel = mediaType.AddPropertyType(new DataTypeDefinition(-88), "trackLabel", "Track label");
    
        //Add the property to the first tab of the media type.
        mediaType.SetTabOnPropertyType(trackLabel, mediaType.getVirtualTabs[0].Id);
    
        //Save the changes.
        mediaType.Save();
    
        string sql = @"
        select c.nodeId, cv.VersionId from cmsContentType ct 
            inner join cmsContent c ON ct.nodeId = c.contentType
            inner join cmsContentVersion cv ON c.nodeId = cv.ContentId
        where ct.masterContentType = @mediaTypeId";
    
        //Get all the media items which have this media type as a base media type.
        using (IRecordsReader dr = SqlHelper.ExecuteReader(sql, SqlHelper.CreateParameter("@mediaTypeId", mediaType.Id)))
        {
            //Loop through all the media items.
            while (dr.Read())
            {
                //Get the id and versionId of a media item.
                int mediaId = dr.GetInt("nodeId");
                Guid versionId = dr.GetGuid("VersionId");
    
                //Check if this property is in the cmsPropertyData table.
                int count = SqlHelper.ExecuteScalar<int>(@"
                select count(*) from cmsPropertyData
                where contentNodeId = @nodeId
                and versionId = @versionId
                and propertytypeId = @propertytypeId", 
                    SqlHelper.CreateParameter("@nodeId", mediaId),
                    SqlHelper.CreateParameter("@versionId", versionId), 
                    SqlHelper.CreateParameter("@propertytypeId", trackLabel.Id));
    
                if (count == 0)
                {
                    //If there is no row in cmsPropertyData it means that this media item doesn't have the new property yet. 
    //This will only happen when using base media types. //By inserting this row into the database this media item will also have the new property. SqlHelper.ExecuteNonQuery("INSERT INTO cmsPropertyData (contentNodeId, versionId, propertyTypeId) VALUES(@contentNodeId, @versionId, @propertyTypeId)", SqlHelper.CreateParameter("@contentNodeId", mediaId), SqlHelper.CreateParameter("@versionId", versionId), SqlHelper.CreateParameter("@propertyTypeId", trackLabel.Id)); } } } }

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 10, 2012 @ 09:44
    Jeroen Breuer
    0

    The package where I used this code in is out: http://our.umbraco.org/projects/website-utilities/track-media.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft