U4-1875 - Cancelling ContentService.Creating event not working

Created by Andreas Iseli 10 Mar 2013, 11:07:02 Updated by Andreas Iseli 23 Mar 2013, 09:30:04

When attaching an event handler to the Creating event of the ContentService and cancelling the event, the content (document) is still being created. This affects only content items being created through the UI.

Example:

public void ContentCreating(IContentService sender, NewEventArgs e)

I've triggered down the problem to the Document.MakeNew(...) method. The contentTasks still calls for backward compatibility the named method, and this method then calls the ContentService.CreateContent(...) method. But when the Creating is canceled in the ContentService.CreateContent(...) method, the Document.MakeNew(...) method ignores this cancelling event.

Here is an extract of the method:

Document.OnNewing(newingArgs); if (newingArgs.Cancel) { return null; }

//Create a new IContent object based on the passed in DocumentType's alias, set the name and save it IContent content = ApplicationContext.Current.Services.ContentService.CreateContent(Name, ParentId, dct.Alias, u.Id); ApplicationContext.Current.Services.ContentService.Save(content, u.Id);

//read the whole object from the db Document d = new Document(content);

//event NewEventArgs e = new NewEventArgs(); d.OnNew(e);

// Log LogHelper.Info(string.Format("New document {0}", d.Id));

// Run Handler umbraco.BusinessLogic.Actions.Action.RunActionHandlers(d, ActionNew.Instance);

// Save doc d.Save();

The problem is the call to d.Save() that is being reached because the cancelling of the Creating event within ContentService.CreateContent(...) is not threatened respectively.

Comments

Andreas Iseli 10 Mar 2013, 11:09:08

I've currently attached a second event receiver to the Document.Newing event to workaround this problem.


Andreas Iseli 10 Mar 2013, 11:11:53

This has the same effect / behavior for the ContentService.Created versus Document.New events. When deleting the document in the ContentService.Created event it is still available afterwards. There is also the difference that the IContent.Id is not set in the Created event but only in the Document.New event.


Morten Christensen 21 Mar 2013, 18:37:31

Fixed in changeset 90cbecebf4c1 - will post link to nightly build when its ready.


Morten Christensen 21 Mar 2013, 19:14:45

Nightly build with fix for this issue is available here: http://nightly.umbraco.org/umbraco%206.0.3/UmbracoCms.6.0.3-build.14.zip


Andreas Iseli 23 Mar 2013, 09:30:04

Thanks!


Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.2

Due in version: 6.0.3

Sprint:

Story Points:

Cycle: