Skip to content

Commit

Permalink
Add temporary PDF cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejackson1 committed Jul 23, 2024
1 parent b8a1326 commit 2038e4e
Show file tree
Hide file tree
Showing 18 changed files with 816 additions and 496 deletions.
29 changes: 16 additions & 13 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,21 @@ public static function delete_plugin_option( $key ) {
}

/**
* When provided the Gravity Form entry ID and PDF ID, this method will correctly generate the PDF, save it to disk,
* trigger appropriate actions and return the absolute path to the PDF.
* Generate a PDF, save it to disk, and return the absolute path to the document
*
* See https://docs.gravitypdf.com/v6/developers/api/create_pdf/ for more information about this method
*
* @param integer $entry_id The Gravity Form entry ID
* @param string $pdf_id The Gravity PDF ID number (the pid number in the URL when viewing a setting in the admin area)
* @param int $entry_id The Gravity Form entry ID
* @param string $pdf_id The Gravity PDF ID number (the pid number in the URL when viewing a setting in the admin area)
* @param bool $bypass_cache Force a new PDF to be generated
*
* @return mixed Return the full path to the PDF, or a WP_Error on failure
* @return string|WP_Error Return the full path to the PDF, or a WP_Error on failure
*
* @since 4.0
* @since 6.12 All PDFs are cached on disk for ~1 hour, but are auto-purged if the form, entry, or PDF settings change
* Re-running the method will return the cached PDF if it exists, unless $bypass_cache = true
*/
public static function create_pdf( $entry_id, $pdf_id ) {
public static function create_pdf( $entry_id, $pdf_id, $bypass_cache = false ) {

$form_class = static::get_form_class();

Expand All @@ -478,16 +480,17 @@ public static function create_pdf( $entry_id, $pdf_id ) {
return new WP_Error( 'invalid_pdf_setting', esc_html__( 'Could not located the PDF Settings. Ensure you pass in a valid PDF ID.', 'gravity-forms-pdf-extended' ) );
}

$pdf = static::get_mvc_class( 'Model_PDF' );
$form = $form_class->get_form( $entry['form_id'] );
if ( $bypass_cache ) {
add_filter( 'gfpdf_override_pdf_bypass', '__return_true' );
}

/** @var \GFPDF\Model\Model_PDF $pdf */
$pdf = static::get_mvc_class( 'Model_PDF' );
$path_to_pdf = $pdf->generate_and_save_pdf( $entry, $setting );

add_filter( 'gfpdf_override_pdf_bypass', '__return_true' );
do_action( 'gfpdf_pre_generate_and_save_pdf', $form, $entry, $setting );
$filename = $pdf->generate_and_save_pdf( $entry, $setting );
do_action( 'gfpdf_post_generate_and_save_pdf', $form, $entry, $setting );
remove_filter( 'gfpdf_override_pdf_bypass', '__return_true' );

return $filename;
return $path_to_pdf;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Controller_Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public function check_install_status() {
* Determine if we should be saving the PDF settings
*
* @since 4.0
*
* @deprecated 6.0
*/
public function maybe_uninstall() {
_doing_it_wrong( __METHOD__, 'This method has been moved to Controller_Uninstall::uninstall_addon()', '6.0' );
Expand Down
Loading

0 comments on commit 2038e4e

Please sign in to comment.