I recently upgraded from 7.2.6 to 7.10.2. I had working content saving event and that was creating node child nodes on a page being saved and it was then publishing the child nodes. Since the upgrade the child nodes are created however they do not seem to be published. Looking at info tab it says:
This document is published but is not in the cache
There are no errors in the log.
The code looks like:
private void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> saveEventArgs)
{
foreach (var savedEntity in saveEventArgs.SavedEntities)
{
if (savedEntity.ContentType.Alias == "GalleryLandingPage")
{
int mediaFolderId = savedEntity.HasProperty("mediaFolder") ? savedEntity.GetValue<int>("mediaFolder") : 0;
bool moveToTop = savedEntity.HasProperty("moveToTop") && savedEntity.GetValue<bool>("moveToTop");
if (mediaFolderId != 0)
{
var mediaFolder = _mediaService.GetById(mediaFolderId);
savedEntity.SetValue("mediaFolder", null);
savedEntity.SetValue("moveToTop", false);
_contentService.SaveAndPublishWithStatus(savedEntity, 0, false);
foreach (var media in mediaFolder.Children())
{
var nodeName = media.Name.Replace("_", " ").Replace(".jpg", "").Replace(".png", "").Replace(".gif", "").Replace(".JPG", "").Replace(".PNG", "").Replace(".GIF", "");
var galleryImage = _contentService.CreateContent(nodeName, savedEntity.Id, "GalleryImage");
galleryImage.SetValue("galleryImage", media.Id);
galleryImage.SetValue("moveToTop", true);
_contentService.SaveAndPublishWithStatus(galleryImage, 0, false);
}
if (moveToTop)
{
var imagesToBeMoved = savedEntity.Children().Where(x => x.GetValue<bool>("moveToTop") == true).ToList();
var galleryImages = savedEntity.Children().ToList();
galleryImages.RemoveAll(x => x.GetValue<bool>("moveToTop"));
galleryImages.InsertRange(0, imagesToBeMoved);
_contentService.Sort(galleryImages, 0, false);
}
}
}
Has something changed in api for 7.10.2 for when u publish from contentservice?
I guess the mediaFolder is a content picker. If that is the case, i think the value of it, will be an UDI. I can't remember if there is a setting for it, but you should be able to set it up in each data-type.
It's an inherited project. So what this has is a gallery parent page and on it you pick a media folder.
When you save content saving event fires it gets the folder and all images in that folder then creates content nodes under the gallery page with the linked image. However before doing that the actual gallery page is published first. I suspect that gallery page has not fully published yet when the other publish happens on the children and therefore the items are not in the cache.
I am going to try one more thing then will try content_saved event. Although I am still unsure as to why this worked with 7.2.6.
Publish issue after upgrade
I recently upgraded from 7.2.6 to 7.10.2. I had working content saving event and that was creating node child nodes on a page being saved and it was then publishing the child nodes. Since the upgrade the child nodes are created however they do not seem to be published. Looking at info tab it says:
There are no errors in the log.
The code looks like:
Has something changed in api for 7.10.2 for when u publish from contentservice?
Regards
Ismail
is this anything? https://our.umbraco.org/documentation/reference/management/services/contentservice#rebuildxmlstructuresparams-int-contenttypeids
I guess the mediaFolder is a content picker. If that is the case, i think the value of it, will be an UDI. I can't remember if there is a setting for it, but you should be able to set it up in each data-type.
https://our.umbraco.org/documentation/getting-started/setup/upgrading/760-breaking-changes#property-editors-storing-udi-instead-of-id-u4-9310
Thing is stuff gets created and it attempts to publish?
Is there a spefici reason why you are using the Saving event ? Otherwise try if it works with the Saved Event.
Dave
Dave,
Cheers your suggestion worked nicely. I am not sure why the original dev did it this way and why on earth it even worked in 7.2.6.
Anyhow i owe u another coffee, i am going be skint at this rate lol
I had an other forum post with the same issue and solution. So something must have changed in Umbraco Core.
Dave
Dave,
It's an inherited project. So what this has is a gallery parent page and on it you pick a media folder.
When you save content saving event fires it gets the folder and all images in that folder then creates content nodes under the gallery page with the linked image. However before doing that the actual gallery page is published first. I suspect that gallery page has not fully published yet when the other publish happens on the children and therefore the items are not in the cache.
I am going to try one more thing then will try content_saved event. Although I am still unsure as to why this worked with 7.2.6.
Regards
Ismail
is working on a reply...