Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into 756-pdf-document-data-in-process
Browse files Browse the repository at this point in the history
# Conflicts:
#	includes/class-wcpdf-admin.php
#	includes/wcpdf-functions.php
  • Loading branch information
MohamadNateqi committed Sep 2, 2024
2 parents 7029ecf + 0237aee commit 9bf76b5
Show file tree
Hide file tree
Showing 22 changed files with 700 additions and 425 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/release-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ jobs:
path: ${{ env.plugin_slug }}
submodules: true

- name: Check stable version in readme.txt
run: |
STABLE_TAG=$(grep -oP '(?<=Stable tag: ).*' ${{ env.plugin_slug }}/readme.txt | tr -d '[:space:]')
if [ "$STABLE_TAG" != "${{ env.version }}" ]; then
echo "Stable tag ($STABLE_TAG) does not match release version (${{ env.version }}). Halting execution."
exit 1
fi
- name: Create ZIP
run: |
# reformat .distignore: remove all empty lines, leading slashes and prefix with the folder
Expand All @@ -37,7 +45,7 @@ jobs:
# create zip file
zip -rq ${{ env.zip_file_name }} ${{ env.plugin_slug }} -x@.zipignore
- name: Add ZIP to release asseets
- name: Add ZIP to release assets
uses: meeDamian/github-release@2.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 0 additions & 3 deletions assets/js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,6 @@ jQuery( function( $ ) {
// (See also https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding.)
pdfData = window.atob( pdfData );

// Loaded via <script> tag, create shortcut to access PDF.js exports.
let pdfjsLib = window['pdfjs-dist/build/pdf'];

// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = worker;

Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-script.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/js/debug-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ jQuery( function( $ ) {
contentType: false,
success ( response ) {
process_form_response( tool, response, $form );
$form.closest( '.tool' ).unblock();
},
error ( xhr, error, status ) {
//console.log( error, status );
$form.closest( '.tool' ).unblock();
}
} );
}

$form.closest( '.tool' ).unblock();
} );

function process_form_response( tool, response, $form ) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/debug-script.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 2 additions & 22 deletions assets/js/pdf_js/pdf.min.js

Large diffs are not rendered by default.

24 changes: 2 additions & 22 deletions assets/js/pdf_js/pdf.worker.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions includes/class-wcpdf-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ public function output_number_date_edit_fields( object $document, array $data =
return;
}

$data = apply_filters( 'wpo_wcpdf_document_data_meta_box_fields', $data, $document );

// Go for default data.
if ( empty( $data ) ) {
$document_title = $document->get_title();
Expand Down
7 changes: 4 additions & 3 deletions includes/class-wcpdf-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function frontend_scripts_styles ( $hook ) {
* Load styles & scripts
*/
public function backend_scripts_styles ( $hook ) {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$pdfjs_version = '4.3.136';

global $wp_version;
if ( WPO_WCPDF()->admin->is_order_page() ) {
Expand Down Expand Up @@ -146,7 +147,7 @@ public function backend_scripts_styles ( $hook ) {
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'template_paths' => WPO_WCPDF()->settings->get_installed_templates(),
'pdfjs_worker' => WPO_WCPDF()->plugin_url() . '/assets/js/pdf_js/pdf.worker.min.js?ver=' . WPO_WCPDF_VERSION, // taken from https://cdnjs.com/libraries/pdf.js
'pdfjs_worker' => WPO_WCPDF()->plugin_url() . '/assets/js/pdf_js/pdf.worker.min.js?ver=' . $pdfjs_version, // taken from https://cdnjs.com/libraries/pdf.js
'preview_excluded_settings' => apply_filters( 'wpo_wcpdf_preview_excluded_settings', array(
// general
'download_display',
Expand Down Expand Up @@ -195,7 +196,7 @@ public function backend_scripts_styles ( $hook ) {
'wpo-wcpdf-pdfjs',
WPO_WCPDF()->plugin_url() . '/assets/js/pdf_js/pdf.min.js', // taken from https://cdnjs.com/libraries/pdf.js
array(),
'3.11.174'
$pdfjs_version
);
}

Expand Down
46 changes: 2 additions & 44 deletions includes/class-wcpdf-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,6 @@

class Main {

/**
* Lock name
*
* @var string
*/
public $lock_name;

/**
* Lock context
*
* @var array
*/
public $lock_context;

/**
* Lock time limit if the release doesn't happen before
*
* @var int
*/
public $lock_time;

/**
* Lock retries
*
* @var int
*/
public $lock_retries;

/**
* Lock loggers
*
* @var int
*/
public $lock_loggers;

/**
* Temp subfolders
*
Expand All @@ -65,13 +30,6 @@ public static function instance() {
}

public function __construct() {
// semaphore
$this->lock_name = 'wpo_wcpdf_main_semaphore_lock';
$this->lock_context = array( 'source' => 'wpo-wcpdf-semaphore' );
$this->lock_time = apply_filters( 'wpo_wcpdf_main_semaphore_lock_time', 60 );
$this->lock_retries = apply_filters( 'wpo_wcpdf_main_semaphore_lock_retries', 0 );
$this->lock_loggers = apply_filters( 'wpo_wcpdf_main_semaphore_lock_loggers', isset( WPO_WCPDF()->settings->debug_settings['semaphore_logs'] ) ? array( wc_get_logger() ) : array() );

add_action( 'wp_ajax_generate_wpo_wcpdf', array( $this, 'generate_document_ajax' ) );
add_action( 'wp_ajax_nopriv_generate_wpo_wcpdf', array( $this, 'generate_document_ajax' ) );

Expand Down Expand Up @@ -181,9 +139,9 @@ public function attach_document_to_email( $attachments, $email_id, $order, $emai
}

$attach_to_document_types = $this->get_documents_for_email( $email_id, $order );
$lock = new Semaphore( $this->lock_name . "_order_{$order_id}_email_{$email_id}", $this->lock_time, $this->lock_loggers, $this->lock_context );
$lock = new Semaphore( "attach_doc_to_email_{$email_id}_from_order_{$order_id}" );

if ( $lock->lock( $this->lock_retries ) ) {
if ( $lock->lock() ) {

$lock->log( sprintf( 'Lock acquired for attach document to email for order ID# %s.', $order_id ), 'info' );

Expand Down
21 changes: 6 additions & 15 deletions includes/class-wcpdf-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ class Settings {
public $general_settings;
public $debug_settings;
public $ubl_tax_settings;
public $lock_name;
public $lock_context;
public $lock_time;
public $lock_retries;
public $lock_loggers;

private $installed_templates = array();
private $installed_templates_cache = array();
Expand All @@ -53,12 +48,6 @@ public function __construct() {
$this->debug_settings = get_option( 'wpo_wcpdf_settings_debug' );
$this->ubl_tax_settings = get_option( 'wpo_wcpdf_settings_ubl_taxes' );

$this->lock_name = 'wpo_wcpdf_settings_semaphore_lock';
$this->lock_context = array( 'source' => 'wpo-wcpdf-semaphore' );
$this->lock_time = apply_filters( 'wpo_wcpdf_settings_semaphore_lock_time', 60 );
$this->lock_retries = apply_filters( 'wpo_wcpdf_settings_semaphore_lock_retries', 0 );
$this->lock_loggers = apply_filters( 'wpo_wcpdf_settings_semaphore_lock_loggers', isset( $this->debug_settings['semaphore_logs'] ) ? array( wc_get_logger() ) : array() );

// Settings menu item
add_action( 'admin_menu', array( $this, 'menu' ), 999 ); // Add menu
// Links on plugin page
Expand Down Expand Up @@ -362,6 +351,8 @@ public function ajax_preview() {
}

} catch ( \Throwable $th ) {
wcpdf_log_error( 'Error trying to generate document: ' . $th->getTraceAsString(), 'critical' );

wp_send_json_error(
array(
'error' => sprintf(
Expand Down Expand Up @@ -807,7 +798,7 @@ public function schedule_yearly_reset_numbers() {

$next_year = strval( intval( current_time( 'Y' ) ) + 1 );
$datetime = new \WC_DateTime( "{$next_year}-01-01 00:00:01", new \DateTimeZone( wc_timezone_string() ) );
$lock = new Semaphore( $this->lock_name, $this->lock_time, $this->lock_loggers, $this->lock_context );
$lock = new Semaphore( 'schedule_yearly_reset_numbers' );
$hook = 'wpo_wcpdf_schedule_yearly_reset_numbers';

// checks if there are pending actions
Expand All @@ -819,7 +810,7 @@ public function schedule_yearly_reset_numbers() {
// if no concurrent actions sets the action
if ( $scheduled_actions < 1 ) {

if ( $lock->lock( $this->lock_retries ) ) {
if ( $lock->lock() ) {

$lock->log( 'Lock acquired for yearly reset numbers schedule.', 'info' );

Expand Down Expand Up @@ -866,9 +857,9 @@ public function schedule_yearly_reset_numbers() {
}

public function yearly_reset_numbers() {
$lock = new Semaphore( $this->lock_name, $this->lock_time, $this->lock_loggers, $this->lock_context );
$lock = new Semaphore( 'yearly_reset_numbers' );

if ( $lock->lock( $this->lock_retries ) ) {
if ( $lock->lock() ) {

$lock->log( 'Lock acquired for yearly reset numbers.', 'info' );

Expand Down
Loading

0 comments on commit 9bf76b5

Please sign in to comment.