{"id":1263339,"date":"2017-04-03T06:21:24","date_gmt":"2017-04-03T13:21:24","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/"},"modified":"2017-04-06T08:31:53","modified_gmt":"2017-04-06T15:31:53","slug":"need-a-wordpress-filter-to-prevent-duplicate-imports","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/","title":{"rendered":"Need a WordPress filter to prevent duplicate imports"},"content":{"rendered":"<p>Hi there,<\/p>\n<p>I&#8217;m working for a client who wants to import events from an iCal feed. The only problem is, the feed provider doesn&#8217;t keep the UID unique&#8211; it changes periodically, about once a day. So, duplicate events are getting imported when we run a scheduled (cron) import. <\/p>\n<p>At first, I thoughtI could get around this by clearing out all events data before the cron job started. I hooked in to <code>tribe_aggregator_cron_run<\/code>, 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.<\/p>\n<p>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:<\/p>\n<p><code><br \/>\n\t\t\tif ( ! empty( $event['ID'] ) &amp;&amp; 'retain' === $update_authority_setting ) {<br \/>\n\t\t\t\t\/\/ Log this Event was Skipped<br \/>\n\t\t\t\t$activity-&gt;add( 'event', 'skipped', $event['ID'] );<br \/>\n\t\t\t\tcontinue;<br \/>\n\t\t\t}<br \/>\n<\/code><\/p>\n<p>but the problem here is that I can&#8217;t filter that data before we get to this line (at least, it doesn&#8217;t look like I can).<\/p>\n<p>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&#8217;s the only way I can see to do it, without hacking the plugin myself.<\/p>\n","protected":false},"template":"","class_list":["post-1263339","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Need a WordPress filter to prevent duplicate imports -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Need a WordPress filter to prevent duplicate imports -\" \/>\n<meta property=\"og:description\" content=\"Hi there, I&#8217;m working for a client who wants to import events from an iCal feed. The only problem is, the feed provider doesn&#8217;t keep the UID unique&#8211; 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 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-06T15:31:53+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/\",\"name\":\"Need a WordPress filter to prevent duplicate imports -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2017-04-03T13:21:24+00:00\",\"dateModified\":\"2017-04-06T15:31:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Event Aggregator\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/event-aggregator\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Need a WordPress filter to prevent duplicate imports\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Need a WordPress filter to prevent duplicate imports -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/","og_locale":"en_US","og_type":"article","og_title":"Need a WordPress filter to prevent duplicate imports -","og_description":"Hi there, I&#8217;m working for a client who wants to import events from an iCal feed. The only problem is, the feed provider doesn&#8217;t keep the UID unique&#8211; 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 [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/","article_modified_time":"2017-04-06T15:31:53+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/","name":"Need a WordPress filter to prevent duplicate imports -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2017-04-03T13:21:24+00:00","dateModified":"2017-04-06T15:31:53+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/need-a-wordpress-filter-to-prevent-duplicate-imports\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Event Aggregator","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/event-aggregator\/"},{"@type":"ListItem","position":5,"name":"Need a WordPress filter to prevent duplicate imports"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1263339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1263339\/revisions"}],"predecessor-version":[{"id":1265932,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1263339\/revisions\/1265932"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1263339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}