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>
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.
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
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.
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 :)
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..
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:
with this:
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:
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:
Regards,
Thomas
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.
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
to
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 :)
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
Will do :)
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
Thanks James... I will have a look at that package :)
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 :)
Of course :) Sometimes the easy solution is the most hard to "remember" :)
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..
Correct... I have come to the same conclusion... :/
is working on a reply...