David, one of the breaking changes with v6 is that you need to call Save explicitly when setting properties.
"you cannot set a property's value without doing an explicit Save() any more. So: doc.getProperty("pageTitle").Value = "Hello World"; does not do a save to the database, you have to call doc.Save(); after that."
As an alternative you can call the .Save(false) method again in the before publish event, so the values get saved and no events are called to prevent an infinite loop.
1) Thanks, Dallas, but umbraco.cms.businesslogic.web.Document' is obsolete also. I'm told to use Umbraco.Core.Models.Content instead. I'm uncertain as to how to do what I need to do with the new content service.
2) Thanks, Jeroen. I'm a bit more confused on the whole matter now.
Is that a bug you're describing?
The warning says: 'ApplicationStartupHandler' is obsolete: 'This class is no longer used, implement IApplicationEventHandler instead... but I haven't been able to get anywhere with that.
I was hoping for a simple code example to show how to assign a value when the user clicks "save and publish". I haven't been able to glue together all the various bits of information enough to create actual working code.
It's beginning to sound like I cannot use version 6 for my applications. Too bad if that's the case. I really wanted to make use of a lot of the new MVC features.
No it's not a bug. You can still use the old API's, but in v6 they work a bit different. The easiest solution is do to the stuff you wanted to do in the before publish event in the before save event. Otherwise you'll need to call .Save() again in the before publish event. I have an example, but it's a bit harder because I wanted my code to be compatible with v4 and v6. Check the Media_AfterSave method here: http://damp.codeplex.com/SourceControl/changeset/view/2df2dc8aab7c#DigibizAdvanceMediaPicker/DAMP_ApplicationBase.cs. It's the aftersave method, but using the before publish probably works the same.
Thanks, Jeroen. I guess I have more work to do to get it to do what I want.
Seems like it got a tad more complicated that it needs to be. Plus, I have always been reluctant to make calls to obsolete code (e.g. ApplicationStartupHandler and Document) - preferring to do things in the new paradigm with the current code base.
My goal with this post was to see an example of code using the new version 6 API to write property values when someone presses save+publish.
If anyone could post some or point me to an example - that would be great.
For those who may need some sample code to write property values when the save+publish is pressed, here is an example using the ContentService.Saving event handler:
using System; using Umbraco.Core.Services; //assembly: Umbraco.Core.dll using umbraco.interfaces;
namespace FoodMethods { public class CustomEventHandler : IApplicationStartupHandler { public CustomEventHandler() { ContentService.Saving += CustomSavingEventHandler; }
As far as I can tell, in V6 there is no longer any such thing as the Document.BeforePublish that we had in V4.
This is unfortunate because, for my application, I don't want the action to occur when the content item is saved but only when published.
Also, this event gets called twice when the save+publish button is clicked - not sure if this is how it is supposed to be - but it will not work for me.
I don't know if I'm doing it incorrectly because I haven't been able to find any documentation on the subject.
This is very disappointing - i really wanted to learn and use the new V6 API and not have to call obsolete code.
I came across this post, which definitely helped me - I ended up following the suggestion to use PublishingStrategy.Publishing event - which suits my needs. I just figured out an alternative way of doing it - I am now subscribing to ContentService.Saved (in ContentService there are lots of useful events, FYI), which also works for me.
Is one way (PublishingStrategy vs ContentService) preferrable over the other ? Which is the newer, recommended approach, which follows umbraco's new paradigms ? I am using Umbraco 7.
P.S. Here are the reasons for opting for ContentService instead of PublishingStrategy:
1) Looks more straightforward/clear to me
2 - the determinant factor :) Gives me the sender object, with which I have access to sender.Move method, which is what I ultimately need in my task.
Thanks
Update: Seems that the answer to my question is simply "they are 2 different events, but from the same umbraco (up-to-date) events model.
public TurnIntoBlogEntry()
{
ContentService.Created += ContentService_Created;
ContentService.Published += ContentService_Published;
}
Indeed, IPublishingStrategy does not provide me with a sender object that has "Move", the created event - which provides a sender object of type IContentService, does. That's all. So for my purposes, I should indeed pick a Created-like event (one that provides me with an interface that implements Move).
BeforePublish Event - unable to assign property value
Hello Umbraco Colleagues,
I'm using Umbraco version 6.0.0 (or trying to... this is a show-stopper if I cannot figure it out).
Could someone *PLEASE* post an example of assigning property values using the BeforePublish Event.
I need to assign some property values using the BeforePublish Event but this appears to be obsolete in Umbraco version 6.
here's the way I used to do it (and it used to work):
and the values are not being assigned with this:
The visual studio warning says this:
'umbraco.businesslogic.ApplicationStartupHandler' is obsolete: 'This class is no longer used, implement IApplicationEventHandler instead'
But I've had no success implementing IApplicationEventHandler so far.
I'd rather not revert back to ver. 4.11.x but I may have to if I can't get it.
If someone would kindly supply an example, I'm sure others are having (or will soon have) the same trouble as I am.
Thanks,
David Hill
David, one of the breaking changes with v6 is that you need to call Save explicitly when setting properties.
"you cannot set a property's value without doing an explicit Save() any more. So: doc.getProperty("pageTitle").Value = "Hello World"; does not do a save to the database, you have to call doc.Save(); after that."
http://umbraco.codeplex.com/releases/view/101178
Hello,
You can only set properties in the before save event. More info here: http://issues.umbraco.org/issue/U4-1372 - http://issues.umbraco.org/issue/U4-1564
As an alternative you can call the .Save(false) method again in the before publish event, so the values get saved and no events are called to prevent an infinite loop.
Jeroen
1)
Thanks, Dallas, but umbraco.cms.businesslogic.web.Document' is obsolete also. I'm told to use Umbraco.Core.Models.Content instead. I'm uncertain as to how to do what I need to do with the new content service.
2)
Thanks, Jeroen. I'm a bit more confused on the whole matter now.
Is that a bug you're describing?
The warning says: 'ApplicationStartupHandler' is obsolete: 'This class is no longer used, implement IApplicationEventHandler instead... but I haven't been able to get anywhere with that.
I was hoping for a simple code example to show how to assign a value when the user clicks "save and publish". I haven't been able to glue together all the various bits of information enough to create actual working code.
It's beginning to sound like I cannot use version 6 for my applications. Too bad if that's the case. I really wanted to make use of a lot of the new MVC features.
David
No it's not a bug. You can still use the old API's, but in v6 they work a bit different. The easiest solution is do to the stuff you wanted to do in the before publish event in the before save event. Otherwise you'll need to call .Save() again in the before publish event. I have an example, but it's a bit harder because I wanted my code to be compatible with v4 and v6. Check the Media_AfterSave method here: http://damp.codeplex.com/SourceControl/changeset/view/2df2dc8aab7c#DigibizAdvanceMediaPicker/DAMP_ApplicationBase.cs. It's the aftersave method, but using the before publish probably works the same.
Jeroen
Thanks, Jeroen. I guess I have more work to do to get it to do what I want.
Seems like it got a tad more complicated that it needs to be. Plus, I have always been reluctant to make calls to obsolete code (e.g. ApplicationStartupHandler and Document) - preferring to do things in the new paradigm with the current code base.
My goal with this post was to see an example of code using the new version 6 API to write property values when someone presses save+publish.
If anyone could post some or point me to an example - that would be great.
Cheers,
David
Update:
For those who may need some sample code to write property values when the save+publish is pressed, here is an example using the ContentService.Saving event handler:
As far as I can tell, in V6 there is no longer any such thing as the Document.BeforePublish that we had in V4.
This is unfortunate because, for my application, I don't want the action to occur when the content item is saved but only when published.
Also, this event gets called twice when the save+publish button is clicked - not sure if this is how it is supposed to be - but it will not work for me.
I don't know if I'm doing it incorrectly because I haven't been able to find any documentation on the subject.
This is very disappointing - i really wanted to learn and use the new V6 API and not have to call obsolete code.
David
Check out PublishingStrategy.Publishing :-)
Thanks, Seb. That's it!
Here is a bit of example code for anyone who may want it:
Note - we don't need to call the "save" method because the item is on its way to being saved and published anyway.
Cheers,
David
cool, just what i needed! did not know Document.BeforePublish is gone. thanks,
G-
I came across this post, which definitely helped me - I ended up following the suggestion to use PublishingStrategy.Publishing event - which suits my needs. I just figured out an alternative way of doing it - I am now subscribing to ContentService.Saved (in ContentService there are lots of useful events, FYI), which also works for me.
Is one way (PublishingStrategy vs ContentService) preferrable over the other ? Which is the newer, recommended approach, which follows umbraco's new paradigms ? I am using Umbraco 7.
P.S. Here are the reasons for opting for ContentService instead of PublishingStrategy: 1) Looks more straightforward/clear to me 2 - the determinant factor :) Gives me the sender object, with which I have access to sender.Move method, which is what I ultimately need in my task.
Thanks
Update: Seems that the answer to my question is simply "they are 2 different events, but from the same umbraco (up-to-date) events model.
Indeed, IPublishingStrategy does not provide me with a sender object that has "Move", the created event - which provides a sender object of type IContentService, does. That's all. So for my purposes, I should indeed pick a Created-like event (one that provides me with an interface that implements Move).
is working on a reply...