• Resolved Torsten H?ndler

    (@shogathu)


    Hey it would be nice if you can implement an option that only new entries after the last export will be exported. If I export data twice or more a day, all entries are in the file.


    Or it would be nice if you can implement an action to manipulate the entries after the export file was created, so that you can hook into and maybe update a hidden field value so you can set a value to the field and then filter the entries with your ‘gfexcel_output_search_criteria’ filter.

    I implement such an action, but it will be gone after update the plugin.

    You simply can add in

    gf-entries-in-excel/build/vender_prefixed/gravitykit/gravityexport-lite-src/GFExcelOutput.php:319

    do_action('gfexcel_after_get_entries', $this->entries, $this->form_id, $this->feed_id);

    before the return.

    Maybe you can add this in the free version. The Premium version we have did also don’t have this option

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Doeke Norg

    (@doekenorg)

    Hi @shogathu,

    Thank you for reaching out.

    Your situation is highly specific, even though I can see why you’d want to use it. However, most people actually want the entire list every time. So I think the way you’ve handled this is fine. There is one thing I would change, and that is to use the existing gfexcel_event_download hook. This is actually fired just before the actual download. At that point you can store a timestamp for that specific form.

    Then you can indeed use the gfexcel_output_search_criteria hook to exclude any entries before that timestamp.

    This question has triggered us to include a timestamp for the latest download in the feed settings. Once this has been added, you can use that value instead of storing it yourself with the gfexcel_event_download hook. Here is a link to the Github issue, so that you may keep an eye on that: https://github.com/GravityKit/GravityExport-Lite/issues/194. Unfortunately I can’t provide you with an ETA on this.

    Hope this helps you out for now.

    Kind regards,

    Doeke
    GravityKit

    Thread Starter Torsten H?ndler

    (@shogathu)

    Hello Doeke,

    thanks for your quick response. Before I wrote the ticket I tested it with the gfexcel_event_download Action but for my case it won’t work because we use the premium version with different export filter feeds, and we have to trigger which feed was used and update a field in the entry, that this entry was downloaded. Your gfexcel_event_download action triggers right between the response but before get the entry list, so our field in the entry was update before the list with the search_creteria filter was created and the list was empty

    But I thank you that you want to include the timestamp that will also help us.

    Best regards

    Torsten

    Plugin Author Doeke Norg

    (@doekenorg)

    @shogathu You are right, I missed the part where the download event is triggered before the entries are retrieved. I’ll look into a better event, maybe just after the download has been rendered.

    In either case, I have a (slightly inelegant) solution for you.

    $is_download = false;
    
    add_filter( 'gfexcel_event_download', function () use ( &$is_download ) {
    	$is_download = true;
    } );
    
    add_filter( 'gfexcel_output_search_criteria', function ( $criteria, $form_id, $feed_id ) use ( &$is_download ) {
    	if ( ! $is_download ) {
    		return $criteria;
    	}
    
    	$feed = GFAPI::get_feed( $feed_id );
    	if (
    		$feed instanceof WP_Error
    		|| ! ( $feed['is_active'] ?? 0 )
    		|| ! $feed['meta']
    	) {
    		return $criteria;
    	}
    
        $download_at  = $feed['meta']['custom-downloaded_at'] ?? 0;
    	if ( $download_at > 0 ) {
    		$criteria['start_date'] = wp_date( 'Y-m-d H:i:s', $download_at );
    	}
    
    	// Update feed for next download.
    	$feed['meta']['custom-downloaded_at'] = wp_date( 'U' );
    
    	GFAPI::update_feed( $feed_id, $feed['meta'], $form_id );
    
    	return $criteria;
    }, 10, 3 );

    So the idea is that we store a custom-download_at value on the feed. This way it is scoped to the feed, and not the entire form. The gfexcel_download_event only records that we are currently working with a download (and no other reason to retrieve the entries). Then the gfexcel_output_search_criteria looks for this value. If we are downloading we see if we recorded a custom-download_at time, and use that as a start_date. After we updated the criteria, we also update that timestamp for the next download.

    Please note we need the “pass-by-reference” &-sign before the $is_download to be able to track the changes of the value. Otherwise we would get a static value of false. And I’ve use custom-download_at because I think we will call the parameter download_at on our end once the time comes. So this will avoid issues when updating later on.

    I hope this makes sense, and helps you out for now; so you can keep updating the plugins.

    Kind regards,

    Doeke

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Export only new entries since last export’ is closed to new replies.