Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Evans 86 posts 116 karma points
    Oct 16, 2014 @ 11:29
    Mark Evans
    0

    help with content publishing

    im looking into how to publish umbraco content to another database.

    i have come across the ContentPublished event that fires when a content item is published in the admin. 

    However im not sure how i access the content item and determine its id prior to inserting into another db.

    any guidance appreciated....

     

  • Damian Green 452 posts 1433 karma points
    Oct 16, 2014 @ 13:52
    Damian Green
    0

    Hi Mark,

    This doc explains the ContentService

    http://our.umbraco.org/documentation/Reference/Events-v6/ContentService-Events

    What you get is a collection of published nodes (because more than one can be published at once).

    Then, for each item, determine if it is a type you want to handle and then work with that item.

    Something like this (this is on the unbpublished so you would want the published also):

    private void ContentServiceOnUnPublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            //Add any types you add that should never appear in navigation to this list
            //
            var typesRequired = new List<string>
            {
                "typea",
                "typeb"                
            };
    
            //Ensure we wil never see the info items in the menus or sitemaps
            //
            foreach (var page in e.PublishedEntities.Where(page => typesRequired.Contains(page.ContentType.Alias.ToLower().Trim())))
            {
                //do your stuff
                //
                try
                {
                    LogHelper.Info<ArchiveUnpublishedJobs>(string.Format("doing something to {0}({1}) after un-publish - ", page.Name, page.Id));
    
                    // Example move using ContentService API
                    //
                    UmbracoContext.Current.Application.Services.ContentService.Move(page, targetid);
                }
                catch (Exception x)
                {
                    LogHelper.Error<ArchiveUnpublishedJobs>(string.Format("Error doing something {0}({1}) after un-publish - ", page.Name, page.Id), x);
                }
    
            }
        }
    

    ArchiveUnpublishedJobs is the name of the class im using here so you can see where the error was raised i nthe logger when you look in the logs.

    Does that help you?

    Damian

  • Damian Green 452 posts 1433 karma points
    Oct 16, 2014 @ 13:54
    Damian Green
    0

    You would also get the id using page.Id (page is an IContent) in the example above.

    Damian

  • Mark Evans 86 posts 116 karma points
    Oct 16, 2014 @ 16:30
    Mark Evans
    0

    thanks damian,

    im getting the page.Id via this method, im not sure how i get the properties for pageTitle and bodyText which will be the ones i would want to send to the external site db via a stored procedure....

     

  • Damian Green 452 posts 1433 karma points
    Nov 07, 2014 @ 14:47
    Damian Green
    0

    Hi,

    Sorry i missed the update to this post. Did you get it done?

    Just use the GetPropertyValue("alias") on the content node.

    You can alaso use property converters if you know the type it is - for example GetPropertyValue

    Please mark as solution you are sorted out.

    Cheers, Damian

Please Sign in or register to post replies

Write your reply to:

Draft