Copied to clipboard

Flag this post as spam?

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


  • Michael Worrall 57 posts 82 karma points
    Nov 29, 2011 @ 17:21
    Michael Worrall
    0

    Scheduled import tasks

    Hi,

    Before I purchase a licence for this package I need to know whether or not it is possible within a scheduled import task to only import new records and not records that already exist within umbraco?

    For example: I have a db table with a unique id (which I would store in a property within umbraco) from the external data source that I'd like to import once a hour say, but once a record has been imported I only want the scheduled task to import new records only.  Is this possible within CMS Import?  If so how?

    Thanks,

    Mike

  • Richard Soeteman 4039 posts 12887 karma points MVP 2x
    Nov 29, 2011 @ 17:47
    Richard Soeteman
    0

    Hi Mike,

    You need to program a few lines of code for that. CMSImport comes with an event system. Before a record gets imported it will raise the RecordImporting event. When you cancel that event the record will not be imported. Below a snippet how CMSImport will find a relation between your datasource and nodes in Umbraco and cancel the event when a document is found. So only new records will be imported.In the result screen you will see skipped records after import. These are the records that you've canceled using the event.

        public class CancelEvent :ApplicationBase
        {
            public CancelEvent()
            {
                // Wires up the event handler
                ContentImport.RecordImporting += new ContentImport.RecordImportingEventHandler(ContentImport_RecordImporting);
            }
    
            private void ContentImport_RecordImporting(object sender, RecordImportingEventArgs e)
            {
                //Cancel the importing event when a relation is found in the database
                e.Cancel = ContentRelation.GetRelatedDocument(e.DataAdapter, e.DataKeyName, e.DataKeyValue) != null;
            }
        }
    

    To use this snippet add references to the dll's

    - umbraco

    - cms

    - businesslogic

    - interfaces

    - Cmsimport.Extensions

    This example will only work in PRO because of the relation that is only available in the PRO edition.

    Hope this helps you, if not please let me know

    Best,

    Richard

  • Michael Worrall 57 posts 82 karma points
    Dec 01, 2011 @ 15:41
    Michael Worrall
    0

    Hi Rchard,

    Thanks for that, I've purchased a licence all ready to mess around with the events as you suggest and noticed that CMS import already seems to do the job of checking for existing records and skipping them already!

    Thanks,

    Mike

  • Richard Soeteman 4039 posts 12887 karma points MVP 2x
    Dec 01, 2011 @ 15:48
    Richard Soeteman
    0

    Hi Mike,

    Yes stupid me. you can skip records from UI indeed :-(

    Thanks for the purchae by the way.

    Best,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft