Need a WordPress filter to prevent duplicate imports

Home Forums Calendar Products Event Aggregator Need a WordPress filter to prevent duplicate imports

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1263339
    Bobbi
    Participant

    Hi there,

    I’m working for a client who wants to import events from an iCal feed. The only problem is, the feed provider doesn’t keep the UID unique– it changes periodically, about once a day. So, duplicate events are getting imported when we run a scheduled (cron) import.

    At first, I thoughtI could get around this by clearing out all events data before the cron job started. I hooked in to tribe_aggregator_cron_run, but it seems like that hook is called every time a cron batch runs. So when the cron kicked off, it deleted all the events; and then the cron job imported 5 events; and then the hook got called again and deleted the 5 events that were just imported, then 5 more events were imported, and so on.

    Next, I went looking in /Aggregator/Record/Abstract.php to see if I could prevent the duplicate event from being imported instead. My thought was to compare the post title, start date and end date to existing records in the database. I saw the code on lines 1051-1055:


    if ( ! empty( $event['ID'] ) && 'retain' === $update_authority_setting ) {
    // Log this Event was Skipped
    $activity->add( 'event', 'skipped', $event['ID'] );
    continue;
    }

    but the problem here is that I can’t filter that data before we get to this line (at least, it doesn’t look like I can).

    Could you add a filter that will let me change event data AND skip the import of the specific event, if I need to? That’s the only way I can see to do it, without hacking the plugin myself.

    #1265930
    Barry
    Member

    Hi Bobbi,

    Thanks for contacting us and apologies for the delayed response — we’ve been experiencing higher demand than normal and additionally have had some staff outages.

    Could you add a filter that will let me change event data AND skip the import of the specific event, if I need to?

    That sounds reasonable — I will log an issue on our internal tracker so we can think this one through and discuss the best approach.

    That’s the only way I can see to do it, without hacking the plugin myself.

    You don’t need to hack the plugin to achieve your goals: though perhaps not ideal, you could use WordPress’s standard save_post_{POST_TYPE} action to examine each venue, organizer and event that has been created and then amend or delete them as appropriate.

    Combining this with some tests to check if your callbacks are operating in the context of the importer admin screen or a cron job could help you to further tighten this process up.

    I hope that gives you some further options to explore and, again, I’ll be sure to log an item for us to look at adding additional hooks in our own code to better facilitate your goals in the future.

    Thanks!

    #1265934
    Bobbi
    Participant

    Excellent, good thought, Barry! I’ll look into save_post in the meantime.

    #1266334
    Barry
    Member

    Awesome, thanks Bobbi (also, I linked this forum topic to the proposal on our internal issue tracker, so we should be able to post an update in here once relevant changes have been made).

    Thanks again!

    #1275905
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Need a WordPress filter to prevent duplicate imports’ is closed to new replies.