Action Handler Question Options
kutedawako
Posted: Sunday, October 14, 2007 7:27:41 AM
Rank: Devotee

Joined: 9/12/2007
Posts: 58
Location: Honoluu, HI
I created a calendar item action handler that responds to a publish event. It moves the calendar item to a specified folder based on the start date specified as a page property. It creates the folders if it doesnt exist.

*** This is the somewhat the same to Niel's blog post action handler that places the blog item to the specified folder based on the create date during an action new event.

Here is my tree structure:

Calendar (Calendar Page doc type) > Year (Calendar Page) > Month (Calendar Page) > Event (Calendar Item)


The PROBLEM I am having is displaying the items in the calendar page. The actual item is not published after it was moved but all the folder are displayed. I tried using the following code

Code:

month.Move(document.ID);
document.publish(document.user);
library.publishSingleNode(document.ID);


to publish the item but that causes an infinite loop because I am calling a publish method in a publish event.

Got any ideas?

Thank you for your help in advance,

John Cruz
kutedawako
Posted: Wednesday, November 07, 2007 3:19:19 AM
Rank: Devotee

Joined: 9/12/2007
Posts: 58
Location: Honoluu, HI
This issue has been resolve by using the method

content.Instance.RefreshContentFromDatabaseAsync();

See full code snipppet below.

Code:

public bool Execute(Document documentObject, IAction action)
        {
            if (documentObject.ContentType.Alias != "Calendar Item") return false;
            CMSNode parentNode = FindRootNodeWithDocType(documentObject.Parent, CALENDARPAGEDOCTYPE);
            if (parentNode != null)
            {                                
                Property p = documentObject.getProperty("startDate");                
                DateTime startDate = Convert.ToDateTime(p.Value);  
              
                string[] dateArray =
                        {                                
                            startDate.ToString("yyyy"), // Full year name (2007)
                            startDate.ToString("MMMM")  // Full month name (October)
                        };

                try
                {  
                    // Retrieve year and month documents
                    Document docYear = GetDocument(documentObject, parentNode, CALENDARPAGEDOCTYPE, dateArray[0]);                    
                    Document docMonth = GetDocument(documentObject, docYear, CALENDARPAGEDOCTYPE, dateArray[1]);                    

                    // move and publish the Calendar item document
                    if (documentObject.Parent.Id != docMonth.Id)
                    {
                        documentObject.Move(docMonth.Id);
                        content.Instance.RefreshContentFromDatabaseAsync();                                                
                    }
                }
                catch (Exception ex)
                {
                    Log.Add(LogTypes.Error, documentObject.User, documentObject.Id, ex.Message);
                    return false;
                }
            }
            return true;
        }
martinbentzen
Posted: Monday, November 12, 2007 1:40:43 PM
Rank: Devotee

Joined: 7/20/2006
Posts: 48
Location: Copenhagen, Denmark
I'm juggle with the same problem, but I can't solve it as you state.

my code:
Code:
using System;
using umbraco.cms.businesslogic.web;
using umbraco;

namespace naesby
{
    public class CalendarYearPostHandler : umbraco.BusinessLogic.Actions.IActionHandler
    {
        public CalendarYearPostHandler()
        {
        }
        #region IActionHandler Members

        public string HandlerName()
        {
            return "Create Calendar Year Folder";
        }

        public bool Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action)
        {           
            if (documentObject.ContentType.Alias == "UmbracoNaesbyCalendarEntry")
            {               

                    if (new Document(documentObject.Parent.Id).ContentType.Alias != "UmbracoNaesbyCalendarYear")
                    {

                        string refNr = (documentObject.getProperty("EventStart").Value.ToString().Substring(6,4));


                       
                        if (refNr.Length == refNr.Length)
                        {
                            // Check if year exists
                            Document year = null;
                            foreach (umbraco.BusinessLogic.console.IconI i in documentObject.Parent.Children)
                            {
                                if (i.Text == refNr)
                                {
                                    year = new Document(i.Id);
                                    break;
                                }
                            }

                            if (year == null)
                            {
                                year = Document.MakeNew(refNr, DocumentType.GetByAlias("UmbracoNaesbyCalendarYear"), documentObject.User, documentObject.Parent.Id);
                                year.Publish(documentObject.User);
                                umbraco.library.PublishSingleNode(year.Id);
                            }
                            else
                                umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, documentObject.User, documentObject.Id, "executed - year not null");

                            documentObject.Move(year.Id);
                            content.Instance.RefreshContentFromDatabaseAsync();
                        }                   
                }
                return true;
            }
            else
                return false;
        }

        public umbraco.interfaces.IAction[] ReturnActions()
        {
            umbraco.interfaces.IAction[] ia = { new umbraco.BusinessLogic.Actions.ActionPublish() };
            return ia;
        }

        #endregion
    }
}


Udblog.dk
kutedawako
Posted: Monday, November 12, 2007 8:04:37 PM
Rank: Devotee

Joined: 9/12/2007
Posts: 58
Location: Honoluu, HI
Hello Martin,

Give me your email and I will send you my code.
martinbentzen
Posted: Monday, November 12, 2007 9:11:25 PM
Rank: Devotee

Joined: 7/20/2006
Posts: 48
Location: Copenhagen, Denmark
John,

Many thanx for your help!
My mail is martin at bentzen dot dk

Regards
Martin

Udblog.dk
martinbentzen
Posted: Monday, December 10, 2007 11:13:08 AM
Rank: Devotee

Joined: 7/20/2006
Posts: 48
Location: Copenhagen, Denmark
John M. Cruz wrote:

Give me your email and I will send you my code.


John,
Do you have time to drop me a mail or post your code here ?
Thanx in advantage!

Kindly regards
Martin


Udblog.dk
martinbentzen
Posted: Friday, December 14, 2007 1:25:25 PM
Rank: Devotee

Joined: 7/20/2006
Posts: 48
Location: Copenhagen, Denmark
John,

Thanks a lot for your help! But... I still have the issue....

It seems that the entry is moved to the correct folder (and calendar pages is created correctly as well). The link to the entry is also correct, eg: site.com/2007/december/entry.aspx

But at the property page for the entry, the link is still site.com/entry.aspx. When I manually Save and Publish the page, this is corrected...

Whats your experiences ?

Best regards
Martin

Udblog.dk
kutedawako
Posted: Friday, December 14, 2007 9:15:36 PM
Rank: Devotee

Joined: 9/12/2007
Posts: 58
Location: Honoluu, HI
can you elaborate more on your problem because I dont know what issue your having?
mikew909
Posted: Tuesday, March 04, 2008 1:21:25 PM
Rank: Newbie

Joined: 9/26/2007
Posts: 10
Hey guys I have the same problem can anyone help?

Creating content with API works perfectly but is not visible until I right click in Umbraco and publish the top level , Ive tried

content.Instance.RefreshContentFromDatabaseAsync();

and

umbraco.library.RePublishNodes(1113); // where 1113 is the root node

and still the only way I can get it to show is the manual interaction.

Is this method correct? Its the final piece of the pizzle :whistle:

cheers and beers
primoz
Posted: Wednesday, March 26, 2008 2:19:37 PM
Rank: Newbie

Joined: 2/26/2007
Posts: 10
Location: Slovenia
martinbentzen wrote:
John,

Thanks a lot for your help! But... I still have the issue....

It seems that the entry is moved to the correct folder (and calendar pages is created correctly as well). The link to the entry is also correct, eg: site.com/2007/december/entry.aspx

But at the property page for the entry, the link is still site.com/entry.aspx. When I manually Save and Publish the page, this is corrected...

Whats your experiences ?

Best regards
Martin


I have same problem. Did you find anything out?
primoz
Posted: Wednesday, March 26, 2008 2:49:10 PM
Rank: Newbie

Joined: 2/26/2007
Posts: 10
Location: Slovenia
martinbentzen wrote:
John,

Thanks a lot for your help! But... I still have the issue....

It seems that the entry is moved to the correct folder (and calendar pages is created correctly as well). The link to the entry is also correct, eg: site.com/2007/december/entry.aspx

But at the property page for the entry, the link is still site.com/entry.aspx. When I manually Save and Publish the page, this is corrected...

Whats your experiences ?

Best regards
Martin


Ok, I figure it out. You have to call Move method to move document to right parent. Then your URL will be ok.
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.