Copied to clipboard

Flag this post as spam?

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


  • Thomas Haggren 29 posts 149 karma points
    Jul 06, 2017 @ 09:15
    Thomas Haggren
    0

    Updating cache (unpublish/publish) issue

    Hi

    I have changed a data type from Umbraco.MultipleMediaPicker (obsolete) to Umbraco.MediaPicker2 for our gallery pages. In the gallery template I have replaced this code:

    var imagesList = Model.Content.GetPropertyValue<string>("images").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
    var imagesCollection = Umbraco.TypedMedia(imagesList).Where(x => x != null);
    

    with this:

    var imagesCollection = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("images");
    

    Testing the gallery afterwards resulted in errors. It seems that I need to unpublish and the publish every page in the backend manually for Umbraco to update the cache.

    I have tried the following without success:

    • TRUNCATE TABLE [cmsContentXml] and delete umbraco.config
    • Republish entire site from backend
    • /umbraco/dialogs/republish.aspx?xml=true
    • /umbraco/dialogs/republish.aspx?previews=true
    • Doing unpublish/publish from a script (see below) (both unpublish and publish returns true)
    • Doing a "Publish Galleri and all its subpages" on the parent node for the gallery pages

    Only thing that updates the cache is manually unpublishing and then publishing each node in the backend (takes forever to do).

    What am I missing here?

    Script:

    @using System.Text.RegularExpressions
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Layout.cshtml";
    
        var cs = ApplicationContext.Current.Services.ContentService;
    
        var docTypeAlias = "Gallery";
    
        var count = 0;
        var root = Umbraco.TypedContentAtRoot();
        var nodes = new List<IPublishedContent>();
        foreach (var item in root)
        {
            nodes.AddRange(item.DescendantsOrSelf().Where(n => n.DocumentTypeAlias == docTypeAlias).ToList());
        }
    }
    
    <div class="container content">
        <h3>Nodes with doctype alias "@docTypeAlias":</h3>
        <p>
            <div class="bodyText">
                <ul>
                    @foreach (var node in nodes)
                    {
                        // Unpublish / publish node (only published nodes will be returned by the ContentService)
                        var content = cs.GetById(node.Id);
                        var unpublishResult = cs.UnPublish(content);
                        var publishResult = cs.Publish(content);
    
                        <li>
                            Node: @node.Name, Unpublish: @unpublishResult, Publish: @publishResult
                        </li>
                    }
                </ul>
                <br />
                Count: @nodes.Count()
            </div>
        </p>
    </div>
    

    Regards,

    Thomas

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jul 06, 2017 @ 13:06
    Dan Diplo
    0

    My understanding (which may be wrong) is that if you swapped a picker for another picker that stores different data then you need to reselect that data and then republish the node that has the picker.

    MediaPicker2 stores a list of GUIDs, whereas the previous (now legacy) picker stored a list of integers IDs. These aren't compatible. So you need to re-select the media, then republish the page. This updates the cache and stores the GUIDs.

    I don't believe you should need to unpublish first.

  • Thomas Haggren 29 posts 149 karma points
    Jul 06, 2017 @ 13:22
    Thomas Haggren
    0

    I thought that to... but doing an unpublish and then publish actually changes the integers IDs to UID (or what it is called).

    So it changes data from

    <images><![CDATA[14051,14053,14054,14056,14055,14057,14058,14059,14060,14062,14063,14064,14066,14067,14068,14071,14070,14074,14076,14077,14079,14082,14084,14085,14087,14090,14093,14094,14096,14099,14100,14101,14106,14109,14112,14117,14120,14123,14125,14128,14131,14132,14140,14142,14143,14150,14151,14154,14156,14158,14160,14162,14165,14168,14169,14172,14174,14175,14177,14181,14183,14191,14193,14196,14200,14201]]></images>
    

    to

    <images><![CDATA[umb://media/43a1a81a27d24111ad341338c288ba4b,umb://media/0ed098661e06415884923d3c3c3f3305,umb://media/8178464ddfc34fc687d1bab7b38fe639,umb://media/2af06a1ac25043de9a030f2f8a98177d,umb://media/e301fb2245c24848bf9792b8e07e7126,umb://media/4ba7d75716c04479aba2e22b1bca53c9,umb://media/11f608f6d0c845ee97397bb95c261eef,umb://media/ba900fe389474e0b94bd3c6960abb898,umb://media/a3ecb9459c0f4f93a06809b6e3e384e8,umb://media/484b1af49b964b3582e19847dbabb90e,umb://media/fdb91cd198c845efb2c9c4a50b5f353a,umb://media/aad6a7c20dd9480188957fc3152dc859,umb://media/a9a1d923702b4d1fa596da10dbe5f6d7,umb://media/b11fba91996a4db4bbf8ce4fae2a7069,umb://media/d886a4484f4145ec8ad46bbc5e97f875,umb://media/c8c5cab5f97345c4955c4c049e610767,umb://media/491229250586485384b6ddba2b7e8df8,umb://media/cd96144fc2164b83add8368e8871d9e8,umb://media/591345120570479194e36c23a4319b9c,umb://media/d0c0d079c3a84e7f89c9305f3b37251a,umb://media/8b66e3bf189f4eea842170ff84ca473d,umb://media/00210c255fb34eda90896d12073b0b8f,umb://media/66a87b2b8fd74a1ba55727c2167a0f3d,umb://media/7bea30e870404383be259be69233e732,umb://media/c6f208fb012c4f92abcd069ecc04c699,umb://media/6e44eff997e442179d2fc87b6bc1088d,umb://media/d5c256f29e4b4e54ae6782efdeb889b4,umb://media/d392b0a16cdc42c5b029d799be38bd35,umb://media/5ccddcf02eff4903a6df8aca6bbe30b4,umb://media/54cf6bdc2f1e4c46bec9e0b2c110543d,umb://media/0012ab48d5534f538624fdda273fab0a,umb://media/c39c82e83c6a4117b7ead8416af4bde3,umb://media/c7a479ebe759410aa66f59fd22bbe9b2,umb://media/243c39884e824050ad3484c82258e19c,umb://media/24df97ae65554370945fb8c44e1166a8,umb://media/0e6e38a297c842899a7834fe7efc3c2e]]></images>
    

    Just by unpublish and then publish from the backend UI (only doing publish doesn't work). Doing the same using the API doesn't work.

    Its like woodoo magic :)

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jul 06, 2017 @ 14:38
    Dan Diplo
    0

    Cool, I never knew that! Though, as you say, you would have thought the same would happen via the API. It definitely would be handy if it did and even better if it just automatically converted them on publish.

    Next time I get chance I'll have a look into this. If you can reproduce this behaviour then might be worth filing an issue - http://issues.umbraco.org/dashboard

  • Thomas Haggren 29 posts 149 karma points
    Jul 10, 2017 @ 05:51
    Thomas Haggren
    0

    Will do :)

  • James Collins 13 posts 34 karma points
    Jul 07, 2017 @ 12:22
    James Collins
    0

    I've had similar situations in the past with changing data types (though not this specific type).

    In any case, to do bulk republishing, I use a package called Bulkmanager...

    https://soetemansoftware.nl/bulkmanager

    Even with the free version, you can unpublish/publish content nodes, which should update the data in the cache. (In my experience though, like Dan, I haven't ever needed to unpublish, only publish).

    Give it a shot. It's very intuitive: select the document type, it gives you a list of all content nodes of this type, check-mark them, click publish, and wait while it goes through and publishes them. It may take a second or two per node, but it works well and definitely beats the manual approach.

    James

  • Thomas Haggren 29 posts 149 karma points
    Jul 10, 2017 @ 05:49
    Thomas Haggren
    0

    Thanks James... I will have a look at that package :)

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jul 07, 2017 @ 15:30
    Dan Diplo
    0

    Another option to make it a bit easier to bulk publish / unpublish is to use a List View - then Umbraco allows you to select multiple items. You can change the page size to make it show more than 10 items per page. A little less tedious than doing each item by hand :)

  • Thomas Haggren 29 posts 149 karma points
    Jul 10, 2017 @ 05:50
    Thomas Haggren
    0

    Of course :) Sometimes the easy solution is the most hard to "remember" :)

  • Jan Hansen 7 posts 27 karma points
    Aug 14, 2017 @ 09:46
    Jan Hansen
    0

    I just tested this problem. A .cshtml kept complaining about not being able to use a media item integer when a UID was expected.

    Unpublish/publish from a List view didn't do the trick, so I tried Bulkmanager, but publish and unpublish/publish from that doesn't do the trick either. You have to open each and every item and click "Save and publish" before the integer list is converted to UIDs. My guess is that the Save operation within Umbraco handles the conversion of values. However, using Bulkmanager, it was a bit easier to open each item, because it does that in a new window, click "Save and publish" and close the window. When using a list view, you have to open the item, click "Save and publish", click "Return to list" and BAM - it has forgotten which page you were at. Sigh..

  • Thomas Haggren 29 posts 149 karma points
    Sep 08, 2017 @ 08:04
    Thomas Haggren
    0

    Correct... I have come to the same conclusion... :/

Please Sign in or register to post replies

Write your reply to:

Draft