Copied to clipboard

Flag this post as spam?

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


  • Seth Niemuth 275 posts 397 karma points
    Dec 22, 2013 @ 17:17
    Seth Niemuth
    1

    Duplicate media nodes when updating from umbraco 3 to umbraco 6

    I am guessing this will not affect very many people but I have been doing an upgrade from a version 3 of umbraco to a version 6.1.6 of umbraco (to learn a bit more about that upgrade click here). When doing the testing afterwards I ran into a weird problem in the media: when I would create a new media item, I was getting a copy or duplicate of the last one and the next to last one but they weren't real duplicates just listed twice as they had the same node Id. But then when I would add another, it was fine like so:

    So, I decided to have a look at the database and this is what I found:

    The only odd thing that I found was that the sort order was the same for the 2 that are repeated. So, I dug around a bit and noticed that if I sort (don't even have to change positions of nodes) before adding a new node, it seemed to be working. Then, I noticed the sort order positions. Here is a folder and nodes created before the upgrade:

    Then, after I click the 'Save' button, the sort order starts from 0. So, I think previously that the sort order for media used to start at 1 and now it starts at 0 and it is causing it to mess up.

    I think I am going to need to write a script that goes through all of the media items and does a sort save so that they all start from 0 and I don't get anymore of the repeating items. Has anyone else encountered this problem and was able to fix it in a different way? 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Dec 23, 2013 @ 13:10
    Jeroen Breuer
    0

    Thanks for posting this. I had the same problem and sorting all the folders did fix it for me. Maybe it's good to mention that if you have duplicate id's in the tree and you navigate between sections the names of the duplicate items are also duplicated. You can get something like this: https://twitter.com/j_breuer/status/392277579513597953

    Jeroen

  • Seth Niemuth 275 posts 397 karma points
    Dec 23, 2013 @ 13:14
    Seth Niemuth
    1

    It may take awhile and you might need to increase your executionTimeout in the web.config to a very large number but here is the code that I used. I had a usercontrol which I put on the dev dashboard which then called this:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Umbraco.Core.Models;
    using Umbraco.Core.Services;
    using System.Linq;
    using Umbraco.Core;
    
    namespace SortAllMedia
    {
        public class SortAllMediaService
        {
            public void SortAll()
            {
                var rootMediaItems = ApplicationContext.Current.Services.MediaService.GetRootMedia();
                SortChildren(rootMediaItems);
            }
    //Recursive method to go down all of the children until it doesn't find any with children
            private void SortChildren(IEnumerable<IMedia> mediaItems)
            {
                foreach (var mediaItem in mediaItems)
                {            
                        var children = mediaItem.Children().ToList();
                        if (children.Any())
                        {
                            SortChildren(children);
                            ApplicationContext.Current.Services.MediaService.Sort(mediaItem.Children());
                        }
                }
            }
        }
    }
    
  • Rasmus Beuchert 14 posts 35 karma points
    May 21, 2014 @ 09:45
    Rasmus Beuchert
    0

    Hello,

    We are experiencing the exact same situation in an Umbraco setup that we upgraded from a version 4 to 6.1.2.

    We have tried to execute the above method, and it seems to fix the problem - at least for a period of time. After a while our users begin to experience the problem again, and then we execute the method again, and the story starts all over.

    It takes about 4 hours to complete the sorting method (We have around 20.000 media nodes). I have written a debug log, to verify that the method doesn't get cut off by a timeout.

    Does anyone have an idea how we can find out what the problem could be?

    Best regards Rasmus Beuchert

  • Seth Niemuth 275 posts 397 karma points
    May 21, 2014 @ 15:08
    Seth Niemuth
    0

    After you have run the re sorting method, what does the sort order look like for the messed up media nodes? As in, when you sort a folder of repeating/messed up nodes in media (right click a folder > 'Sort') is it starting at 0 or 1? Then, what does it look like after you have sorted?

    If the sort order does start with 0 and the media nodes are messed up, then I think this is not your problem and you have something else going on.

  • Rasmus Beuchert 14 posts 35 karma points
    May 21, 2014 @ 15:33
    Rasmus Beuchert
    0

    When a media folder is messed up, the sort order is for example 1, 2, 2. When I run the resorting method it becomes correct 0, 1, 2. But when the problem occurs again later, the sort order is back to something like 1, 2, 2.

    I have just run the method yesterday, and every sort order I look up starts correctly with 0, and right now I can upload new files or create new folders without problems.

    Now I'll just wait and see if the problem reoccurs when the customer continues to put up content.

  • Camilla Gaardsted 4 posts 74 karma points
    Feb 25, 2016 @ 15:08
    Camilla Gaardsted
    0

    Do you still experience this problem? I consider to implement a button to trigger the sorting, since we often experience this problem at a customer site. But I would rather know what causes this problem.

Please Sign in or register to post replies

Write your reply to:

Draft