I have been busy creating a 'member content management' type setup with Contour, and one of the key things is to keep the created node in sync with the record (using workflows in record > node & events/action handlers in node > record). I have written this as I cannot seem to update the record in an action handler (that is called on unpublish action- required so I can implement expire at date on the node).
Full Action hanlder: (runs as expected, but the commented lines in meat of it cause it to fail):
using System; using System.Collections.Generic; using System.Text; using umbraco.cms.businesslogic.web; using umbraco.BusinessLogic; using Umbraco.Forms.Core; using Umbraco.Forms.Core.Services; using Umbraco.Forms.Data; using Umbraco.Forms.Data.Storage;
namespace AdvertPublishing {
/// <summary> /// Helps us with housekeeping - deleting node after (auto) unpublishing; /// </summary> public class UnPublishActionHandler : umbraco.BusinessLogic.Actions.IActionHandler { #region IActionHandler RemoveAdHandler
public bool Execute(Document sender, umbraco.interfaces.IAction action) { /// <summary> /// have to use the action handler rather than unpublish event because the event doesn't get called when a document /// is being automatically expired (unpublished) /// </summary> if (action.Alias == umbraco.BusinessLogic.Actions.ActionUnPublish.Instance.Alias) {
//Only applies for Advert if (sender.ContentType.Alias == "Advert") { Log.Add(LogTypes.Custom, 0, "UnPublishActionHandler Executed in RemoveAdHandler");
//Check if content has recordGuid if (!String.IsNullOrEmpty(sender.getProperty("recordGuid").Value.ToString())) {
var storage = new RecordStorage(); Record record = storage.GetRecord(new Guid(sender.getProperty("recordGuid").Value.ToString())); RecordService rs = new RecordService(record); Form form = new FormStorage().GetFormFromRecordId(record.Id);
// Clear node from record record.GetRecordField("Node").Values.Clear(); record.GetRecordField("Duration").Values.Clear(); storage.UpdateRecord(record, form); //storage.UpdateRecordXml(record, form); //storage.Dispose(); //rs.Submit(); //rs.Dispose();
Any thoughts, have I missed something (seemingly) obvious, or is there something with the context of an action handler that the contour record stoage etc won't work.
Also while here, can you not delete a node from an upublish action? As that doesn't work either :(
No errors, the script just doesnt make it to the following Log.Add - I wrapped the lot in a try catch, and logged the catch, but this didnt reveal anything either, the script still partially runs and just stops when hits something it does't like (sender.delete() also).
Because it's running in an automated thread, there is no way to physically watch this happen (that I know of), can you suggest anything to debug it?
But, at least you cant see anything obv wrong with code, or experienced similar before?
I got back to this again, and looks like the record stuff needs HttpContext / umbracoContext (which can't be available from the event handlers??) - with error thrown by the
storage.UpdateRecordXml(record,form);
is as follows:
System.ArgumentNullException: Value cannot be null.
Parameter name: umbracoContext
at Umbraco.Web.UmbracoHelper..ctor(UmbracoContext umbracoContext)
at Umbraco.Forms.Core.Record.ToXml(XmlDocument xd)
at Umbraco.Forms.Data.Storage.RecordStorage.UpdateRecordXml(Record record, Form form)
at AdvertPublishing.UnPublishActionHandler.Execute(Document sender, IAction action)
Further the RecordService also fails if in the unpublish event handler:
System.NullReferenceException:
The HttpContext property has not been set or the object execution is
not running inside of an HttpContext
at umbraco.BusinessLogic.StateHelper.get_HttpContext()
at umbraco.BusinessLogic.StateHelper.Cookies.get_HasCookies()
at umbraco.BusinessLogic.StateHelper.SetCookieValue(String key,
String value, Double daysToPersist)
at Umbraco.Forms.Core.Services.RecordService.()
at Umbraco.Forms.Core.Services.RecordService.Submit()
at
AdvertPublishing.UnpublishAdHandler.Document_AfterUnPublish(Document
sender, UnPublishEventArgs e)
As a temp workaround you could place the code on a seperate page and then request that page from the action handler, not ideal but a fast workaround...
Update record in action handler
Hi guys
I have been busy creating a 'member content management' type setup with Contour, and one of the key things is to keep the created node in sync with the record (using workflows in record > node & events/action handlers in node > record). I have written this as I cannot seem to update the record in an action handler (that is called on unpublish action- required so I can implement expire at date on the node).
Full Action hanlder: (runs as expected, but the commented lines in meat of it cause it to fail):
Relevant lines and why would these not work:
Any thoughts, have I missed something (seemingly) obvious, or is there something with the context of an action handler that the contour record stoage etc won't work.
Also while here, can you not delete a node from an upublish action? As that doesn't work either :(
Thanks!
Josh
Comment author was deleted
Hi,
Do you get any errors when those lines aren't commented out? If so could you provide the error messages
No errors, the script just doesnt make it to the following Log.Add - I wrapped the lot in a try catch, and logged the catch, but this didnt reveal anything either, the script still partially runs and just stops when hits something it does't like (sender.delete() also).
Because it's running in an automated thread, there is no way to physically watch this happen (that I know of), can you suggest anything to debug it?
But, at least you cant see anything obv wrong with code, or experienced similar before?
Comment author was deleted
Don't see any issue with the code, you should be able to debug when attaching to the process and adding a breakpoint
Hi Tim
I got back to this again, and looks like the record stuff needs HttpContext / umbracoContext (which can't be available from the event handlers??) - with error thrown by the
is as follows:
Further the RecordService also fails if in the unpublish event handler:
Comment author was deleted
Ok thanks for the details will add this to our issue tracker and take a look at it for the next maintenance release...
Comment author was deleted
The issue: http://issues.umbraco.org/issue/CON-221
Comment author was deleted
As a temp workaround you could place the code on a seperate page and then request that page from the action handler, not ideal but a fast workaround...
Thanks Tim, that's where I was headed (as you say not ideal, but will have to do meantime).
Please update when there is resolution and I'll mark the thread as solved ;)
is working on a reply...