GravityPDF / gravity-pdf

Gravity PDF is a GPLv2-licensed WordPress plugin that allows you to automatically generate, email and download PDF documents using Gravity Forms.
https://gravitypdf.com
89 stars 21 forks source link

Reset the Background Queue after Dispatch #1446

Closed jakejackson1 closed 1 year ago

jakejackson1 commented 1 year ago

Description

This fixes an issue when creating multiple entries via the GFAPI, whereby the queue was not empty before each new entry was processed. The more entries added in a single request, the more duplicate notifications were sent.

Testing instructions

  1. Enable PDF Notifications on a test form and PDF Background Processing in the settings
  2. Generate multiple entries on demand using code like this:
add_action('admin_init', function() {
    if( empty( $_GET['test1'] ) ) {
        return;
    }

    $backup_post = $_POST;

    for ( $i = 0; $i < 3; $i ++ ) {
        $entry = [
            'input_1' => 'test' . rand(),
            'input_3' => 'test' . rand(),
            'input_4' => 'test' . rand(),
        ];

        $results = \GFAPI::submit_form( 848, $entry );

        $_POST = $backup_post;
        \GFFormsModel::flush_current_lead();
        \GFFormDisplay::$submission = [];
    }
} );
  1. Verify you only get 3 emails with a PDF attached to each.

Screenshots

Checklist:

Additional Comments

codecov[bot] commented 1 year ago

Codecov Report

Merging #1446 (5390a53) into development (60824d2) will increase coverage by 17.59%. The diff coverage is n/a.

@@                Coverage Diff                 @@
##             development    #1446       +/-   ##
==================================================
+ Coverage          75.70%   93.30%   +17.59%     
==================================================
  Files                243       57      -186     
  Lines              12827     1464    -11363     
  Branches             370      370               
==================================================
- Hits                9711     1366     -8345     
+ Misses              3108       90     -3018     
  Partials               8        8               
Impacted Files Coverage Δ
src/Controller/Controller_Pdf_Queue.php
src/Helper/Helper_Field_Container_Void.php
src/View/html/Settings/tabs.php
src/Helper/Fields/Field_Multiselect.php
src/Helper/Helper_Abstract_Fields.php
src/templates/rubix.php
src/Helper/Fonts/TtfFontValidation.php
src/Model/Model_Actions.php
src/autoload.php
src/Helper/Fields/Field_Tos.php
... and 176 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.